Skip to content

Commit

Permalink
ata: libata-scsi: Fix ata_scsi_dev_rescan() error path
Browse files Browse the repository at this point in the history
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 <dan.carpenter@linaro.org>
Fixes: 0c76106 ("scsi: sd: Fix TCG OPAL unlock on system resume")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
  • Loading branch information
damien-lemoal committed Apr 13, 2024
1 parent 24cfd86 commit 7933650
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/ata/libata-scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4745,7 +4745,7 @@ void ata_scsi_dev_rescan(struct work_struct *work)
* bail out.
*/
if (ap->pflags & ATA_PFLAG_SUSPENDED)
goto unlock;
goto unlock_ap;

if (!sdev)
continue;
Expand All @@ -4758,20 +4758,21 @@ void ata_scsi_dev_rescan(struct work_struct *work)
if (do_resume) {
ret = scsi_resume_device(sdev);
if (ret == -EWOULDBLOCK)
goto unlock;
goto unlock_scan;
dev->flags &= ~ATA_DFLAG_RESUMING;
}
ret = scsi_rescan_device(sdev);
scsi_device_put(sdev);
spin_lock_irqsave(ap->lock, flags);

if (ret)
goto unlock;
goto unlock_ap;
}
}

unlock:
unlock_ap:
spin_unlock_irqrestore(ap->lock, flags);
unlock_scan:
mutex_unlock(&ap->scsi_scan_mutex);

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

0 comments on commit 7933650

Please sign in to comment.