Skip to contentSkip to conversation

mtd: rawnand: fix return value check for bad block status

PATCH Applied Abhishek Sahu 3 participants 3 messages Jun 13, 2018 – Jun 22, 2018

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

PATCH 1/1 mtd: rawnand: fix return value check for bad block status

Positive return value from read_oob() is making false BAD blocks. For some of the NAND controllers, OOB bytes will be protected with ECC and read_oob() will return number of bitflips. If there is any bitflip in ECC protected OOB bytes for BAD block status page, then that block is getting treated as BAD.

Fixes c120e75e0e7d ("mtd: nand: use read_oob() instead of cmdfunc() for bad block check")
---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +1 -1
index f28c3a5..4a73f73 100644
@@ -440,7 +440,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
 
 	for (; page < page_end; page++) {
 		res = chip->ecc.read_oob(mtd, chip, page);
-		if (res)
+		if (res < 0)
 			return res;
 
 		bad = chip->oob_poi[chip->badblockpos];
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc.
is a member of Code Aurora Forum, hosted by The Linux Foundation
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Boris,

Quoted 18 lines · Abhishek Sahu

Positive return value from read_oob() is making false BAD blocks. For some of the NAND controllers, OOB bytes will be protected with ECC and read_oob() will return number of bitflips. If there is any bitflip in ECC protected OOB bytes for BAD block status page, then that block is getting treated as BAD.

Fixes c120e75e0e7d ("mtd: nand: use read_oob() instead of cmdfunc() for bad block check")
---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +0 -0
index f28c3a5..4a73f73 100644

drivers/mtd/nand/raw/nand_base.c static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) · line 446

Quoted 8 lines
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -440,7 +440,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
 
 	for (; page < page_end; page++) {
 		res = chip->ecc.read_oob(mtd, chip, page);
-		if (res)
+		if (res < 0)
 			return res;
 
 		bad = chip->oob_poi[chip->badblockpos];

I suppose this patch is a good candidate to be part of a future mtd/fixes PR?

Regards,
Miquèl

#2 lore raw
Quoted 30 lines · On Mon, 18 Jun 2018 15:57:57 +0200 Miquel Raynal <[email protected]>…

Hi Boris,

Quoted 25 lines · Abhishek Sahu

Positive return value from read_oob() is making false BAD blocks. For some of the NAND controllers, OOB bytes will be protected with ECC and read_oob() will return number of bitflips. If there is any bitflip in ECC protected OOB bytes for BAD block status page, then that block is getting treated as BAD.

Fixes c120e75e0e7d ("mtd: nand: use read_oob() instead of cmdfunc() for bad block check")
---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +1 -1
index f28c3a5..4a73f73 100644
@@ -440,7 +440,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
 
 	for (; page < page_end; page++) {
 		res = chip->ecc.read_oob(mtd, chip, page);
-		if (res)
+		if (res < 0)
 			return res;
 
Quoted 3 lines

drivers/mtd/nand/raw/nand_base.c static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) · line 446

Quoted 1 line
drivers/mtd/nand/raw/nand_base.c +0 -0
 		bad = chip->oob_poi[chip->badblockpos];  

Applied.

Thanks,

Boris

Quoted 10 lines

I suppose this patch is a good candidate to be part of a future mtd/fixes PR?

Regards,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/