scsi: core: Fix incorrect usage of shost_for_each_device
authorYe Bin <yebin10@huawei.com>
Mon, 18 May 2020 07:44:20 +0000 (15:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jun 2020 15:48:51 +0000 (17:48 +0200)
[ Upstream commit 4dea170f4fb225984b4f2f1cf0a41d485177b905 ]

shost_for_each_device(sdev, shost) \
for ((sdev) = __scsi_iterate_devices((shost), NULL); \
     (sdev); \
     (sdev) = __scsi_iterate_devices((shost), (sdev)))

When terminating shost_for_each_device() iteration with break or return,
scsi_device_put() should be used to prevent stale scsi device references
from being left behind.

Link: https://lore.kernel.org/r/20200518074420.39275-1-yebin10@huawei.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Ye Bin <yebin10@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/scsi_error.c
drivers/scsi/scsi_lib.c

index 978be1602f71807ca07ca90df3493c8c6ac4321f..927b1e6418423fa6e08b82d75ff53b6b94dc1d0f 100644 (file)
@@ -1412,6 +1412,7 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
                                sdev_printk(KERN_INFO, sdev,
                                            "%s: skip START_UNIT, past eh deadline\n",
                                            current->comm));
+                       scsi_device_put(sdev);
                        break;
                }
                stu_scmd = NULL;
@@ -1478,6 +1479,7 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
                                sdev_printk(KERN_INFO, sdev,
                                            "%s: skip BDR, past eh deadline\n",
                                             current->comm));
+                       scsi_device_put(sdev);
                        break;
                }
                bdr_scmd = NULL;
index 3ecdae18597d121176bd7d820092885f25fbcb24..b8b4366f12001d19d02d70f30c952dc12814dfd4 100644 (file)
@@ -2865,8 +2865,10 @@ scsi_host_unblock(struct Scsi_Host *shost, int new_state)
 
        shost_for_each_device(sdev, shost) {
                ret = scsi_internal_device_unblock(sdev, new_state);
-               if (ret)
+               if (ret) {
+                       scsi_device_put(sdev);
                        break;
+               }
        }
        return ret;
 }