aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_scan.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2012-06-22 02:47:28 -0400
committerJames Bottomley <JBottomley@Parallels.com>2012-07-20 03:58:45 -0400
commit3b661a92e869ebe2358de8f4b3230ad84f7fce51 (patch)
treeaec30c8a07dacb470e0ca90082d34651b5ba4c1c /drivers/scsi/scsi_scan.c
parentb5f1758f221e446c5a2956cf7ffdf62b005f6458 (diff)
[SCSI] fix hot unplug vs async scan race
The following crash results from cases where the end_device has been removed before scsi_sysfs_add_sdev has had a chance to run. BUG: unable to handle kernel NULL pointer dereference at 0000000000000098 IP: [<ffffffff8115e100>] sysfs_create_dir+0x32/0xb6 ... Call Trace: [<ffffffff8125e4a8>] kobject_add_internal+0x120/0x1e3 [<ffffffff81075149>] ? trace_hardirqs_on+0xd/0xf [<ffffffff8125e641>] kobject_add_varg+0x41/0x50 [<ffffffff8125e70b>] kobject_add+0x64/0x66 [<ffffffff8131122b>] device_add+0x12d/0x63a [<ffffffff814b65ea>] ? _raw_spin_unlock_irqrestore+0x47/0x56 [<ffffffff8107de15>] ? module_refcount+0x89/0xa0 [<ffffffff8132f348>] scsi_sysfs_add_sdev+0x4e/0x28a [<ffffffff8132dcbb>] do_scan_async+0x9c/0x145 ...teach scsi_sysfs_add_devices() to check for deleted devices() before trying to add them, and teach scsi_remove_target() how to remove targets that have not been added via device_add(). Cc: <stable@vger.kernel.org> Reported-by: Dariusz Majchrzak <dariusz.majchrzak@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/scsi_scan.c')
-rw-r--r--drivers/scsi/scsi_scan.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 2e5fe584aad3..f55e5f166973 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1717,6 +1717,9 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost)
1717{ 1717{
1718 struct scsi_device *sdev; 1718 struct scsi_device *sdev;
1719 shost_for_each_device(sdev, shost) { 1719 shost_for_each_device(sdev, shost) {
1720 /* target removed before the device could be added */
1721 if (sdev->sdev_state == SDEV_DEL)
1722 continue;
1720 if (!scsi_host_scan_allowed(shost) || 1723 if (!scsi_host_scan_allowed(shost) ||
1721 scsi_sysfs_add_sdev(sdev) != 0) 1724 scsi_sysfs_add_sdev(sdev) != 0)
1722 __scsi_remove_device(sdev); 1725 __scsi_remove_device(sdev);