Skip to contentSkip to conversation

scsi: scsi_devinfo: remove redundant 'found'

PATCH Superseded mrigendrachaubey 2 participants 3 messages May 31, 2025 – Jun 22, 2025 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: scsi_devinfo: remove redundant 'found'

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.

---
 drivers/scsi/scsi_devinfo.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/scsi/scsi_devinfo.c +5 -9
index a348df895dca..53cc60ab6dab 100644
@@ -269,17 +269,13 @@ 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);
+	list_for_each_entry(devinfo_table, &scsi_dev_info_list, node) {
+		if (devinfo_table->key == key)
+			return devinfo_table;
+	}
 
-	return devinfo_table;
+	return ERR_PTR(-EINVAL);
 }
 
 /*
Signature · 1 line
2.34.1
#1 lore raw

drivers/scsi/scsi_devinfo.c static struct { · line 276

Quoted 4 lines · mrigendrachaubey
drivers/scsi/scsi_devinfo.c +4 -0
+	list_for_each_entry(devinfo_table, &scsi_dev_info_list, node) {
+		if (devinfo_table->key == key)
+			return devinfo_table;
+	}

The braces around the loop body are not necessary. Please remove these.

Thanks,

Bart.

#2 lore raw

PATCH v2 1/1 scsi: scsi_devinfo: remove redundant 'found'

In reply to mrigendrachaubey

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.

---
 drivers/scsi/scsi_devinfo.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/scsi/scsi_devinfo.c +3 -8
index a348df895dca..e364829b6079 100644
@@ -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);
 }
 
 /*
Signature · 1 line
2.34.1