On Fri, Oct 18, 2024 at 02:25:19AM +0000, Hui-Ping Chen wrote: > +static int ma35_nfi_ecc_check(struct nand_chip *chip, u8 *addr) > +{ > + struct ma35_nand_info *nand = nand_get_controller_data(chip); > + struct mtd_info *mtd = nand_to_mtd(chip); > + int i, j, nchunks = 0; > + int report_err = 0; > + int err_cnt = 0; > + u32 status; > + > + nchunks = mtd->writesize / chip->ecc.steps; > + if (nchunks < 4) > + nchunks = 1; > + else > + nchunks /= 4; > + > + for (j = 0; j < nchunks; j++) { > + status = readl(nand->regs + MA35_NFI_REG_NANDECCES0 + j * 4); > + if (!status) > + continue; > + > + for (i = 0; i < 4; i++) { > + if ((status & ECC_STATUS_MASK) == 0x01) { > + /* Correctable error */ > + err_cnt = (status >> 2) & ECC_ERR_CNT_MASK; > + ma35_nfi_correct(chip, j * 4 + i, err_cnt, addr); > + report_err += err_cnt; This is still wrong. This should be report_err = max(report_err, err_cnt); You have to search for the subpage that has the most bitflips and return the number of bitflips on that subpage, *not* the total amount of errors on the whole page. That said, the statistic counter should still count the total number of bitflips occurred. Sascha > + } else { > + /* Uncorrectable error */ > + dev_warn(nand->dev, "uncorrectable error! 0x%4x\n", status); > + return -EBADMSG; > + } > + status >>= 8; > + } > + } > + return report_err; > +} > + -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |