linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtdblock: tolerate corrected bit-flips
@ 2023-03-14 16:56 Bang Li
  2023-03-22 16:08 ` Miquel Raynal
  0 siblings, 1 reply; 6+ messages in thread
From: Bang Li @ 2023-03-14 16:56 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Bang Li

mtd_read() may return -EUCLEAN in case of corrected bit-flips.This
particular condition should not be treated like an error.

Signed-off-by: Bang Li <libang.linuxer@gmail.com>
---
 drivers/mtd/mtdblock_ro.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 7c51952ce55d..66ffc9f1ead2 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -16,8 +16,10 @@ static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
 			      unsigned long block, char *buf)
 {
 	size_t retlen;
+	int err;
 
-	if (mtd_read(dev->mtd, (block * 512), 512, &retlen, buf))
+	err = mtd_read(dev->mtd, (block * 512), 512, &retlen, buf);
+	if (err && !mtd_is_bitflip(err))
 		return 1;
 	return 0;
 }
-- 
2.25.1


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

* Re: [PATCH] mtdblock: tolerate corrected bit-flips
  2023-03-14 16:56 [PATCH] mtdblock: tolerate corrected bit-flips Bang Li
@ 2023-03-22 16:08 ` Miquel Raynal
  0 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2023-03-22 16:08 UTC (permalink / raw)
  To: Bang Li, miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel

On Tue, 2023-03-14 at 16:56:53 UTC, Bang Li wrote:
> mtd_read() may return -EUCLEAN in case of corrected bit-flips.This
> particular condition should not be treated like an error.
> 
> Signed-off-by: Bang Li <libang.linuxer@gmail.com>

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

Miquel

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

* Re: [PATCH] mtdblock: tolerate corrected bit-flips
  2023-03-28 13:21   ` Richard Weinberger
@ 2023-03-28 14:00     ` Miquel Raynal
  0 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2023-03-28 14:00 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Bang Li, Vignesh Raghavendra, linux-mtd, linux-kernel

Hi Richard,

richard@nod.at wrote on Tue, 28 Mar 2023 15:21:50 +0200 (CEST):

> Hi!
> 
> ----- Ursprüngliche Mail -----
> > libang.linuxer@gmail.com wrote on Thu, 23 Mar 2023 22:03:50 +0800:
> >   
> >> mtd_read() may return -EUCLEAN in case of corrected bit-flips.This
> >> particular condition should not be treated like an error.  
> > 
> > I'm fine with the patch, Richard, are you okay as well?  
> 
> Hm yes. I see the bug. I think it broke about 10 years ago
> by e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()").
> 
> In the early day I'd expect someone to hit this bug but I guess
> on the last 10 years mtdblock had no real users.

Right.

Well, anyhow I guess this patch deserves a Fixes/Cc: stable # v3.7+

Li, can you please re-send with the proper tags? Thanks.

Thanks,
Miquèl

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

