mtd-utils: mtd_debug: check amount of data read.
Michal Suchanek
hramrach at gmail.com
Mon Jul 27 06:47:10 PDT 2015
The kernel refuses to read more data from a MTD device than the device
size. However, mtd_debug does not check the amount of data read as
returned by read(2) and assumes the requested amount is always read when
there is no error. Reading 8M data from a 4M flash chip results in 8M
file containing the flash data at the start.
Signed-off-by: Michal Suchanek <hramrach at gmail.com>
---
mtd_debug.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/mtd_debug.c b/mtd_debug.c
index d6993ce..f3826cf 100644
--- a/mtd_debug.c
+++ b/mtd_debug.c
@@ -141,7 +141,10 @@ retry:
perror("read()");
goto err2;
}
- err = write(outfd, buf, size);
+ if (err < size) {
+ fprintf(stderr, "%s: short read, requested %#x, read %#x\n", __func__, size, err);
+ }
+ err = write(outfd, buf, err);
if (err < 0) {
fprintf(stderr, "%s: write, size %#x, n %#x\n", __func__, size, n);
perror("write()");
--
2.1.4
More information about the linux-mtd
mailing list