[PATCH v2] scsi: scsi_devinfo: remove redundant 'found'

mrigendrachaubey posted 1 patch 3 months, 2 weeks ago
There is a newer version of this series
drivers/scsi/scsi_devinfo.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
[PATCH v2] scsi: scsi_devinfo: remove redundant 'found'
Posted by mrigendrachaubey 3 months, 2 weeks ago
Remove the unnecessary 'found' flag in scsi_devinfo_lookup_by_key().
The loop can return the matching entry directly when found, and fall
through to return ERR_PTR(-EINVAL) otherwise.

Signed-off-by: mrigendrachaubey <mrigendra.chaubey@gmail.com>
---
 drivers/scsi/scsi_devinfo.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index a348df895dca..e364829b6079 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -269,17 +269,12 @@ static struct {
 static struct scsi_dev_info_list_table *scsi_devinfo_lookup_by_key(int key)
 {
 	struct scsi_dev_info_list_table *devinfo_table;
-	int found = 0;
 
 	list_for_each_entry(devinfo_table, &scsi_dev_info_list, node)
-		if (devinfo_table->key == key) {
-			found = 1;
-			break;
-		}
-	if (!found)
-		return ERR_PTR(-EINVAL);
+		if (devinfo_table->key == key)
+			return devinfo_table;
 
-	return devinfo_table;
+	return ERR_PTR(-EINVAL);
 }
 
 /*
-- 
2.34.1
Re: [PATCH v2] scsi: scsi_devinfo: remove redundant 'found'
Posted by Martin K. Petersen 3 months, 2 weeks ago
> Remove the unnecessary 'found' flag in scsi_devinfo_lookup_by_key().
> The loop can return the matching entry directly when found, and fall
> through to return ERR_PTR(-EINVAL) otherwise.

Applied to 6.17/scsi-staging, thanks!

-- 
Martin K. Petersen
Re: [PATCH v2] scsi: scsi_devinfo: remove redundant 'found'
Posted by Bart Van Assche 3 months, 2 weeks ago
On 6/21/25 10:57 PM, mrigendrachaubey wrote:
> Remove the unnecessary 'found' flag in scsi_devinfo_lookup_by_key().
> The loop can return the matching entry directly when found, and fall
> through to return ERR_PTR(-EINVAL) otherwise.
> 
> Signed-off-by: mrigendrachaubey <mrigendra.chaubey@gmail.com>
> ---
>   drivers/scsi/scsi_devinfo.c | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
> index a348df895dca..e364829b6079 100644
> --- a/drivers/scsi/scsi_devinfo.c
> +++ b/drivers/scsi/scsi_devinfo.c
> @@ -269,17 +269,12 @@ static struct {
>   static struct scsi_dev_info_list_table *scsi_devinfo_lookup_by_key(int key)
>   {
>   	struct scsi_dev_info_list_table *devinfo_table;
> -	int found = 0;
>   
>   	list_for_each_entry(devinfo_table, &scsi_dev_info_list, node)
> -		if (devinfo_table->key == key) {
> -			found = 1;
> -			break;
> -		}
> -	if (!found)
> -		return ERR_PTR(-EINVAL);
> +		if (devinfo_table->key == key)
> +			return devinfo_table;
>   
> -	return devinfo_table;
> +	return ERR_PTR(-EINVAL);
>   }

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