[U-Boot] [PATCH] fix: nand: Fix nand RW access wrappers

kostap at marvell.com kostap at marvell.com
Wed Feb 22 13:29:19 UTC 2017


From: Konstantin Porotchkin <kostap at marvell.com>

The inline functions nand_read and nand_write wrap calls
to mtd_read and mtd_write APIs.
The MTD APIs are using an additional parameter for returning
the amount of bytes actually handled by the RW operation.
The wrapper uses a pointer to the same input "len" parameter
for both input and output bytes count when calls to MTD API.
However the MTD finctions are zeroing the returning bytes
count at the beginning effectively zeroing the input/output
buffer length as well.

Signed-off-by: Konstantin Porotchkin <kostap at marvell.com>
Cc: Scott Wood <oss at buserror.net>
Cc: Stefan Roese <sr at denx.de>
---
 include/nand.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/nand.h b/include/nand.h
index b6eb223..8414c6c 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -48,13 +48,21 @@ extern struct mtd_info *nand_info[];
 static inline int nand_read(struct mtd_info *info, loff_t ofs, size_t *len,
 			    u_char *buf)
 {
-	return mtd_read(info, ofs, *len, (size_t *)len, buf);
+	size_t retlen;
+	int ret = mtd_read(info, ofs, *len, &retlen, buf);
+
+	*len = retlen;
+	return ret;
 }
 
 static inline int nand_write(struct mtd_info *info, loff_t ofs, size_t *len,
 			     u_char *buf)
 {
-	return mtd_write(info, ofs, *len, (size_t *)len, buf);
+	size_t retlen;
+	int ret = mtd_write(info, ofs, *len, &retlen, buf);
+
+	*len = retlen;
+	return ret;
 }
 
 static inline int nand_block_isbad(struct mtd_info *info, loff_t ofs)
-- 
2.7.4



More information about the U-Boot mailing list