mtd: mxc-nand: kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 28 00:59:06 EST 2014


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=a5900554a8b5fbc4fb731c6f9896ed265683f94e
Commit:     a5900554a8b5fbc4fb731c6f9896ed265683f94e
Parent:     2fec386a94bbe8a02d0669d9fcb32e6a69918d9f
Author:     Huang Shijie <shijie8 at gmail.com>
AuthorDate: Sat Dec 21 00:02:27 2013 +0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Sat Jan 11 12:20:06 2014 -0800

    mtd: mxc-nand: kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE
    
    We kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE by the following way:
     1.) Before we call the nand_scan_ident, we allocate a temporary buffer
         whose size is PAGE_SIZE.
     2.) After we finish the nand_scan_ident, we have already getten the
         page size and oob size. We will allocate the right buffer size
         again.
    
    Signed-off-by: Huang Shijie <shijie8 at gmail.com>
    Reviewed-by: Josh Triplett <josh at joshtriplett.org>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/nand/mxc_nand.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 567a5e5..e9a4835 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -1399,12 +1399,15 @@ static int mxcnd_probe(struct platform_device *pdev)
 	int err = 0;
 
 	/* Allocate memory for MTD device structure and private data */
-	host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host) +
-			NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE, GFP_KERNEL);
+	host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host),
+			GFP_KERNEL);
 	if (!host)
 		return -ENOMEM;
 
-	host->data_buf = (uint8_t *)(host + 1);
+	/* allocate a temporary buffer for the nand_scan_ident() */
+	host->data_buf = devm_kzalloc(&pdev->dev, PAGE_SIZE, GFP_KERNEL);
+	if (!host->data_buf)
+		return -ENOMEM;
 
 	host->dev = &pdev->dev;
 	/* structures must be linked */
@@ -1532,6 +1535,15 @@ static int mxcnd_probe(struct platform_device *pdev)
 		goto escan;
 	}
 
+	/* allocate the right size buffer now */
+	devm_kfree(&pdev->dev, (void *)host->data_buf);
+	host->data_buf = devm_kzalloc(&pdev->dev, mtd->writesize + mtd->oobsize,
+					GFP_KERNEL);
+	if (!host->data_buf) {
+		err = -ENOMEM;
+		goto escan;
+	}
+
 	/* Call preset again, with correct writesize this time */
 	host->devtype_data->preset(mtd);
 



More information about the linux-mtd-cvs mailing list