From bc349da0a6b3c6cf795b6a51e3f448d9d16a1686 Mon Sep 17 00:00:00 2001 From: Richard Weinberger Date: Mon, 1 Jun 2015 23:10:51 +0200 Subject: [PATCH] mtd: cs553x_nand: Fix kasprintf() usage kasprintf() does a dynamic memory allocation and can fail. We have to handle that case. Signed-off-by: Richard Weinberger Signed-off-by: Brian Norris --- drivers/mtd/nand/cs553x_nand.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c index 88109d375ae7..aec6045058c7 100644 --- a/drivers/mtd/nand/cs553x_nand.c +++ b/drivers/mtd/nand/cs553x_nand.c @@ -237,17 +237,23 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr) /* Enable the following for a flash based bad block table */ this->bbt_options = NAND_BBT_USE_FLASH; - /* Scan to find existence of the device */ - if (nand_scan(new_mtd, 1)) { - err = -ENXIO; + new_mtd->name = kasprintf(GFP_KERNEL, "cs553x_nand_cs%d", cs); + if (!new_mtd->name) { + err = -ENOMEM; goto out_ior; } - new_mtd->name = kasprintf(GFP_KERNEL, "cs553x_nand_cs%d", cs); + /* Scan to find existence of the device */ + if (nand_scan(new_mtd, 1)) { + err = -ENXIO; + goto out_free; + } cs553x_mtd[cs] = new_mtd; goto out; +out_free: + kfree(new_mtd->name); out_ior: iounmap(this->IO_ADDR_R); out_mtd: