From: Jagdish Gediya Date: Fri, 23 Mar 2018 21:25:51 +0000 (+0530) Subject: mtd: nand: fsl_ifc: Fix eccstat array overflow for IFC ver >= 2.0.0 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f195fad178979020b226671cafec9f9592860174;p=project%2Fbcm63xx%2Fu-boot.git mtd: nand: fsl_ifc: Fix eccstat array overflow for IFC ver >= 2.0.0 Number of ECC status registers i.e. (ECCSTATx) has been increased in IFC version 2.0.0 due to increase in SRAM size. This is causing eccstat array to over flow. So, replace eccstat array with u32 variable to make it fail-safe and independent of number of ECC status registers or SRAM size. Signed-off-by: Prabhakar Kushwaha Signed-off-by: Jagdish Gediya Reviewed-by: York Sun --- diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c index a82913cac1..3cb487510a 100644 --- a/drivers/mtd/nand/fsl_ifc_nand.c +++ b/drivers/mtd/nand/fsl_ifc_nand.c @@ -269,14 +269,9 @@ static int is_blank(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl, /* returns nonzero if entire page is blank */ static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl, - u32 *eccstat, unsigned int bufnum) + u32 eccstat, unsigned int bufnum) { - u32 reg = eccstat[bufnum / 4]; - int errors; - - errors = (reg >> ((3 - bufnum % 4) * 8)) & 15; - - return errors; + return (eccstat >> ((3 - bufnum % 4) * 8)) & 15; } /* @@ -290,7 +285,7 @@ static int fsl_ifc_run_command(struct mtd_info *mtd) struct fsl_ifc_runtime *ifc = ctrl->regs.rregs; u32 timeo = (CONFIG_SYS_HZ * 10) / 1000; u32 time_start; - u32 eccstat[8] = {0}; + u32 eccstat; int i; /* set the chip select for NAND Transaction */ @@ -320,20 +315,17 @@ static int fsl_ifc_run_command(struct mtd_info *mtd) if (ctrl->eccread) { int errors; int bufnum = ctrl->page & priv->bufnum_mask; - int sector = bufnum * chip->ecc.steps; - int sector_end = sector + chip->ecc.steps - 1; - - for (i = sector / 4; i <= sector_end / 4; i++) { - if (i >= ARRAY_SIZE(eccstat)) { - printf("%s: eccstat too small for %d\n", - __func__, i); - return -EIO; - } + int sector_start = bufnum * chip->ecc.steps; + int sector_end = sector_start + chip->ecc.steps - 1; + u32 *eccstat_regs; - eccstat[i] = ifc_in32(&ifc->ifc_nand.nand_eccstat[i]); - } + eccstat_regs = ifc->ifc_nand.nand_eccstat; + eccstat = ifc_in32(&eccstat_regs[sector_start / 4]); + + for (i = sector_start; i <= sector_end; i++) { + if ((i != sector_start) && !(i % 4)) + eccstat = ifc_in32(&eccstat_regs[i / 4]); - for (i = sector; i <= sector_end; i++) { errors = check_read_ecc(mtd, ctrl, eccstat, i); if (errors == 15) { diff --git a/include/fsl_ifc.h b/include/fsl_ifc.h index d051e92ce4..8120ca0de8 100644 --- a/include/fsl_ifc.h +++ b/include/fsl_ifc.h @@ -891,8 +891,8 @@ struct fsl_ifc_nand { u32 nand_erattr1; u32 res19[0x10]; u32 nand_fsr; - u32 res20[0x3]; - u32 nand_eccstat[6]; + u32 res20[0x1]; + u32 nand_eccstat[8]; u32 res21[0x1c]; u32 nanndcr; u32 res22[0x2];