diff mbox series

[v2] mtd: powernv_flash: check return value of devm_kasprintf()

Message ID 20231019013050.316022-1-yiyang13@huawei.com
State New
Headers show
Series [v2] mtd: powernv_flash: check return value of devm_kasprintf() | expand

Commit Message

Yi Yang Oct. 19, 2023, 1:30 a.m. UTC
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful by
checking the pointer validity.

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(+)

Comments

Miquel Raynal Oct. 19, 2023, 6:25 a.m. UTC | #1
Hi Yi,

yiyang13@huawei.com wrote on Thu, 19 Oct 2023 01:30:50 +0000:

> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful by
> checking the pointer validity.
> 
> Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>

Please re-read my previous answer and address all comments.

Thanks,
Miquèl
diff mbox series

Patch

diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c
index 66044f4f5bad..956a79c739e5 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;