diff mbox series

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

Message ID 20230926065733.3240322-1-wangzhaolong1@huawei.com
State Accepted
Headers show
Series [-next] mtd: Add WARN_ON_ONCE() to mtd_read() to check the return value | expand

Commit Message

ZhaoLong Wang Sept. 26, 2023, 6:57 a.m. UTC
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 <wangzhaolong1@huawei.com>
---
 drivers/mtd/mtdcore.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Miquel Raynal Oct. 16, 2023, 9:28 a.m. UTC | #1
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 <wangzhaolong1@huawei.com>

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

Miquel
diff mbox series

Patch

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);