Skip to contentSkip to conversation

mtd: powernv_flash: check return value of devm_kasprintf()

PATCH Superseded Yi Yang 2 participants 2 messages Oct 19, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH v2 1/1 mtd: powernv_flash: check return value of devm_kasprintf()

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")
---
 drivers/mtd/devices/powernv_flash.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mtd/devices/powernv_flash.c +4 -0
index 66044f4f5bad..956a79c739e5 100644
@@ -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;
Signature · 6 lines
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#1 lore raw

Hi Yi,

[email protected] wrote on Thu, 19 Oct 2023 01:30:50 +0000:

Quoted 6 lines

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")

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

Thanks,
Miquèl

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