]> www.infradead.org Git - mtd-utils.git/commitdiff
nandwrite: add stricter sanity checking for blockalign
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 11 Jan 2017 10:45:18 +0000 (11:45 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 12 Jan 2017 10:02:18 +0000 (11:02 +0100)
This patch makes sure that a virtual erase block is always
composed of a postivie number of erase blocks (i.e. 1 or more)
and enforces the block alignment to be a power of two as
suggested by the help text and assumed throughout the program.

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

index 9602a6e35b9c6047e5c577b38cad582356cdadda..998c68c1c78cc1962b937f503e1afe2e25936871 100644 (file)
@@ -191,9 +191,13 @@ static void process_options(int argc, char * const argv[])
                errmsg_die("Can't specify negative device offset with option"
                                " -s: %lld", mtdoffset);
 
-       if (blockalign < 0)
-               errmsg_die("Can't specify negative blockalign with option -b:"
-                               " %d", blockalign);
+       if (blockalign <= 0)
+               errmsg_die("Can't specify negative or zero blockalign with "
+                               "option -b: %d", blockalign);
+
+       if (!is_power_of_2(blockalign))
+               errmsg_die("Can't specify a non-power-of-two blockalign with "
+                               "option -b: %d", blockalign);
 
        if (autoplace && noecc)
                errmsg_die("Autoplacement and no-ECC are mutually exclusive");