]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ata: libata-scsi: Improve ata_scsi_handle_link_detach()
authorDamien Le Moal <dlemoal@kernel.org>
Thu, 5 Sep 2024 02:00:59 +0000 (11:00 +0900)
committerDamien Le Moal <dlemoal@kernel.org>
Sat, 7 Sep 2024 01:16:55 +0000 (10:16 +0900)
A struct ata_device flags should always be set and cleared with the
device port locked. Testing for a flag should thus also be done while
holding the device port lock. In accordance to this principle, modify
ata_scsi_handle_link_detach() to test and clear the ATA_DFLAG_DETACHED
flag while holding the device port lock.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
drivers/ata/libata-scsi.c

index 3a442f564b0d071a282789b4f5f197cbc38415e5..6bd7ab27fcbb2e498c9874eeb4dfaa65a53ec66c 100644 (file)
@@ -4605,10 +4605,12 @@ static void ata_scsi_handle_link_detach(struct ata_link *link)
        ata_for_each_dev(dev, link, ALL) {
                unsigned long flags;
 
-               if (!(dev->flags & ATA_DFLAG_DETACHED))
+               spin_lock_irqsave(ap->lock, flags);
+               if (!(dev->flags & ATA_DFLAG_DETACHED)) {
+                       spin_unlock_irqrestore(ap->lock, flags);
                        continue;
+               }
 
-               spin_lock_irqsave(ap->lock, flags);
                dev->flags &= ~ATA_DFLAG_DETACHED;
                spin_unlock_irqrestore(ap->lock, flags);