* Re: [PATCH] mtdblock: tolerate corrected bit-flips
  2023-03-28 12:58 ` Miquel Raynal
@ 2023-03-28 13:21   ` Richard Weinberger
  2023-03-28 14:00     ` Miquel Raynal
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Weinberger @ 2023-03-28 13:21 UTC (permalink / raw)
  To: Miquel Raynal; +Cc: Bang Li, Vignesh Raghavendra, linux-mtd, linux-kernel

Hi!

----- Ursprüngliche Mail -----
> libang.linuxer@gmail.com wrote on Thu, 23 Mar 2023 22:03:50 +0800:
> 
>> mtd_read() may return -EUCLEAN in case of corrected bit-flips.This
>> particular condition should not be treated like an error.
> 
> I'm fine with the patch, Richard, are you okay as well?

Hm yes. I see the bug. I think it broke about 10 years ago
by e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()").

In the early day I'd expect someone to hit this bug but I guess
on the last 10 years mtdblock had no real users.

Thanks,
//richard

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

* Re: [PATCH] mtdblock: tolerate corrected bit-flips
  2023-03-23 14:03 Bang Li
@ 2023-03-28 12:58 ` Miquel Raynal
  2023-03-28 13:21   ` Richard Weinberger
  0 siblings, 1 reply; 6+ messages in thread
From: Miquel Raynal @ 2023-03-28 12:58 UTC (permalink / raw)
  To: Bang Li; +Cc: richard, vigneshr, linux-mtd, linux-kernel

Hello,

libang.linuxer@gmail.com wrote on Thu, 23 Mar 2023 22:03:50 +0800:

> mtd_read() may return -EUCLEAN in case of corrected bit-flips.This
> particular condition should not be treated like an error.

I'm fine with the patch, Richard, are you okay as well?

> Signed-off-by: Bang Li <libang.linuxer@gmail.com>
> ---
>  drivers/mtd/mtdblock.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
> index 1e94e7d10b8b..a0a1194dc1d9 100644
> --- a/drivers/mtd/mtdblock.c
> +++ b/drivers/mtd/mtdblock.c
> @@ -153,7 +153,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
>  				mtdblk->cache_state = STATE_EMPTY;
>  				ret = mtd_read(mtd, sect_start, sect_size,
>  					       &retlen, mtdblk->cache_data);
> -				if (ret)
> +				if (ret && !mtd_is_bitflip(ret))
>  					return ret;
>  				if (retlen != sect_size)
>  					return -EIO;
> @@ -188,8 +188,12 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
>  	pr_debug("mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n",
>  			mtd->name, pos, len);
>  
> -	if (!sect_size)
> -		return mtd_read(mtd, pos, len, &retlen, buf);
> +	if (!sect_size) {
> +		ret = mtd_read(mtd, pos, len, &retlen, buf);
> +		if (ret && !mtd_is_bitflip(ret))
> +			return ret;
> +		return 0;
> +	}
>  
>  	while (len > 0) {
>  		unsigned long sect_start = (pos/sect_size)*sect_size;
> @@ -209,7 +213,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
>  			memcpy (buf, mtdblk->cache_data + offset, size);
>  		} else {
>  			ret = mtd_read(mtd, pos, size, &retlen, buf);
> -			if (ret)
> +			if (ret && !mtd_is_bitflip(ret))
>  				return ret;
>  			if (retlen != size)
>  				return -EIO;


Thanks,
Miquèl

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

* [PATCH] mtdblock: tolerate corrected bit-flips
@ 2023-03-23 14:03 Bang Li
  2023-03-28 12:58 ` Miquel Raynal
  0 siblings, 1 reply; 6+ messages in thread
From: Bang Li @ 2023-03-23 14:03 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Bang Li

mtd_read() may return -EUCLEAN in case of corrected bit-flips.This
particular condition should not be treated like an error.

Signed-off-by: Bang Li <libang.linuxer@gmail.com>
---
 drivers/mtd/mtdblock.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 1e94e7d10b8b..a0a1194dc1d9 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -153,7 +153,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
 				mtdblk->cache_state = STATE_EMPTY;
 				ret = mtd_read(mtd, sect_start, sect_size,
 					       &retlen, mtdblk->cache_data);
-				if (ret)
+				if (ret && !mtd_is_bitflip(ret))
 					return ret;
 				if (retlen != sect_size)
 					return -EIO;
@@ -188,8 +188,12 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
 	pr_debug("mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n",
 			mtd->name, pos, len);
 
-	if (!sect_size)
-		return mtd_read(mtd, pos, len, &retlen, buf);
+	if (!sect_size) {
+		ret = mtd_read(mtd, pos, len, &retlen, buf);
+		if (ret && !mtd_is_bitflip(ret))
+			return ret;
+		return 0;
+	}
 
 	while (len > 0) {
 		unsigned long sect_start = (pos/sect_size)*sect_size;
@@ -209,7 +213,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
 			memcpy (buf, mtdblk->cache_data + offset, size);
 		} else {
 			ret = mtd_read(mtd, pos, size, &retlen, buf);
-			if (ret)
+			if (ret && !mtd_is_bitflip(ret))
 				return ret;
 			if (retlen != size)
 				return -EIO;
-- 
2.25.1


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

end of thread, other threads:[~2023-03-28 14:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 16:56 [PATCH] mtdblock: tolerate corrected bit-flips Bang Li
2023-03-22 16:08 ` Miquel Raynal
2023-03-23 14:03 Bang Li
2023-03-28 12:58 ` Miquel Raynal
2023-03-28 13:21   ` Richard Weinberger
2023-03-28 14:00     ` 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).