linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mtd: nand: Fix BBT update issue
       [not found] <1613435875-6846-1-git-send-email-ytc-mb-yfuruyama7@kioxia.com>
@ 2021-02-16  0:37 ` Yoshio Furuyama
  2021-03-19  9:23   ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Yoshio Furuyama @ 2021-02-16  0:37 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel

Fixed issue of manages BBT (Bad Block Table).
It didn't mark correctly when a specific block was bad block.

This issue occurs when the bad block mark (3-bit chunk) is 
crosses over 32 bit (e.g. Block10, Block21...) unit.

Signed-off-by: Yoshio Furuyama <ytc-mb-yfuruyama7@kioxia.com>
---
 drivers/mtd/nand/bbt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
index 044adf913854..979c47e61381 100644
--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -112,18 +112,20 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
 			     ((entry * bits_per_block) / BITS_PER_LONG);
 	unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
 	unsigned long val = status & GENMASK(bits_per_block - 1, 0);
+	unsigned long shift = ((bits_per_block + offs <= BITS_PER_LONG) ?
+					(offs + bits_per_block - 1) : (BITS_PER_LONG - 1));
 
 	if (entry >= nanddev_neraseblocks(nand))
 		return -ERANGE;
 
-	pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);
+	pos[0] &= ~GENMASK(shift, offs);
 	pos[0] |= val << offs;
 
 	if (bits_per_block + offs > BITS_PER_LONG) {
 		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_LONG - offs));
 	}
 
 	return 0;
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] mtd: nand: Fix BBT update issue
  2021-02-16  0:37 ` [PATCH v1] mtd: nand: Fix BBT update issue Yoshio Furuyama
@ 2021-03-19  9:23   ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2021-03-19  9:23 UTC (permalink / raw)
  To: Yoshio Furuyama; +Cc: richard, vigneshr, linux-mtd, linux-kernel, Patrick Doyle

Hi Yoshio,

+ Patrick

Yoshio Furuyama <ytc-mb-yfuruyama7@kioxia.com> wrote on Tue, 16 Feb
2021 09:37:55 +0900:

> Fixed issue of manages BBT (Bad Block Table).
> It didn't mark correctly when a specific block was bad block.
> 
> This issue occurs when the bad block mark (3-bit chunk) is 
> crosses over 32 bit (e.g. Block10, Block21...) unit.
> 

Thanks for the patch and sorry for the very long wait period, I wanted
to understand better the issue but I didn't had the time to do it.

Would you mind having a look at Patrick's fix merged in U-Boot a year
ago:

commit 06fc4573b9d0878dd1d3b302884601263fe6e85f
Author: Doyle, Patrick <pdoyle@irobot.com>
Date:   Wed Jul 15 14:46:34 2020 +0000

    Fix corner case in bad block table handling.
    
    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@irobot.com>
    Reviewed-by: Richard Weinberger <richard@nod.at>

diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
index 84d60b86521..294daee7b22 100644
--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -127,7 +127,7 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
                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;

It looks both patches fix different errors but I wonder if merging Patrick's patch first would not make more sense. 

Ideally, could you please send a series with the two patches, perhaps
Patrick's patch first, then yours, adding a Fixes and Cc: stable tags
to both?

> Signed-off-by: Yoshio Furuyama <ytc-mb-yfuruyama7@kioxia.com>
> ---
>  drivers/mtd/nand/bbt.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
> index 044adf913854..979c47e61381 100644
> --- a/drivers/mtd/nand/bbt.c
> +++ b/drivers/mtd/nand/bbt.c
> @@ -112,18 +112,20 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
>  			     ((entry * bits_per_block) / BITS_PER_LONG);
>  	unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
>  	unsigned long val = status & GENMASK(bits_per_block - 1, 0);
> +	unsigned long shift = ((bits_per_block + offs <= BITS_PER_LONG) ?
> +					(offs + bits_per_block - 1) : (BITS_PER_LONG - 1));
>  
>  	if (entry >= nanddev_neraseblocks(nand))
>  		return -ERANGE;
>  
> -	pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);
> +	pos[0] &= ~GENMASK(shift, offs);
>  	pos[0] |= val << offs;
>  
>  	if (bits_per_block + offs > BITS_PER_LONG) {
>  		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_LONG - offs));
>  	}
>  
>  	return 0;

Thanks,
Miquèl

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-19  9:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1613435875-6846-1-git-send-email-ytc-mb-yfuruyama7@kioxia.com>
2021-02-16  0:37 ` [PATCH v1] mtd: nand: Fix BBT update issue Yoshio Furuyama
2021-03-19  9:23   ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).