public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Yoshio Furuyama <ytc-mb-yfuruyama7@kioxia.com>
Cc: richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org, Patrick Doyle <pdoyle@irobot.com>
Subject: Re: [PATCH v1] mtd: nand: Fix BBT update issue
Date: Fri, 19 Mar 2021 10:23:38 +0100	[thread overview]
Message-ID: <20210319102117.47774faf@xps13> (raw)
In-Reply-To: <b04b128eaca91961597fa9586c7ccaa3934aaa03.1612501067.git.ytc-mb-yfuruyama7@kioxia.com>

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

      reply	other threads:[~2021-03-19  9:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210319102117.47774faf@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=pdoyle@irobot.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    --cc=ytc-mb-yfuruyama7@kioxia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox