[PATCH 2/2] mtd: brcmnand: Add a NULL check for devm_kasprintf()

Fabio Estevam festevam at gmail.com
Fri Jan 5 12:02:56 PST 2018


From: Fabio Estevam <fabio.estevam at nxp.com>

devm_kasprintf() may fail, so we should better add a NULL check
and propagate an error on failure.

Signed-off-by: Fabio Estevam <fabio.estevam at nxp.com>
---
 drivers/mtd/nand/brcmnand/brcmnand.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index 3310e14..8942aa6 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -2237,6 +2237,8 @@ static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
 	nand_set_controller_data(chip, host);
 	mtd->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "brcmnand.%d",
 				   host->cs);
+	if (!mtd->name)
+		return -ENOMEM;
 	mtd->owner = THIS_MODULE;
 	mtd->dev.parent = &pdev->dev;
 
-- 
2.7.4




More information about the linux-mtd mailing list