scsi: serialize ->rescan against ->remove
authorChristoph Hellwig <hch@lst.de>
Mon, 2 Feb 2015 13:01:24 +0000 (14:01 +0100)
committerJames Bottomley <JBottomley@Parallels.com>
Thu, 19 Mar 2015 13:38:43 +0000 (06:38 -0700)
Lock the device embedded in the scsi_device to protect against
concurrent calls to ->remove.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/scsi_scan.c

index 9c0a520d933c91eaaf793a259ba099d87c8d3176..60aae01caa89d96cd8c78681a8f0a97b44cae8ec 100644 (file)
@@ -1570,16 +1570,15 @@ EXPORT_SYMBOL(scsi_add_device);
 
 void scsi_rescan_device(struct device *dev)
 {
-       if (!dev->driver)
-               return;
-
-       if (try_module_get(dev->driver->owner)) {
+       device_lock(dev);
+       if (dev->driver && try_module_get(dev->driver->owner)) {
                struct scsi_driver *drv = to_scsi_driver(dev->driver);
 
                if (drv->rescan)
                        drv->rescan(dev);
                module_put(dev->driver->owner);
        }
+       device_unlock(dev);
 }
 EXPORT_SYMBOL(scsi_rescan_device);