Skip to content

Commit 894f189

Browse files
miquelraynalsmb49
authored andcommitted
mtd: rawnand: atmel: Fix possible memory leak
BugLink: https://bugs.launchpad.net/bugs/2101915 [ Upstream commit 6d734f1bfc336aaea91313a5632f2f197608fadd ] The pmecc "user" structure is allocated in atmel_pmecc_create_user() and was supposed to be freed with atmel_pmecc_destroy_user(), but this other helper is never called. One solution would be to find the proper location to call the destructor, but the trend today is to switch to device managed allocations, which in this case fits pretty well. Replace kzalloc() by devm_kzalloc() and drop the destructor entirely. Reported-by: "Dr. David Alan Gilbert" <linux@treblig.org> Closes: https://lore.kernel.org/all/ZvmIvRJCf6VhHvpo@gallifrey/ Fixes: f88fc12 ("mtd: nand: Cleanup/rework the atmel_nand driver") Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20241001203149.387655-1-miquel.raynal@bootlin.com Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 1c7c952 commit 894f189

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

drivers/mtd/nand/raw/atmel/pmecc.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
362362
size = ALIGN(size, sizeof(s32));
363363
size += (req->ecc.strength + 1) * sizeof(s32) * 3;
364364

365-
user = kzalloc(size, GFP_KERNEL);
365+
user = devm_kzalloc(pmecc->dev, size, GFP_KERNEL);
366366
if (!user)
367367
return ERR_PTR(-ENOMEM);
368368

@@ -408,12 +408,6 @@ atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
408408
}
409409
EXPORT_SYMBOL_GPL(atmel_pmecc_create_user);
410410

411-
void atmel_pmecc_destroy_user(struct atmel_pmecc_user *user)
412-
{
413-
kfree(user);
414-
}
415-
EXPORT_SYMBOL_GPL(atmel_pmecc_destroy_user);
416-
417411
static int get_strength(struct atmel_pmecc_user *user)
418412
{
419413
const int *strengths = user->pmecc->caps->strengths;

drivers/mtd/nand/raw/atmel/pmecc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ struct atmel_pmecc *devm_atmel_pmecc_get(struct device *dev);
5555
struct atmel_pmecc_user *
5656
atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
5757
struct atmel_pmecc_user_req *req);
58-
void atmel_pmecc_destroy_user(struct atmel_pmecc_user *user);
59-
6058
void atmel_pmecc_reset(struct atmel_pmecc *pmecc);
6159
int atmel_pmecc_enable(struct atmel_pmecc_user *user, int op);
6260
void atmel_pmecc_disable(struct atmel_pmecc_user *user);

0 commit comments

Comments
 (0)