mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] nvdimm/btt: fix a few memory leaks
@ 2026-05-19  5:50 Abdun Nihaal
  2026-05-19  5:50 ` [PATCH 1/2] nvdimm/btt: fix potential memory leak in discover_arenas() Abdun Nihaal
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Abdun Nihaal @ 2026-05-19  5:50 UTC (permalink / raw)
  To: Vishal Verma, Dan Williams, Dave Jiang, Ira Weiny
  Cc: nvdimm, linux-kernel, stable, Abdun Nihaal

The following two patches fix memory leak issues in error paths in the
btt_init() and discover_arenas() functions.

- nvdimm/btt: fix potential memory leak in btt_init()
- nvdimm/btt: fix potential memory leak in discover_arenas()

Compile tested only. Issue found using static analysis.

Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Abdun Nihaal (2):
      nvdimm/btt: fix potential memory leak in discover_arenas()
      nvdimm/btt: fix potential memory leak in btt_init()

 drivers/nvdimm/btt.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260519-nvdimmleaks-11f40a4af32a

Best regards,
-- 
Abdun Nihaal <nihaal@cse.iitm.ac.in>


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

* [PATCH 1/2] nvdimm/btt: fix potential memory leak in discover_arenas()
  2026-05-19  5:50 [PATCH 0/2] nvdimm/btt: fix a few memory leaks Abdun Nihaal
@ 2026-05-19  5:50 ` Abdun Nihaal
  2026-05-19  5:50 ` [PATCH 2/2] nvdimm/btt: fix potential memory leak in btt_init() Abdun Nihaal
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Abdun Nihaal @ 2026-05-19  5:50 UTC (permalink / raw)
  To: Vishal Verma, Dan Williams, Dave Jiang, Ira Weiny
  Cc: nvdimm, linux-kernel, stable, Abdun Nihaal

Memory allocated in btt_freelist_init(), btt_rtt_init() and
btt_maplocks_init() which are called in discover_arenas() is not freed
in some error paths. Fix that by adding kfree() calls to error path.

Fixes: 5212e11fde4d ("nd_btt: atomic sector updates")
Cc: stable@vger.kernel.org
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
 drivers/nvdimm/btt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index fdcb080a4314..e0b6a85a8124 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -919,6 +919,9 @@ static int discover_arenas(struct btt *btt)
 	return ret;
 
  out:
+	kfree(arena->freelist);
+	kfree(arena->rtt);
+	kfree(arena->map_locks);
 	kfree(arena);
 	free_arenas(btt);
 	return ret;

-- 
2.43.0


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

* [PATCH 2/2] nvdimm/btt: fix potential memory leak in btt_init()
  2026-05-19  5:50 [PATCH 0/2] nvdimm/btt: fix a few memory leaks Abdun Nihaal
  2026-05-19  5:50 ` [PATCH 1/2] nvdimm/btt: fix potential memory leak in discover_arenas() Abdun Nihaal
@ 2026-05-19  5:50 ` Abdun Nihaal
  2026-06-01 23:03 ` [PATCH 0/2] nvdimm/btt: fix a few memory leaks Alison Schofield
  2026-06-02  0:33 ` Alison Schofield
  3 siblings, 0 replies; 5+ messages in thread
From: Abdun Nihaal @ 2026-05-19  5:50 UTC (permalink / raw)
  To: Vishal Verma, Dan Williams, Dave Jiang, Ira Weiny
  Cc: nvdimm, linux-kernel, stable, Abdun Nihaal

The memory allocated by discover_arenas() or create_arenas() is not
freed in some of the error paths in btt_init(). Fix that by calling
free_arenas() on the error paths.

Fixes: 5212e11fde4d ("nd_btt: atomic sector updates")
Cc: stable@vger.kernel.org
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
 drivers/nvdimm/btt.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index e0b6a85a8124..7e1112960d7f 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -1592,7 +1592,7 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
 	if (btt->init_state != INIT_READY && nd_region->ro) {
 		dev_warn(dev, "%s is read-only, unable to init btt metadata\n",
 				dev_name(&nd_region->dev));
-		return NULL;
+		goto err;
 	} else if (btt->init_state != INIT_READY) {
 		btt->num_arenas = (rawsize / ARENA_MAX_SIZE) +
 			((rawsize % ARENA_MAX_SIZE) ? 1 : 0);
@@ -1602,25 +1602,28 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
 		ret = create_arenas(btt);
 		if (ret) {
 			dev_info(dev, "init: create_arenas: %d\n", ret);
-			return NULL;
+			goto err;
 		}
 
 		ret = btt_meta_init(btt);
 		if (ret) {
 			dev_err(dev, "init: error in meta_init: %d\n", ret);
-			return NULL;
+			goto err;
 		}
 	}
 
 	ret = btt_blk_init(btt);
 	if (ret) {
 		dev_err(dev, "init: error in blk_init: %d\n", ret);
-		return NULL;
+		goto err;
 	}
 
 	btt_debugfs_init(btt);
 
 	return btt;
+err:
+	free_arenas(btt);
+	return NULL;
 }
 
 /**

-- 
2.43.0


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

* Re: [PATCH 0/2] nvdimm/btt: fix a few memory leaks
  2026-05-19  5:50 [PATCH 0/2] nvdimm/btt: fix a few memory leaks Abdun Nihaal
  2026-05-19  5:50 ` [PATCH 1/2] nvdimm/btt: fix potential memory leak in discover_arenas() Abdun Nihaal
  2026-05-19  5:50 ` [PATCH 2/2] nvdimm/btt: fix potential memory leak in btt_init() Abdun Nihaal
@ 2026-06-01 23:03 ` Alison Schofield
  2026-06-02  0:33 ` Alison Schofield
  3 siblings, 0 replies; 5+ messages in thread
From: Alison Schofield @ 2026-06-01 23:03 UTC (permalink / raw)
  To: Abdun Nihaal
  Cc: Vishal Verma, Dan Williams, Dave Jiang, Ira Weiny, nvdimm,
	linux-kernel, stable

On Tue, May 19, 2026 at 11:20:11AM +0530, Abdun Nihaal wrote:
> The following two patches fix memory leak issues in error paths in the
> btt_init() and discover_arenas() functions.
> 
> - nvdimm/btt: fix potential memory leak in btt_init()
> - nvdimm/btt: fix potential memory leak in discover_arenas()
> 
> Compile tested only. Issue found using static analysis.
> 
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>


Hi Abdun,

Thanks for the patches!

I'm giving this my Reviewed-by Tag and will apply with some fixups
to the commit messages and the commit log of patch 2.

Sashiko noted 3 potential issues which I've worked thru to my
satisfaction (no changes needed) For future reference, I'd expect
you to come back around and offer comment on such complaints.

https://sashiko.dev/#/patchset/20260519-nvdimmleaks-v1-0-592300fb7a43%40cse.iitm.ac.in

Reviewed-by: Alison Schofield <alison.schofield@intel.com>


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

* Re: [PATCH 0/2] nvdimm/btt: fix a few memory leaks
  2026-05-19  5:50 [PATCH 0/2] nvdimm/btt: fix a few memory leaks Abdun Nihaal
                   ` (2 preceding siblings ...)
  2026-06-01 23:03 ` [PATCH 0/2] nvdimm/btt: fix a few memory leaks Alison Schofield
@ 2026-06-02  0:33 ` Alison Schofield
  3 siblings, 0 replies; 5+ messages in thread
From: Alison Schofield @ 2026-06-02  0:33 UTC (permalink / raw)
  To: Abdun Nihaal
  Cc: Vishal Verma, Dan Williams, Dave Jiang, Ira Weiny, nvdimm,
	linux-kernel, stable

On Tue, May 19, 2026 at 11:20:11AM +0530, Abdun Nihaal wrote:
> The following two patches fix memory leak issues in error paths in the
> btt_init() and discover_arenas() functions.
> 
> - nvdimm/btt: fix potential memory leak in btt_init()
> - nvdimm/btt: fix potential memory leak in discover_arenas()
> 
> Compile tested only. Issue found using static analysis.
> 
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
> ---
> Abdun Nihaal (2):
>       nvdimm/btt: fix potential memory leak in discover_arenas()
>       nvdimm/btt: fix potential memory leak in btt_init()

Applied to nvdimm/nvdimm.git (libnvdimm-for-next)
https://git.kernel.org/nvdimm/nvdimm/c/13fe4cd9ddd0
https://git.kernel.org/nvdimm/nvdimm/c/1a6b6442a982


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

end of thread, other threads:[~2026-06-02  0:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-19  5:50 [PATCH 0/2] nvdimm/btt: fix a few memory leaks Abdun Nihaal
2026-05-19  5:50 ` [PATCH 1/2] nvdimm/btt: fix potential memory leak in discover_arenas() Abdun Nihaal
2026-05-19  5:50 ` [PATCH 2/2] nvdimm/btt: fix potential memory leak in btt_init() Abdun Nihaal
2026-06-01 23:03 ` [PATCH 0/2] nvdimm/btt: fix a few memory leaks Alison Schofield
2026-06-02  0:33 ` Alison Schofield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®