diff mbox series

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

Message ID 1528880556-20348-1-git-send-email-absahu@codeaurora.org
State Accepted
Delegated to: Boris Brezillon
Headers show
Series mtd: rawnand: fix return value check for bad block status | expand

Commit Message

Abhishek Sahu June 13, 2018, 9:02 a.m. UTC
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")
Cc: <stable@vger.kernel.org>
Signed-off-by: Abhishek Sahu <absahu@codeaurora.org>
---
 drivers/mtd/nand/raw/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Miquel Raynal June 18, 2018, 1:57 p.m. UTC | #1
Hi Boris,

On Wed, 13 Jun 2018 14:32:36 +0530, Abhishek Sahu
<absahu@codeaurora.org> wrote:

> 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")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Abhishek Sahu <absahu@codeaurora.org>
> ---
>  drivers/mtd/nand/raw/nand_base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index f28c3a5..4a73f73 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -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];

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

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

Regards,
Miquèl
Boris Brezillon June 22, 2018, 11:34 a.m. UTC | #2
On Mon, 18 Jun 2018 15:57:57 +0200
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> Hi Boris,
> 
> On Wed, 13 Jun 2018 14:32:36 +0530, Abhishek Sahu
> <absahu@codeaurora.org> wrote:
> 
> > 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")
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Abhishek Sahu <absahu@codeaurora.org>
> > ---
> >  drivers/mtd/nand/raw/nand_base.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> > index f28c3a5..4a73f73 100644
> > --- a/drivers/mtd/nand/raw/nand_base.c
> > +++ b/drivers/mtd/nand/raw/nand_base.c
> > @@ -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];  
> 
> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied.

Thanks,

Boris

> 
> 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/
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index f28c3a5..4a73f73 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -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];