All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: Fix incorrect usage of shost_for_each_device
@ 2020-05-18  7:44 Ye Bin
  2020-05-18 14:39 ` Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ye Bin @ 2020-05-18  7:44 UTC (permalink / raw)
  To: martin.petersen, jejb; +Cc: yebin10, linux-scsi, linux-kernel

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.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 drivers/scsi/scsi_error.c | 2 ++
 drivers/scsi/scsi_lib.c   | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 978be1602f71..927b1e641842 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -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;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index be1a4a9a5fca..173bc7fc2836 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2859,8 +2859,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;
 }
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: Fix incorrect usage of shost_for_each_device
  2020-05-18  7:44 [PATCH] scsi: Fix incorrect usage of shost_for_each_device Ye Bin
@ 2020-05-18 14:39 ` Bart Van Assche
  2020-05-20  2:30 ` Martin K. Petersen
  2020-06-04  6:05 ` Hannes Reinecke
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2020-05-18 14:39 UTC (permalink / raw)
  To: Ye Bin, martin.petersen, jejb; +Cc: linux-scsi, linux-kernel

On 2020-05-18 00:44, Ye Bin wrote:
> 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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: Fix incorrect usage of shost_for_each_device
  2020-05-18  7:44 [PATCH] scsi: Fix incorrect usage of shost_for_each_device Ye Bin
  2020-05-18 14:39 ` Bart Van Assche
@ 2020-05-20  2:30 ` Martin K. Petersen
  2020-06-04  6:05 ` Hannes Reinecke
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-05-20  2:30 UTC (permalink / raw)
  To: Ye Bin, jejb; +Cc: Martin K . Petersen, linux-scsi, linux-kernel

On Mon, 18 May 2020 15:44:20 +0800, Ye Bin wrote:

> 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.

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: core: Fix incorrect usage of shost_for_each_device
      https://git.kernel.org/mkp/scsi/c/4dea170f4fb2

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: Fix incorrect usage of shost_for_each_device
  2020-05-18  7:44 [PATCH] scsi: Fix incorrect usage of shost_for_each_device Ye Bin
  2020-05-18 14:39 ` Bart Van Assche
  2020-05-20  2:30 ` Martin K. Petersen
@ 2020-06-04  6:05 ` Hannes Reinecke
  2 siblings, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2020-06-04  6:05 UTC (permalink / raw)
  To: Ye Bin, martin.petersen, jejb; +Cc: linux-scsi, linux-kernel

On 5/18/20 9:44 AM, Ye Bin wrote:
> 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.
> 
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
>   drivers/scsi/scsi_error.c | 2 ++
>   drivers/scsi/scsi_lib.c   | 4 +++-
>   2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
> index 978be1602f71..927b1e641842 100644
> --- a/drivers/scsi/scsi_error.c
> +++ b/drivers/scsi/scsi_error.c
> @@ -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;
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index be1a4a9a5fca..173bc7fc2836 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -2859,8 +2859,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;
>   }
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke            Teamlead Storage & Networking
hare@suse.de                               +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-04  6:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18  7:44 [PATCH] scsi: Fix incorrect usage of shost_for_each_device Ye Bin
2020-05-18 14:39 ` Bart Van Assche
2020-05-20  2:30 ` Martin K. Petersen
2020-06-04  6:05 ` Hannes Reinecke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.