Skip to content

Commit 1b61a59

Browse files
Jiasheng Jiangmiquelraynal
authored andcommitted
mtd: Replace kcalloc() with devm_kcalloc()
Replace kcalloc() with devm_kcalloc() to prevent memory leaks in case of errors. Fixes: 78c0824 ("mtd: Support kmsg dumper based on pstore/blk") Cc: [email protected] # v5.10+ Signed-off-by: Jiasheng Jiang <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 9ea13d9 commit 1b61a59

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

drivers/mtd/mtdpstore.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ static void mtdpstore_notify_add(struct mtd_info *mtd)
417417
}
418418

419419
longcnt = BITS_TO_LONGS(div_u64(mtd->size, info->kmsg_size));
420-
cxt->rmmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
421-
cxt->usedmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
420+
cxt->rmmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
421+
cxt->usedmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
422422

423423
longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize));
424-
cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
424+
cxt->badmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
425425

426426
/* just support dmesg right now */
427427
cxt->dev.flags = PSTORE_FLAGS_DMESG;
@@ -527,9 +527,6 @@ static void mtdpstore_notify_remove(struct mtd_info *mtd)
527527
mtdpstore_flush_removed(cxt);
528528

529529
unregister_pstore_device(&cxt->dev);
530-
kfree(cxt->badmap);
531-
kfree(cxt->usedmap);
532-
kfree(cxt->rmmap);
533530
cxt->mtd = NULL;
534531
cxt->index = -1;
535532
}

0 commit comments

Comments
 (0)