From db0f003c66c720fd799897f3eab1b485b9f66ed7 Mon Sep 17 00:00:00 2001 From: Jon Lin Date: Wed, 8 Sep 2021 20:02:21 +0800 Subject: [PATCH] mtd: nand: bbt: Fix error in BBT block location methord Avoid the high 32btis input param of GENMASK bigger then BITS_PER_LONG. For example offs 62, bits_per_block 3, and BITS_PER_LONG 64, then: GENMASK(offs + bits_per_block - 1, offs) -> GENMASK(64, 62) -> 0. But actually we want to mask GENMASK(63, 62) which is equals to 0xc000000000000000. Change-Id: Ie3ee89a4b3e3deca45ccf429bfdfc5b88e3e6b9c Signed-off-by: Jon Lin --- drivers/mtd/nand/bbt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c index 044adf913854..cfc78198ecd5 100644 --- a/drivers/mtd/nand/bbt.c +++ b/drivers/mtd/nand/bbt.c @@ -116,7 +116,10 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry, if (entry >= nanddev_neraseblocks(nand)) return -ERANGE; - pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs); + if (bits_per_block + offs > BITS_PER_LONG) + pos[0] &= ~GENMASK(BITS_PER_LONG - 1, offs); + else + pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs); pos[0] |= val << offs; if (bits_per_block + offs > BITS_PER_LONG) {