[PATCH] libata: make sure sdev doesn't go away while rescanning
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>
This commit is contained in:
@@ -3181,15 +3181,27 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
|
|||||||
void ata_scsi_dev_rescan(void *data)
|
void ata_scsi_dev_rescan(void *data)
|
||||||
{
|
{
|
||||||
struct ata_port *ap = data;
|
struct ata_port *ap = data;
|
||||||
struct ata_device *dev;
|
unsigned long flags;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < ATA_MAX_DEVICES; i++) {
|
spin_lock_irqsave(ap->lock, flags);
|
||||||
dev = &ap->device[i];
|
|
||||||
|
|
||||||
if (ata_dev_enabled(dev) && dev->sdev)
|
for (i = 0; i < ATA_MAX_DEVICES; i++) {
|
||||||
scsi_rescan_device(&(dev->sdev->sdev_gendev));
|
struct ata_device *dev = &ap->device[i];
|
||||||
|
struct scsi_device *sdev = dev->sdev;
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user