public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: Add check for kcalloc()
@ 2025-02-02 20:54 Jiasheng Jiang
  2025-02-03  8:32 ` Miquel Raynal
  0 siblings, 1 reply; 15+ messages in thread
From: Jiasheng Jiang @ 2025-02-02 20:54 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, gmpy.liaowx, kees
  Cc: linux-mtd, linux-kernel, Jiasheng Jiang

Add a check for kcalloc() and print an error message if it fails.

Fixes: 78c08247b9d3 ("mtd: Support kmsg dumper based on pstore/blk")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/mtd/mtdpstore.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/mtdpstore.c b/drivers/mtd/mtdpstore.c
index 7ac8ac901306..368997155c07 100644
--- a/drivers/mtd/mtdpstore.c
+++ b/drivers/mtd/mtdpstore.c
@@ -423,6 +423,11 @@ static void mtdpstore_notify_add(struct mtd_info *mtd)
 	longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize));
 	cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
 
+	if (!cxt->rmmap || !cxt->usedmap || !cxt->badmap) {
+		dev_err(&mtd->dev, "failed to allocate memory for map\n");
+		return;
+	}
+
 	/* just support dmesg right now */
 	cxt->dev.flags = PSTORE_FLAGS_DMESG;
 	cxt->dev.zone.read = mtdpstore_read;
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-02-07 14:49 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-02 20:54 [PATCH] mtd: Add check for kcalloc() Jiasheng Jiang
2025-02-03  8:32 ` Miquel Raynal
2025-02-03 18:04   ` Christophe JAILLET
2025-02-04  2:33     ` [PATCH v2] mtd: Add check and kfree() " Jiasheng Jiang
2025-02-04  6:17       ` Christophe JAILLET
2025-02-04  6:36         ` Jiri Slaby
2025-02-04 20:50           ` Christophe JAILLET
2025-02-05  2:31             ` [PATCH v3 1/2] mtd: Replace kcalloc() with devm_kcalloc() Jiasheng Jiang
2025-02-05  2:31               ` [PATCH v3 2/2] mtd: Add check for devm_kcalloc() Jiasheng Jiang
2025-02-07 14:46               ` [PATCH v3 1/2] mtd: Replace kcalloc() with devm_kcalloc() Miquel Raynal
2025-02-05  2:35             ` [PATCH v2] mtd: Add check and kfree() for kcalloc() Jiasheng Jiang
2025-02-04  6:32       ` Jiri Slaby
2025-02-04  9:17       ` Miquel Raynal
2025-02-04  2:37     ` [PATCH] mtd: Add check " Jiasheng Jiang
2025-02-04  2:34   ` Jiasheng Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox