Skip to content

Commit

Permalink
scsi: ufs: ufshpb: Fix a NULL check on list iterator
Browse files Browse the repository at this point in the history
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.

Link: https://lore.kernel.org/r/20220320150733.21824-1-xiam0nd.tong@gmail.com
Fixes: 4b5f490 ("scsi: ufs: ufshpb: L2P map management for HPB read")
Reviewed-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Xiaomeng Tong authored and Martin K. Petersen committed Apr 7, 2022
1 parent 0325225 commit bfb7789
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drivers/scsi/ufs/ufshpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,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;

Expand All @@ -888,6 +882,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;
}

Expand Down

0 comments on commit bfb7789

Please sign in to comment.