Skip to contentSkip to conversation

mtd: rawnand: nand_bbt: Skip bad blocks when searching for the BBT in NAND

PATCH Applied Stefan Riedmueller 2 participants 2 messages Mar 25, 2021 – Mar 28, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: rawnand: nand_bbt: Skip bad blocks when searching for the BBT in NAND

The blocks containing the bad block table can become bad as well. So make sure to skip any blocks that are marked bad when searching for the bad block table.

Otherwise in very rare cases where two BBT blocks wear out it might happen that an obsolete BBT is used instead of a newer available version.

---
 drivers/mtd/nand/raw/nand_bbt.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/mtd/nand/raw/nand_bbt.c +5 -0
index dced32a126d9..6e25a5ce5ba9 100644
@@ -525,6 +525,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
 {
 	u64 targetsize = nanddev_target_size(&this->base);
 	struct mtd_info *mtd = nand_to_mtd(this);
+	struct nand_bbt_descr *bd = this->badblock_pattern;
 	int i, chips;
 	int startblock, block, dir;
 	int scanlen = mtd->writesize + mtd->oobsize;
@@ -560,6 +561,10 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
 			int actblock = startblock + dir * block;
 			loff_t offs = (loff_t)actblock << this->bbt_erase_shift;
 
+			/* Check if block is marked bad */
+			if (scan_block_fast(this, bd, offs, buf))
+				continue;
+
 			/* Read first page */
 			scan_read(this, buf, offs, mtd->writesize, td);
 			if (!check_pattern(buf, scanlen, mtd->writesize, td)) {
Signature · 6 lines
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Applied
#1 lore raw
Quoted 9 lines · Stefan Riedmueller

The blocks containing the bad block table can become bad as well. So make sure to skip any blocks that are marked bad when searching for the bad block table.

Otherwise in very rare cases where two BBT blocks wear out it might happen that an obsolete BBT is used instead of a newer available version.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel