Skip to contentSkip to conversation

scsi: ufs: ufshpb: Fix possible memory leak

PATCH Applied Keoseong Park 3 participants 4 messages Aug 23, 2021 – Aug 28, 2021 1 message not in the archive SCSI

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20210823090714epcms2p1e414fdd91582bdbf8170b4cefb8a0f74@epcms2p1

#1 lore raw

PATCH v2 1/1 scsi: ufs: ufshpb: Fix possible memory leak

When HPB pinned region exists and mctx allocation for this region fails, memory leak is possible because memory is not released for the subregion table of the current region.

So, change to free memory for the subregion table of the current region.

---
v1 -> v2:
* Merge new kvfree() statement with the for-loop below it.
* Change to assign "hpb->rgn_tbl" when no error occurs.

 drivers/scsi/ufs/ufshpb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshpb.c +3 -3
index 9acce92a356b..58db9ab8f0ae 100644
@@ -1904,8 +1904,6 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb)
 	if (!rgn_table)
 		return -ENOMEM;
 
-	hpb->rgn_tbl = rgn_table;
-
 	for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) {
 		int srgn_cnt = hpb->srgns_per_rgn;
 		bool last_srgn = false;
@@ -1942,10 +1940,12 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb)
 		rgn->hpb = hpb;
 	}
 
+	hpb->rgn_tbl = rgn_table;
+
 	return 0;
 
 release_srgn_table:
-	for (i = 0; i < rgn_idx; i++)
+	for (i = 0; i <= rgn_idx; i++)
 		kvfree(rgn_table[i].srgn_tbl);
 
 	kvfree(rgn_table);
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#2 lore raw
Quoted 3 lines · Keoseong Park

When HPB pinned region exists and mctx allocation for this region fails, memory leak is possible because memory is not released for the subregion table of the current region.

#3 lore raw
In reply to Keoseong Park

Keoseong,

Quoted 3 lines

When HPB pinned region exists and mctx allocation for this region fails, memory leak is possible because memory is not released for the subregion table of the current region.

Applied to 5.15/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
In reply to Keoseong Park
Quoted 8 lines · Keoseong Park

When HPB pinned region exists and mctx allocation for this region fails, memory leak is possible because memory is not released for the subregion table of the current region.

So, change to free memory for the subregion table of the current region.

[...]

Applied to 5.15/scsi-queue, thanks!

[1/1] scsi: ufs: ufshpb: Fix possible memory leak

      https://git.kernel.org/mkp/scsi/c/6c9783e6296e
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering