Skip to content

Commit 1a6b644

Browse files
Abdun NihaalAlisonSchofield
authored andcommitted
nvdimm/btt: Free arenas on btt_init() error paths
The arenas allocated by discover_arenas() or create_arenas() are not freed on some error paths in btt_init(). This leaks memory when BTT initialization fails. Call free_arenas() from the affected error paths to release the allocations. [ as: commit message and log edits ] Fixes: 5212e11 ("nd_btt: atomic sector updates") Cc: stable@vger.kernel.org Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Link: https://patch.msgid.link/20260519-nvdimmleaks-v1-2-592300fb7a43@cse.iitm.ac.in Signed-off-by: Alison Schofield <alison.schofield@intel.com>
1 parent 13fe4cd commit 1a6b644

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

drivers/nvdimm/btt.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
15921592
if (btt->init_state != INIT_READY && nd_region->ro) {
15931593
dev_warn(dev, "%s is read-only, unable to init btt metadata\n",
15941594
dev_name(&nd_region->dev));
1595-
return NULL;
1595+
goto err;
15961596
} else if (btt->init_state != INIT_READY) {
15971597
btt->num_arenas = (rawsize / ARENA_MAX_SIZE) +
15981598
((rawsize % ARENA_MAX_SIZE) ? 1 : 0);
@@ -1602,25 +1602,28 @@ static struct btt *btt_init(struct nd_btt *nd_btt, unsigned long long rawsize,
16021602
ret = create_arenas(btt);
16031603
if (ret) {
16041604
dev_info(dev, "init: create_arenas: %d\n", ret);
1605-
return NULL;
1605+
goto err;
16061606
}
16071607

16081608
ret = btt_meta_init(btt);
16091609
if (ret) {
16101610
dev_err(dev, "init: error in meta_init: %d\n", ret);
1611-
return NULL;
1611+
goto err;
16121612
}
16131613
}
16141614

16151615
ret = btt_blk_init(btt);
16161616
if (ret) {
16171617
dev_err(dev, "init: error in blk_init: %d\n", ret);
1618-
return NULL;
1618+
goto err;
16191619
}
16201620

16211621
btt_debugfs_init(btt);
16221622

16231623
return btt;
1624+
err:
1625+
free_arenas(btt);
1626+
return NULL;
16241627
}
16251628

16261629
/**

0 commit comments

Comments
 (0)