]> www.infradead.org Git - mtd-utils.git/commitdiff
ubiformat: process command line arguments first
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sat, 12 May 2018 19:51:56 +0000 (21:51 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sat, 12 May 2018 19:59:19 +0000 (21:59 +0200)
If libmtd_open fails, the program always exists with failure status
and prints "MTD subsystem is not present".

Even `ubiformat --help` produces the same result, which is definitely
undesired.

This patch moves command line option processing first to get the desired
behavior.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubi-utils/ubiformat.c

index c38b9b4abb1638d4d53e344bf7be1c1e09f411d6..694ab4cc45bb5d924927b59bcb9895dc566a820d 100644 (file)
@@ -692,13 +692,14 @@ int main(int argc, char * const argv[])
        struct ubigen_info ui;
        struct ubi_scan_info *si;
 
-       libmtd = libmtd_open();
-       if (!libmtd)
-               return errmsg("MTD subsystem is not present");
 
        err = parse_opt(argc, argv);
        if (err)
-               goto out_close_mtd;
+               return -1;
+
+       libmtd = libmtd_open();
+       if (!libmtd)
+               return errmsg("MTD subsystem is not present");
 
        err = mtd_get_info(libmtd, &mtd_info);
        if (err) {