public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: powernv_flash: check return value of devm_kasprintf()
@ 2023-10-18  9:27 Yi Yang
  2023-10-19  1:16 ` Michael Ellerman
  0 siblings, 1 reply; 3+ messages in thread
From: Yi Yang @ 2023-10-18  9:27 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, mpe, npiggin, christophe.leroy,
	u.kleine-koenig, tudor.ambarus, robh
  Cc: linux-mtd, linuxppc-dev

The devm_kasprintf() returns a pointer to dynamically allocated memory.
that will return NULL when allocate failed.
Fix it by check return value of devm_kasprintf().

Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/mtd/devices/powernv_flash.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c
index 66044f4f5bad..b305e555ddbf 100644
--- a/drivers/mtd/devices/powernv_flash.c
+++ b/drivers/mtd/devices/powernv_flash.c
@@ -207,6 +207,10 @@ 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) {
+		dev_err(dev, "failed to allocate mtd->name\n");
+		return -ENOMEM;
+	}
 	mtd->type = MTD_NORFLASH;
 	mtd->flags = MTD_WRITEABLE;
 	mtd->size = size;
-- 
2.25.1


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

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

end of thread, other threads:[~2023-10-19  1:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-18  9:27 [PATCH] mtd: powernv_flash: check return value of devm_kasprintf() Yi Yang
2023-10-19  1:16 ` Michael Ellerman
2023-10-19  1:26   ` yiyang (D)

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