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

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Feb 16 18:59:04 PST 2015


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=526789fc532a445975b60885a65d3cea5bfa6391
Commit:     526789fc532a445975b60885a65d3cea5bfa6391
Parent:     45c6a0caeb2bde9e043bcd833af322db57a37498
Author:     Akinobu Mita <akinobu.mita at gmail.com>
AuthorDate: Sun Jan 11 22:07:20 2015 +0900
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Thu Jan 15 19:33:03 2015 -0800

    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.
    
    Signed-off-by: Akinobu Mita <akinobu.mita at gmail.com>
    Cc: Jonathan McDowell <noodles at earth.li>
    Cc: David Woodhouse <dwmw2 at infradead.org>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/nand/ams-delta.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index f1d555c..842f8fe 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -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;
 



More information about the linux-mtd-cvs mailing list