[PATCH 5.10 562/563] mtd: nand: bbt: Fix corner case in bad block table handling

From: Greg Kroah-Hartman
Date: Mon Jan 24 2022 - 16:49:04 EST


From: Doyle, Patrick <pdoyle@xxxxxxxxxx>

commit fd0d8d85f7230052e638a56d1bfea170c488e6bc upstream.

In the unlikely event that both blocks 10 and 11 are marked as bad (on a
32 bit machine), then the process of marking block 10 as bad stomps on
cached entry for block 11. There are (of course) other examples.

Signed-off-by: Patrick Doyle <pdoyle@xxxxxxxxxx>
Reviewed-by: Richard Weinberger <richard@xxxxxx>
Signed-off-by: Yoshio Furuyama <ytc-mb-yfuruyama7@xxxxxxxxxx>
[<miquel.raynal@xxxxxxxxxxx>: Fixed the title]
Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>
Cc: Frieder Schrempf <frieder.schrempf@xxxxxxxxxx>
Link: https://lore.kernel.org/linux-mtd/774a92693f311e7de01e5935e720a179fb1b2468.1616635406.git.ytc-mb-yfuruyama7@xxxxxxxxxx
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/mtd/nand/bbt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -123,7 +123,7 @@ int nanddev_bbt_set_block_status(struct
unsigned int rbits = bits_per_block + offs - BITS_PER_LONG;

pos[1] &= ~GENMASK(rbits - 1, 0);
- pos[1] |= val >> rbits;
+ pos[1] |= val >> (bits_per_block - rbits);
}

return 0;