Skip to contentSkip to conversation

mtd: nand: ams-delta: fix overwritten mtd_info->owner in initialization

PATCH Applied Akinobu Mita 2 participants 2 messages Jan 11, 2015 – Jan 16, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: ams-delta: fix overwritten mtd_info->owner in initialization

In initialization routine, mtd_info->owner is overwritten by memset() just after being initialized. This can be fixed by moving memset() calls to just before setting mtd_info->owner. But the memory region is allocated by kmalloc, so we can fix it by using kzalloc instead of kmalloc.

Cc Jonathan McDowell <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Brian Norris <[email protected]>
---
 drivers/mtd/nand/ams-delta.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/nand/ams-delta.c +1 -5
index f1d555c..842f8fe 100644
@@ -183,7 +183,7 @@ static int ams_delta_init(struct platform_device *pdev)
 		return -ENXIO;
 
 	/* Allocate memory for MTD device structure and private data */
-	ams_delta_mtd = kmalloc(sizeof(struct mtd_info) +
+	ams_delta_mtd = kzalloc(sizeof(struct mtd_info) +
 				sizeof(struct nand_chip), GFP_KERNEL);
 	if (!ams_delta_mtd) {
 		printk (KERN_WARNING "Unable to allocate E3 NAND MTD device structure.\n");
@@ -196,10 +196,6 @@ static int ams_delta_init(struct platform_device *pdev)
 	/* Get pointer to private data */
 	this = (struct nand_chip *) (&ams_delta_mtd[1]);
 
-	/* Initialize structures */
-	memset(ams_delta_mtd, 0, sizeof(struct mtd_info));
-	memset(this, 0, sizeof(struct nand_chip));
-
 	/* Link the private data with the MTD structure */
 	ams_delta_mtd->priv = this;
 
Signature · 1 line
1.9.1
Applied
#1 lore raw
Quoted 10 lines · Akinobu Mita

In initialization routine, mtd_info->owner is overwritten by memset() just after being initialized. This can be fixed by moving memset() calls to just before setting mtd_info->owner. But the memory region is allocated by kmalloc, so we can fix it by using kzalloc instead of kmalloc.

Cc Jonathan McDowell <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Brian Norris <[email protected]>

Pushed to l2-mtd.git. Thanks!

Brian