Skip to content

Commit 6d734f1

Browse files
committed
mtd: rawnand: atmel: Fix possible memory leak
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" <[email protected]> Closes: https://lore.kernel.org/all/ZvmIvRJCf6VhHvpo@gallifrey/ Fixes: f88fc12 ("mtd: nand: Cleanup/rework the atmel_nand driver") Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 8ab1b51 commit 6d734f1

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)