linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libata: make sure sdev doesn't go away while rescanning
@ 2006-11-22  2:21 Tejun Heo
  2006-11-28  9:05 ` Jeff Garzik
  0 siblings, 1 reply; 2+ messages in thread
From: Tejun Heo @ 2006-11-22  2:21 UTC (permalink / raw)
  To: Jeff Garzik, linux-ide

ata_scsi_dev_rescan() doesn't synchronize against SCSI device detach
and the target sdev might go away in the middle.  Fix it.

Signed-off-by: Tejun Heo <htejun@gmail.com>

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 0552c3f..3976b25 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3215,15 +3215,27 @@ static int ata_scsi_user_scan(struct Scs
 void ata_scsi_dev_rescan(void *data)
 {
 	struct ata_port *ap = data;
-	struct ata_device *dev;
+	unsigned long flags;
 	unsigned int i;
 
+	spin_lock_irqsave(ap->lock, flags);
+
 	for (i = 0; i < ATA_MAX_DEVICES; i++) {
-		dev = &ap->device[i];
+		struct ata_device *dev = &ap->device[i];
+		struct scsi_device *sdev = dev->sdev;
 
-		if (ata_dev_enabled(dev) && dev->sdev)
-			scsi_rescan_device(&(dev->sdev->sdev_gendev));
+		if (!ata_dev_enabled(dev) || !sdev)
+			continue;
+		if (scsi_device_get(sdev))
+			continue;
+
+		spin_unlock_irqrestore(ap->lock, flags);
+		scsi_rescan_device(&(sdev->sdev_gendev));
+		scsi_device_put(sdev);
+		spin_lock_irqsave(ap->lock, flags);
 	}
+
+	spin_unlock_irqrestore(ap->lock, flags);
 }
 
 /**

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libata: make sure sdev doesn't go away while rescanning
  2006-11-22  2:21 [PATCH] libata: make sure sdev doesn't go away while rescanning Tejun Heo
@ 2006-11-28  9:05 ` Jeff Garzik
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Garzik @ 2006-11-28  9:05 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-ide

Tejun Heo wrote:
> ata_scsi_dev_rescan() doesn't synchronize against SCSI device detach
> and the target sdev might go away in the middle.  Fix it.
> 
> Signed-off-by: Tejun Heo <htejun@gmail.com>

ACK



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-28  9:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-22  2:21 [PATCH] libata: make sure sdev doesn't go away while rescanning Tejun Heo
2006-11-28  9:05 ` Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).