--- zzzz-none-000/linux-3.10.107/drivers/mtd/nand/cs553x_nand.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/mtd/nand/cs553x_nand.c 2021-02-04 17:41:59.000000000 +0000 @@ -197,9 +197,8 @@ } /* Allocate memory for MTD device structure and private data */ - new_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); + new_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); if (!new_mtd) { - printk(KERN_WARNING "Unable to allocate CS553X NAND MTD device structure.\n"); err = -ENOMEM; goto out; } @@ -207,10 +206,6 @@ /* Get pointer to private data */ this = (struct nand_chip *)(&new_mtd[1]); - /* Initialize structures */ - memset(new_mtd, 0, sizeof(struct mtd_info)); - memset(this, 0, sizeof(struct nand_chip)); - /* Link the private data with the MTD structure */ new_mtd->priv = this; new_mtd->owner = THIS_MODULE; @@ -242,17 +237,23 @@ /* Enable the following for a flash based bad block table */ this->bbt_options = NAND_BBT_USE_FLASH; + new_mtd->name = kasprintf(GFP_KERNEL, "cs553x_nand_cs%d", cs); + if (!new_mtd->name) { + err = -ENOMEM; + goto out_ior; + } + /* Scan to find existence of the device */ if (nand_scan(new_mtd, 1)) { err = -ENXIO; - goto out_ior; + goto out_free; } - new_mtd->name = kasprintf(GFP_KERNEL, "cs553x_nand_cs%d", cs); - cs553x_mtd[cs] = new_mtd; goto out; +out_free: + kfree(new_mtd->name); out_ior: iounmap(this->IO_ADDR_R); out_mtd: