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)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 20 May 2020 01:54:17 +0000 (21:54 -0400)
commit4dea170f4fb225984b4f2f1cf0a41d485177b905
tree56b5b4f84c3438fc546318c2ccf8931378ca0611
parent7ffa5b939751b6638e4a99518775c8503fbb46be
scsi: core: Fix incorrect usage of shost_for_each_device

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>
drivers/scsi/scsi_error.c
drivers/scsi/scsi_lib.c