Skip to content

Commit 7933650

Browse files
committed
ata: libata-scsi: Fix ata_scsi_dev_rescan() error path
Commit 0c76106 ("scsi: sd: Fix TCG OPAL unlock on system resume") incorrectly handles failures of scsi_resume_device() in ata_scsi_dev_rescan(), leading to a double call to spin_unlock_irqrestore() to unlock a device port. Fix this by redefining the goto labels used in case of errors and only unlock the port scsi_scan_mutex when scsi_resume_device() fails. Bug found with the Smatch static checker warning: drivers/ata/libata-scsi.c:4774 ata_scsi_dev_rescan() error: double unlocked 'ap->lock' (orig line 4757) Reported-by: Dan Carpenter <[email protected]> Fixes: 0c76106 ("scsi: sd: Fix TCG OPAL unlock on system resume") Cc: [email protected] Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
1 parent 24cfd86 commit 7933650

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/ata/libata-scsi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,7 +4745,7 @@ void ata_scsi_dev_rescan(struct work_struct *work)
47454745
* bail out.
47464746
*/
47474747
if (ap->pflags & ATA_PFLAG_SUSPENDED)
4748-
goto unlock;
4748+
goto unlock_ap;
47494749

47504750
if (!sdev)
47514751
continue;
@@ -4758,20 +4758,21 @@ void ata_scsi_dev_rescan(struct work_struct *work)
47584758
if (do_resume) {
47594759
ret = scsi_resume_device(sdev);
47604760
if (ret == -EWOULDBLOCK)
4761-
goto unlock;
4761+
goto unlock_scan;
47624762
dev->flags &= ~ATA_DFLAG_RESUMING;
47634763
}
47644764
ret = scsi_rescan_device(sdev);
47654765
scsi_device_put(sdev);
47664766
spin_lock_irqsave(ap->lock, flags);
47674767

47684768
if (ret)
4769-
goto unlock;
4769+
goto unlock_ap;
47704770
}
47714771
}
47724772

4773-
unlock:
4773+
unlock_ap:
47744774
spin_unlock_irqrestore(ap->lock, flags);
4775+
unlock_scan:
47754776
mutex_unlock(&ap->scsi_scan_mutex);
47764777

47774778
/* Reschedule with a delay if scsi_rescan_device() returned an error */

0 commit comments

Comments
 (0)