Let the variable "numblocks" contain the number of blocks of the NAND device (and not twice this value). Also the loop variable counts blocks now instead of the doubled value. Further calculate the offset of the i-th block from i instead of incrementing in each step and pick a more sensbile variable name for it. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx> --- drivers/mtd/nand/raw/mxc_nand.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/nand/raw/mxc_nand.c b/drivers/mtd/nand/raw/mxc_nand.c index da1c426d1951..a72275480144 100644 --- a/drivers/mtd/nand/raw/mxc_nand.c +++ b/drivers/mtd/nand/raw/mxc_nand.c @@ -1583,31 +1583,31 @@ static int imxnd_create_bbt(struct nand_chip *chip) { struct mtd_info *mtd = nand_to_mtd(chip); int len, i, numblocks, ret; - loff_t from = 0; uint8_t *bbt; - len = mtd->size >> (chip->bbt_erase_shift + 2); + numblocks = mtd->size >> chip->bbt_erase_shift; - /* Allocate memory (2bit per block) and clear the memory bad block table */ + /* + * Allocate memory (2bit per block = 1 byte per 4 blocks) and clear the + * memory bad block table + */ + len = (numblocks + 3) >> 2; bbt = kzalloc(len, GFP_KERNEL); if (!bbt) return -ENOMEM; - numblocks = mtd->size >> (chip->bbt_erase_shift - 1); + for (i = 0; i < numblocks; ++i) { + loff_t ofs = i << chip->bbt_erase_shift; - for (i = 0; i < numblocks;) { - ret = checkbad(chip, from); + ret = checkbad(chip, ofs); if (ret < 0) goto out; if (ret) { - bbt[i >> 3] |= 0x03 << (i & 0x6); + bbt[i >> 2] |= 0x03 << (2 * (i & 0x3)); dev_info(mtd->dev.parent, "Bad eraseblock %d at 0x%08x\n", - i >> 1, (unsigned int)from); + i, (unsigned int)ofs); } - - i += 2; - from += (1 << chip->bbt_erase_shift); } chip->bbt_td->options |= NAND_BBT_CREATE; -- 2.43.0