linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd-utils: lib: mtd_read: Take the buffer offset into account when reading
@ 2015-10-06 12:13 Marcus Prebble
  2015-11-12 19:09 ` Brian Norris
  0 siblings, 1 reply; 6+ messages in thread
From: Marcus Prebble @ 2015-10-06 12:13 UTC (permalink / raw)
  To: linux-mtd@lists.infradead.org; +Cc: Ricard Wanderlöf

[-- Attachment #1: Type: text/plain, Size: 246 bytes --]

Hi mtd-list,

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.

Suggested patch attached (git format-patch)

-Marcus

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mtd_read-Take-the-buffer-offset-into-account-when-re.patch --]
[-- Type: text/x-patch; name="0001-mtd_read-Take-the-buffer-offset-into-account-when-re.patch", Size: 944 bytes --]

From 5dccbbd87604665e896472d52f3351c14c24d2b3 Mon Sep 17 00:00:00 2001
From: Marcus Prebble <prebble@axis.com>
Date: Mon, 5 Oct 2015 17:32:54 +0200
Subject: [PATCH] mtd_read: Take the buffer offset into account when reading

Subsequent calls to read() within the loop will now no longer
overwrite the existing contents of buf.
---
 lib/libmtd.c | 4 ++--
 1 file 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;
 	}
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-11-17 20:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06 12:13 [PATCH] mtd-utils: lib: mtd_read: Take the buffer offset into account when reading Marcus Prebble
2015-11-12 19:09 ` Brian Norris
2015-11-13 10:07   ` Marcus Prebble
2015-11-13 19:17     ` Brian Norris
2015-11-17  8:43       ` Marcus Prebble
2015-11-17 20:34         ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).