linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak
       [not found] <CGME20210823090714epcms2p1e414fdd91582bdbf8170b4cefb8a0f74@epcms2p1>
@ 2021-08-23  9:07 ` Keoseong Park
  2021-08-23 16:19   ` Bart Van Assche
                     ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Keoseong Park @ 2021-08-23  9:07 UTC (permalink / raw)
  To: ALIM AKHTAR, avri.altman, jejb, martin.petersen, Daejun Park,
	beanhuo, cang, linux-scsi, linux-kernel

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.

Signed-off-by: Keoseong Park <keosung.park@samsung.com>
---
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(-)

diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c
index 9acce92a356b..58db9ab8f0ae 100644
--- a/drivers/scsi/ufs/ufshpb.c
+++ b/drivers/scsi/ufs/ufshpb.c
@@ -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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak
  2021-08-23  9:07 ` [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak Keoseong Park
@ 2021-08-23 16:19   ` Bart Van Assche
  2021-08-24  3:22   ` Martin K. Petersen
  2021-08-28  2:32   ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2021-08-23 16:19 UTC (permalink / raw)
  To: keosung.park, ALIM AKHTAR, avri.altman, jejb, martin.petersen,
	Daejun Park, beanhuo, cang, linux-scsi, linux-kernel

On 8/23/21 2:07 AM, Keoseong Park wrote:
> 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.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak
  2021-08-23  9:07 ` [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak Keoseong Park
  2021-08-23 16:19   ` Bart Van Assche
@ 2021-08-24  3:22   ` Martin K. Petersen
  2021-08-28  2:32   ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-08-24  3:22 UTC (permalink / raw)
  To: Keoseong Park
  Cc: ALIM AKHTAR, avri.altman, jejb, martin.petersen, Daejun Park,
	beanhuo, cang, linux-scsi, linux-kernel


Keoseong,

> 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!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak
  2021-08-23  9:07 ` [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak Keoseong Park
  2021-08-23 16:19   ` Bart Van Assche
  2021-08-24  3:22   ` Martin K. Petersen
@ 2021-08-28  2:32   ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-08-28  2:32 UTC (permalink / raw)
  To: beanhuo, linux-scsi, cang, linux-kernel, Daejun Park,
	avri.altman, Keoseong Park, jejb, ALIM AKHTAR
  Cc: Martin K . Petersen

On Mon, 23 Aug 2021 18:07:14 +0900, Keoseong Park wrote:

> 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

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-28  2:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210823090714epcms2p1e414fdd91582bdbf8170b4cefb8a0f74@epcms2p1>
2021-08-23  9:07 ` [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak Keoseong Park
2021-08-23 16:19   ` Bart Van Assche
2021-08-24  3:22   ` Martin K. Petersen
2021-08-28  2:32   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).