]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mtd: Add check for devm_kcalloc()
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Wed, 5 Feb 2025 02:31:41 +0000 (02:31 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:44:01 +0000 (07:44 +0200)
commit 2aee30bb10d7bad0a60255059c9ce1b84cf0130e upstream.

Add a check for devm_kcalloc() to ensure successful allocation.

Fixes: 78c08247b9d3 ("mtd: Support kmsg dumper based on pstore/blk")
Cc: stable@vger.kernel.org # v5.10+
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mtd/mtdpstore.c

index e13d42c0acb0f5407bdc57de95eecda8cdd0461f..085728366c9bebb6cc3c0b90c7bbda3a58bc5897 100644 (file)
@@ -423,6 +423,9 @@ 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)
+               return;
+
        /* just support dmesg right now */
        cxt->dev.flags = PSTORE_FLAGS_DMESG;
        cxt->dev.zone.read = mtdpstore_read;