Commit 7803b56d3b0d29a0231af3164dc7d3d9e86ded90

Authored by Jon Mason
Committed by Greg Kroah-Hartman
1 parent 24460c53b7

NTB: Add Error Handling in ntb_device_setup

commit 3b12a0d15bd1559e72ad21d9d807fd2a6706f0ab upstream.

If an error is encountered in ntb_device_setup, it is possible that the
spci_cmd isn't populated.  Writes to the offset can result in a NULL
pointer dereference.  This issue is easily encountered by running in
NTB-RP mode, as it currently is not supported and will generate an
error.  To get around this issue, return if an error is encountered
prior to attempting to write to the spci_cmd offset.

Signed-off-by: Jon Mason <jon.mason@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 4 additions and 1 deletions Side-by-side Diff

drivers/ntb/ntb_hw.c
... ... @@ -644,10 +644,13 @@
644 644 rc = -ENODEV;
645 645 }
646 646  
  647 + if (rc)
  648 + return rc;
  649 +
647 650 /* Enable Bus Master and Memory Space on the secondary side */
648 651 writew(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, ndev->reg_ofs.spci_cmd);
649 652  
650   - return rc;
  653 + return 0;
651 654 }
652 655  
653 656 static void ntb_device_free(struct ntb_device *ndev)