Skip to contentSkip to conversation

ufs: fix an NULL check on list iterator

PATCH In review Xiaomeng Tong 2 participants 2 messages Mar 20, 2022 – Mar 21, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ufs: fix an NULL check on list iterator

The list iterator is always non-NULL so the check 'if (!rgn)' is always false and the dev_err() is never called. Move the check outside the loop and determine if 'victim_rgn' is NULL, to fix this bug.

Fixes 4b5f49079c52a ("scsi: ufs: ufshpb: L2P map management for HPB read")

---
changes since v1:
- move the check outside the loop (Jakob Koschel)
v1: https://lore.kernel.org/all/[email protected]/

---
 drivers/scsi/ufs/ufshpb.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/scsi/ufs/ufshpb.c +5 -6
index 2d36a0715fca..b34feba1f53d 100644
@@ -869,12 +869,6 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb)
 	struct ufshpb_region *rgn, *victim_rgn = NULL;
 
 	list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) {
-		if (!rgn) {
-			dev_err(&hpb->sdev_ufs_lu->sdev_dev,
-				"%s: no region allocated\n",
-				__func__);
-			return NULL;
-		}
 		if (ufshpb_check_srgns_issue_state(hpb, rgn))
 			continue;
 
@@ -890,6 +884,11 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb)
 		break;
 	}
 
+	if (!victim_rgn)
+		dev_err(&hpb->sdev_ufs_lu->sdev_dev,
+			"%s: no region allocated\n",
+			__func__);
+
 	return victim_rgn;
 }
 

base-commit: 14702b3b2438e2f2d07ae93b5d695c166e5c83d1

Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw

Hi Xiaomeng Tong,

Quoted 8 lines

The list iterator is always non-NULL so the check 'if (!rgn)' is always false and the dev_err() is never called. Move the check outside the loop and determine if 'victim_rgn' is NULL, to fix this bug.

Fixes 4b5f49079c52a ("scsi: ufs: ufshpb: L2P map management for HPB read")

---

Good catch. Free to add my reviewed-by tag.

Thanks,
Daejun