All of lore.kernel.org
 help / color / mirror / Atom feed
* Two small patches for mtd-utils
@ 2009-09-23 13:01 Michael Roth
  2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: fix more 64-bit image sequence number confusion Michael Roth
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michael Roth @ 2009-09-23 13:01 UTC (permalink / raw)
  To: linux-mtd

Hello,

two small patches for mtd-utils.
please CC me as I'm not on this list.

Michael Roth

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ubiformat, ubinize: fix more 64-bit image sequence number confusion
  2009-09-23 13:01 Two small patches for mtd-utils Michael Roth
@ 2009-09-23 13:01 ` Michael Roth
  2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: Don't randomize 0xFFFFFFFF sequence number Michael Roth
  2009-09-28  8:59 ` Two small patches for mtd-utils Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Roth @ 2009-09-23 13:01 UTC (permalink / raw)
  To: linux-mtd; +Cc: Michael Roth

The sequence number is only 32 bit as the strtoul() function.

Signed-off-by: Michael Roth <mroth@nessie.de>
---
 ubi-utils/src/ubiformat.c |    2 +-
 ubi-utils/src/ubinize.c   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c
index 345593c..bed0339 100644
--- a/ubi-utils/src/ubiformat.c
+++ b/ubi-utils/src/ubiformat.c
@@ -134,7 +134,7 @@ static int parse_opt(int argc, char * const argv[])
 	while (1) {
 		int key;
 		char *endp;
-		unsigned long long image_seq;
+		unsigned long int image_seq;
 
 		key = getopt_long(argc, argv, "nh?Vyqve:x:s:O:f:S:", long_options, NULL);
 		if (key == -1)
diff --git a/ubi-utils/src/ubinize.c b/ubi-utils/src/ubinize.c
index dd8d3ed..a46833c 100644
--- a/ubi-utils/src/ubinize.c
+++ b/ubi-utils/src/ubinize.c
@@ -161,7 +161,7 @@ static int parse_opt(int argc, char * const argv[])
 	while (1) {
 		int key;
 		char *endp;
-		unsigned long long image_seq;
+		unsigned long int image_seq;
 
 		key = getopt_long(argc, argv, "o:p:m:s:O:e:x:Q:vhV", long_options, NULL);
 		if (key == -1)
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] ubiformat, ubinize: Don't randomize 0xFFFFFFFF sequence number
  2009-09-23 13:01 Two small patches for mtd-utils Michael Roth
  2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: fix more 64-bit image sequence number confusion Michael Roth
@ 2009-09-23 13:01 ` Michael Roth
  2009-09-28  8:59 ` Two small patches for mtd-utils Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Roth @ 2009-09-23 13:01 UTC (permalink / raw)
  To: linux-mtd; +Cc: Michael Roth

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>
---
 ubi-utils/src/ubiformat.c |    8 +++-----
 ubi-utils/src/ubinize.c   |    8 +++-----
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c
index bed0339..54363d7 100644
--- a/ubi-utils/src/ubiformat.c
+++ b/ubi-utils/src/ubiformat.c
@@ -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;
diff --git a/ubi-utils/src/ubinize.c b/ubi-utils/src/ubinize.c
index a46833c..74ddc0f 100644
--- a/ubi-utils/src/ubinize.c
+++ b/ubi-utils/src/ubinize.c
@@ -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;
 }
 
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Two small patches for mtd-utils
  2009-09-23 13:01 Two small patches for mtd-utils Michael Roth
  2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: fix more 64-bit image sequence number confusion Michael Roth
  2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: Don't randomize 0xFFFFFFFF sequence number Michael Roth
@ 2009-09-28  8:59 ` Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2009-09-28  8:59 UTC (permalink / raw)
  To: Michael Roth; +Cc: linux-mtd

On Wed, 2009-09-23 at 15:01 +0200, Michael Roth wrote:
> Hello,
> 
> two small patches for mtd-utils.
> please CC me as I'm not on this list.
> 
> Michael Roth

Pushed the series, thanks!

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-28  9:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-23 13:01 Two small patches for mtd-utils Michael Roth
2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: fix more 64-bit image sequence number confusion Michael Roth
2009-09-23 13:01 ` [PATCH] ubiformat, ubinize: Don't randomize 0xFFFFFFFF sequence number Michael Roth
2009-09-28  8:59 ` Two small patches for mtd-utils Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.