[PATCH 15/22] mtd: have mtd_read populate retlen always

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Mar 13 00:34:38 PDT 2025


We currently populate retlen only on successful reads of more than zero
bytes, while Linux function with the same name populates it
unconditionally.

Mimic the Linux API for compatibility.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mtd/core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 562443275fe6..c75c52dcb3a5 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -375,16 +375,15 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 		.len = len,
 		.datbuf = buf,
 	};
-	int ret;
+	int ret = 0;
 
 	if (from < 0 || from >= mtd->size || len > mtd->size - from)
 		return -EINVAL;
-	if (!len)
-		return 0;
 
-	ret = mtd_read_oob(mtd, from, &ops);
+	if (len)
+		ret = mtd_read_oob(mtd, from, &ops);
+
 	*retlen = ops.retlen;
-
 	return ret;
 }
 
-- 
2.39.5




More information about the barebox mailing list