mtd: nand: fix memory leak in ONFI extended parameter page

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Sep 27 06:59:01 EDT 2013


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=5cb1327172281cadb7ee8c5fa294d7ac8e09b8db
Commit:     5cb1327172281cadb7ee8c5fa294d7ac8e09b8db
Parent:     7b9e3a6ac00be4f3d654a711573b1794b046c22f
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Mon Sep 16 17:59:20 2013 -0700
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Fri Sep 27 05:48:02 2013 -0500

    mtd: nand: fix memory leak in ONFI extended parameter page
    
    This fixes a memory leak in the ONFI support code for detecting the
    required ECC levels from this commit:
    
      commit 6dcbe0cdd83fb5f77be4f44c9e06c535281c375a
      Author: Huang Shijie <b32955 at freescale.com>
      Date:   Wed May 22 10:28:27 2013 +0800
    
          mtd: get the ECC info from the Extended Parameter Page
    
    In the success case, we never freed the 'ep' buffer.
    
    Also, this fixes an oversight in the same commit where we (harmlessly)
    freed the NULL pointer.
    
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Acked-by: Huang Shijie <b32955 at freescale.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/nand/nand_base.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 7ed4841..d340b2f 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2869,10 +2869,8 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
 
 	len = le16_to_cpu(p->ext_param_page_length) * 16;
 	ep = kmalloc(len, GFP_KERNEL);
-	if (!ep) {
-		ret = -ENOMEM;
-		goto ext_out;
-	}
+	if (!ep)
+		return -ENOMEM;
 
 	/* Send our own NAND_CMD_PARAM. */
 	chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
@@ -2920,7 +2918,7 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
 	}
 
 	pr_info("ONFI extended param page detected.\n");
-	return 0;
+	ret = 0;
 
 ext_out:
 	kfree(ep);



More information about the linux-mtd-cvs mailing list