2023-09-26 07:05:16

by Wang Zhaolong

[permalink] [raw]
Subject: [PATCH -next] mtd: Add WARN_ON_ONCE() to mtd_read() to check the return value

If the driver cannot read all the requested data, -EBADMSG or
-EUCLEAN should never be returned.

Add a WARN_ON_ONCE() to help driver developers detect this error.

Signed-off-by: ZhaoLong Wang <[email protected]>
---
drivers/mtd/mtdcore.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 9bd661be3ae9..848ca4ae058d 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1505,6 +1505,8 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
ret = mtd_read_oob(mtd, from, &ops);
*retlen = ops.retlen;

+ WARN_ON_ONCE(*retlen != len && mtd_is_bitflip_or_eccerr(ret));
+
return ret;
}
EXPORT_SYMBOL_GPL(mtd_read);
--
2.31.1


2023-10-16 09:29:10

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH -next] mtd: Add WARN_ON_ONCE() to mtd_read() to check the return value

On Tue, 2023-09-26 at 06:57:33 UTC, ZhaoLong Wang wrote:
> If the driver cannot read all the requested data, -EBADMSG or
> -EUCLEAN should never be returned.
>
> Add a WARN_ON_ONCE() to help driver developers detect this error.
>
> Signed-off-by: ZhaoLong Wang <[email protected]>

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

Miquel