path: root/lib
diff options
authorMarcus Prebble <>2015-10-06 14:13:23 +0200
committerBrian Norris <>2015-11-17 12:31:37 -0800
commit772469f83a54e4bc077880212e37b0e7b9ba85ac (patch)
tree4246e18b90ef8db0ef89fab7d947b117688af9e5 /lib
parent08b243fb24c6b8b7bf0f31a102802a1927a1d4d7 (diff)
libmtd: mtd_read: Take the buffer offset into account when reading
Assuming the read() call does not return zero and the result is less than len, the current implementation will overwrite the data already read in buf which doesn't seem correct. With this patch, subsequent calls to read() within the loop will now no longer overwrite the existing contents of buf. Signed-off-by: Marcus Prebble <> Signed-off-by: Brian Norris <>
Diffstat (limited to 'lib')
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 60b4782..bf6d71f 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -1072,10 +1072,10 @@ int mtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
mtd->mtd_num, seek);
while (rd < len) {
- ret = read(fd, buf, len);
+ ret = read(fd, buf + rd, len - rd);
if (ret < 0)
return sys_errmsg("cannot read %d bytes from mtd%d (eraseblock %d, offset %d)",
- len, mtd->mtd_num, eb, offs);
+ len - rd, mtd->mtd_num, eb, offs + rd);
rd += ret;