Skip to contentSkip to conversation

mtd: rawnand: intel: check return value of devm_kasprintf()

PATCH Applied Yi Yang 2 participants 2 messages Oct 19, 2023 – Oct 27, 2023

Subsystems (2)
lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH v3 1/1 mtd: rawnand: intel: 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 0b1039f016e8 ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")

---
v2:Change commit log, and fix error check code. v3:No need for error messages upon memory allocation failures.

---
 drivers/mtd/nand/raw/intel-nand-controller.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mtd/nand/raw/intel-nand-controller.c +10 -0
index cb5d88f42297..f0ad2308f6d5 100644
@@ -619,6 +619,11 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	ebu_host->cs_num = cs;
 
 	resname = devm_kasprintf(dev, GFP_KERNEL, "nand_cs%d", cs);
+	if (!resname) {
+		ret = -ENOMEM;
+		goto err_of_node_put;
+	}
+
 	ebu_host->cs[cs].chipaddr = devm_platform_ioremap_resource_byname(pdev,
 									  resname);
 	if (IS_ERR(ebu_host->cs[cs].chipaddr)) {
@@ -649,6 +654,11 @@ static int ebu_nand_probe(struct platform_device *pdev)
 	}
 
 	resname = devm_kasprintf(dev, GFP_KERNEL, "addr_sel%d", cs);
+	if (!resname) {
+		ret = -ENOMEM;
+		goto err_cleanup_dma;
+	}
+
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname);
 	if (!res) {
 		ret = -EINVAL;
Signature · 6 lines
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Applied
#1 lore raw
Quoted 6 lines · Yi Yang

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 0b1039f016e8 ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

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