This patch modifies the internal helpers to read and parse integers from sysfs files by initializing them first and removes turns an obscure "a = open(...) if (a >= 0) {...} if (a == -1) {...}" inside recv_image into a more straight forward if/else branch. Signed-off-by: David Oberhollenzer <david.oberhollenzer@xxxxxxxxxxxxx> --- lib/libmtd.c | 2 ++ lib/libubi.c | 1 + misc-utils/recv_image.c | 3 +-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index 564e5c0..9d8d0e8 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -217,6 +217,7 @@ static int read_hex_ll(const char *file, long long *value) } buf[rd] = '\0'; + *value = 0; if (sscanf(buf, "%llx\n", value) != 1) { errmsg("cannot read integer from \"%s\"\n", file); errno = EINVAL; @@ -269,6 +270,7 @@ static int read_pos_ll(const char *file, long long *value) goto out_error; } + *value = 0; if (sscanf(buf, "%lld\n", value) != 1) { errmsg("cannot read integer from \"%s\"\n", file); errno = EINVAL; diff --git a/lib/libubi.c b/lib/libubi.c index 4322a19..aaeeb38 100644 --- a/lib/libubi.c +++ b/lib/libubi.c @@ -94,6 +94,7 @@ static int read_positive_ll(const char *file, long long *value) } buf[rd] = '\0'; + *value = 0; if (sscanf(buf, "%lld\n", value) != 1) { errmsg("cannot read integer from \"%s\"\n", file); errno = EINVAL; diff --git a/misc-utils/recv_image.c b/misc-utils/recv_image.c index 7f6662b..eeaa2e2 100644 --- a/misc-utils/recv_image.c +++ b/misc-utils/recv_image.c @@ -81,8 +81,7 @@ int main(int argc, char **argv) printf("Receive to MTD device %s with erasesize %d\n", argv[3], meminfo.erasesize); } - } - if (flfd == -1) { + } else { /* Try again, as if it's a file */ flfd = open(argv[3], O_CREAT|O_TRUNC|O_RDWR, 0644); if (flfd < 0) { -- 2.24.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/