]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.1/ata-libata-scsi-fix-ata_scsi_dev_rescan-error-path.patch
b359dc25cbc8688e09edc8d3bdacedce92f6b228
[thirdparty/kernel/stable-queue.git] / queue-6.1 / ata-libata-scsi-fix-ata_scsi_dev_rescan-error-path.patch
1 From 79336504781e7fee5ddaf046dcc186c8dfdf60b1 Mon Sep 17 00:00:00 2001
2 From: Damien Le Moal <dlemoal@kernel.org>
3 Date: Fri, 12 Apr 2024 08:41:15 +0900
4 Subject: ata: libata-scsi: Fix ata_scsi_dev_rescan() error path
5
6 From: Damien Le Moal <dlemoal@kernel.org>
7
8 commit 79336504781e7fee5ddaf046dcc186c8dfdf60b1 upstream.
9
10 Commit 0c76106cb975 ("scsi: sd: Fix TCG OPAL unlock on system resume")
11 incorrectly handles failures of scsi_resume_device() in
12 ata_scsi_dev_rescan(), leading to a double call to
13 spin_unlock_irqrestore() to unlock a device port. Fix this by redefining
14 the goto labels used in case of errors and only unlock the port
15 scsi_scan_mutex when scsi_resume_device() fails.
16
17 Bug found with the Smatch static checker warning:
18
19 drivers/ata/libata-scsi.c:4774 ata_scsi_dev_rescan()
20 error: double unlocked 'ap->lock' (orig line 4757)
21
22 Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
23 Fixes: 0c76106cb975 ("scsi: sd: Fix TCG OPAL unlock on system resume")
24 Cc: stable@vger.kernel.org
25 Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
26 Reviewed-by: Niklas Cassel <cassel@kernel.org>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29 drivers/ata/libata-scsi.c | 9 +++++----
30 1 file changed, 5 insertions(+), 4 deletions(-)
31
32 --- a/drivers/ata/libata-scsi.c
33 +++ b/drivers/ata/libata-scsi.c
34 @@ -4667,7 +4667,7 @@ void ata_scsi_dev_rescan(struct work_str
35 * bail out.
36 */
37 if (ap->pflags & ATA_PFLAG_SUSPENDED)
38 - goto unlock;
39 + goto unlock_ap;
40
41 if (!sdev)
42 continue;
43 @@ -4680,7 +4680,7 @@ void ata_scsi_dev_rescan(struct work_str
44 if (do_resume) {
45 ret = scsi_resume_device(sdev);
46 if (ret == -EWOULDBLOCK)
47 - goto unlock;
48 + goto unlock_scan;
49 dev->flags &= ~ATA_DFLAG_RESUMING;
50 }
51 ret = scsi_rescan_device(sdev);
52 @@ -4688,12 +4688,13 @@ void ata_scsi_dev_rescan(struct work_str
53 spin_lock_irqsave(ap->lock, flags);
54
55 if (ret)
56 - goto unlock;
57 + goto unlock_ap;
58 }
59 }
60
61 -unlock:
62 +unlock_ap:
63 spin_unlock_irqrestore(ap->lock, flags);
64 +unlock_scan:
65 mutex_unlock(&ap->scsi_scan_mutex);
66
67 /* Reschedule with a delay if scsi_rescan_device() returned an error */