mtd: powernv: Add check devm_kasprintf() returned value
authorCharles Han <hanchunchao@inspur.com>
Wed, 28 Aug 2024 09:24:27 +0000 (17:24 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 6 Sep 2024 15:10:08 +0000 (17:10 +0200)
devm_kasprintf() can return a NULL pointer on failure but this
returned value is not checked.

Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20240828092427.128177-1-hanchunchao@inspur.com
drivers/mtd/devices/powernv_flash.c

index 66044f4f5bade81e4cd8dcf698fa2500a13fbbf0..10cd1d9b48859dfa8f275ab87e67f5f4f09cd6e7 100644 (file)
@@ -207,6 +207,9 @@ static int powernv_flash_set_driver_info(struct device *dev,
         * get them
         */
        mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
+       if (!mtd->name)
+               return -ENOMEM;
+
        mtd->type = MTD_NORFLASH;
        mtd->flags = MTD_WRITEABLE;
        mtd->size = size;