]> www.infradead.org Git - mtd-utils.git/commitdiff
ubiformat/ubinize: Don't randomize 0xFFFFFFFF sequence number
authorMichael Roth <mroth@nessie.de>
Wed, 23 Sep 2009 13:01:27 +0000 (15:01 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mon, 28 Sep 2009 08:19:14 +0000 (11:19 +0300)
args.image_seq is of type uint32_t and was initialized to -1 which
becomes 0xFFFFFFFF in this case. Later the value -1 was used as a flag
that args.image_seq should be replaced with a randomized value.

With the option --image-seq (-Q) a user could provide any sequence
number at will.

But when the user provided sequence number was 0xFFFFFFFF this was
understood effectivly as -1 and got overridden by a randomized
sequence number.

So this patch change the programm flow to respect the principle of
least surprise and never use a randomized sequence number when the
user provide one at own will.

Signed-off-by: Michael Roth <mroth@nessie.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
ubi-utils/src/ubiformat.c
ubi-utils/src/ubinize.c

index bed033953724955319abad6a9f773776b5ea58a8..54363d785a6dfb731f7038bb62563d80363fcaf5 100644 (file)
@@ -70,7 +70,6 @@ struct args {
 static struct args args =
 {
        .ubi_ver   = 1,
-       .image_seq = -1,
 };
 
 static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
@@ -131,6 +130,9 @@ static const struct option long_options[] = {
 
 static int parse_opt(int argc, char * const argv[])
 {
+       srand(getpid());
+       args.image_seq = random();
+
        while (1) {
                int key;
                char *endp;
@@ -235,10 +237,6 @@ static int parse_opt(int argc, char * const argv[])
        if (args.image && args.novtbl)
                return errmsg("-n cannot be used together with -f");
 
-       if (!args.image_seq == -1) {
-               srand(getpid());
-               args.image_seq = random();
-       }
 
        args.node = argv[optind];
        return 0;
index a46833c86a429eb5e779c243fca17bef14804fdb..74ddc0fe8af5726a592c82a213802d6ecf83bddd 100644 (file)
@@ -153,11 +153,13 @@ static struct args args = {
        .min_io_size  = -1,
        .subpage_size = -1,
        .ubi_ver      = 1,
-       .image_seq    = -1,
 };
 
 static int parse_opt(int argc, char * const argv[])
 {
+       srand(getpid());
+       args.image_seq = random();
+
        while (1) {
                int key;
                char *endp;
@@ -283,10 +285,6 @@ static int parse_opt(int argc, char * const argv[])
                        return errmsg("VID header offset has to be multiple of min. I/O unit size");
        }
 
-       if (!args.image_seq == -1) {
-               srand(getpid());
-               args.image_seq = random();
-       }
        return 0;
 }