Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
mtd: mxc-nand: kill the NAND_MAX_PAGESIZE/NAND_MAX_OOBSIZE
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Josh Triplett <[email protected]>
Signed-off-by: Brian Norris <[email protected]>
  • Loading branch information
zyzii authored and computersforpeace committed Jan 11, 2014
1 parent 2fec386 commit a590055
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drivers/mtd/nand/mxc_nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a590055

Please sign in to comment.