]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mtd: Add WARN_ON_ONCE() to mtd_read() to check the return value
authorZhaoLong Wang <wangzhaolong1@huawei.com>
Tue, 26 Sep 2023 06:57:33 +0000 (14:57 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 16 Oct 2023 08:50:28 +0000 (10:50 +0200)
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>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230926065733.3240322-1-wangzhaolong1@huawei.com
drivers/mtd/mtdcore.c

index 9bd661be3ae93d55c70713f5e708e34111737930..848ca4ae058d83452da81ecbe51caa215e6f6238 100644 (file)
@@ -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);