[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250205023141.26195-1-jiashengjiangcool@gmail.com>
Date: Wed, 5 Feb 2025 02:31:40 +0000
From: Jiasheng Jiang <jiashengjiangcool@...il.com>
To: christophe.jaillet@...adoo.fr
Cc: gmpy.liaowx@...il.com,
jiashengjiangcool@...il.com,
jirislaby@...nel.org,
kees@...nel.org,
linux-kernel@...r.kernel.org,
linux-mtd@...ts.infradead.org,
miquel.raynal@...tlin.com,
richard@....at,
stable@...r.kernel.org,
vigneshr@...com
Subject: [PATCH v3 1/2] mtd: Replace kcalloc() with devm_kcalloc()
Replace kcalloc() with devm_kcalloc() to prevent memory leaks in case of
errors.
Fixes: 78c08247b9d3 ("mtd: Support kmsg dumper based on pstore/blk")
Cc: <stable@...r.kernel.org> # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@...il.com>
---
Changelog:
v2 -> v3:
1. Replace kcalloc() with devm_kcalloc().
2. Remove kfree().
3. Remove checks.
v1 -> v2:
1. Remove redundant logging.
2. Add kfree() in the error-handling path.
---
drivers/mtd/mtdpstore.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/mtdpstore.c b/drivers/mtd/mtdpstore.c
index 7ac8ac901306..2d004d41cf75 100644
--- a/drivers/mtd/mtdpstore.c
+++ b/drivers/mtd/mtdpstore.c
@@ -417,11 +417,11 @@ static void mtdpstore_notify_add(struct mtd_info *mtd)
}
longcnt = BITS_TO_LONGS(div_u64(mtd->size, info->kmsg_size));
- cxt->rmmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
- cxt->usedmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
+ cxt->rmmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
+ cxt->usedmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize));
- cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
+ cxt->badmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL);
/* just support dmesg right now */
cxt->dev.flags = PSTORE_FLAGS_DMESG;
@@ -527,9 +527,6 @@ static void mtdpstore_notify_remove(struct mtd_info *mtd)
mtdpstore_flush_removed(cxt);
unregister_pstore_device(&cxt->dev);
- kfree(cxt->badmap);
- kfree(cxt->usedmap);
- kfree(cxt->rmmap);
cxt->mtd = NULL;
cxt->index = -1;
}
--
2.25.1
Powered by blists - more mailing lists