linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] mkfs.ubifs: check output first
@ 2010-06-17  8:42 Shevchenko Andriy (EXT-Teleca/Helsinki)
  2010-06-17  8:42 ` [PATCH 2/3] flash_eraseall: move constants out of for loop Shevchenko Andriy (EXT-Teleca/Helsinki)
  0 siblings, 1 reply; 8+ messages in thread
From: Shevchenko Andriy (EXT-Teleca/Helsinki) @ 2010-06-17  8:42 UTC (permalink / raw)
  To: Bityutskiy Artem (Nokia-D/Helsinki)
  Cc: Shevchenko Andriy (EXT-Teleca/Helsinki)

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 mkfs.ubifs/mkfs.ubifs.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c
index e4b4e3c..9061453 100644
--- a/mkfs.ubifs/mkfs.ubifs.c
+++ b/mkfs.ubifs/mkfs.ubifs.c
@@ -647,8 +647,11 @@ static int get_options(int argc, char**argv)
 
 	if (optind != argc && !output)
 		output = strdup(argv[optind]);
-	if (output)
-		out_ubi = !open_ubi(output);
+
+	if (!output)
+		return err_msg("not output device or file specified");
+
+	out_ubi = !open_ubi(output);
 
 	if (out_ubi) {
 		c->min_io_size = c->di.min_io_size;
@@ -656,9 +659,6 @@ static int get_options(int argc, char**argv)
 		c->max_leb_cnt = c->vi.rsvd_lebs;
 	}
 
-	if (!output)
-		return err_msg("not output device or file specified");
-
 	if (c->min_io_size == -1)
 		return err_msg("min. I/O unit was not specified "
 			       "(use -h for help)");
-- 
1.6.3.3

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

* [PATCH 2/3] flash_eraseall: move constants out of for loop
  2010-06-17  8:42 [PATCH 1/3] mkfs.ubifs: check output first Shevchenko Andriy (EXT-Teleca/Helsinki)
@ 2010-06-17  8:42 ` Shevchenko Andriy (EXT-Teleca/Helsinki)
  2010-06-17  8:42   ` [PATCH 3/3] flash_eraseall: make -? option the same as --help Shevchenko Andriy (EXT-Teleca/Helsinki)
  2010-06-22 17:33   ` [PATCH 2/3] flash_eraseall: move constants out of for loop Mike Frysinger
  0 siblings, 2 replies; 8+ messages in thread
From: Shevchenko Andriy (EXT-Teleca/Helsinki) @ 2010-06-17  8:42 UTC (permalink / raw)
  To: Bityutskiy Artem (Nokia-D/Helsinki)
  Cc: Shevchenko Andriy (EXT-Teleca/Helsinki)

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 flash_eraseall.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/flash_eraseall.c b/flash_eraseall.c
index a22fc49..f6319d1 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -194,21 +194,21 @@ void process_options (int argc, char *argv[])
 {
 	int error = 0;
 
+	static const char *short_options = "jq";
+	static const struct option long_options[] = {
+		{"help", no_argument, 0, 0},
+		{"version", no_argument, 0, 0},
+		{"jffs2", no_argument, 0, 'j'},
+		{"quiet", no_argument, 0, 'q'},
+		{"silent", no_argument, 0, 'q'},
+
+		{0, 0, 0, 0},
+	};
+
 	exe_name = argv[0];
 
 	for (;;) {
 		int option_index = 0;
-		static const char *short_options = "jq";
-		static const struct option long_options[] = {
-			{"help", no_argument, 0, 0},
-			{"version", no_argument, 0, 0},
-			{"jffs2", no_argument, 0, 'j'},
-			{"quiet", no_argument, 0, 'q'},
-			{"silent", no_argument, 0, 'q'},
-
-			{0, 0, 0, 0},
-		};
-
 		int c = getopt_long(argc, argv, short_options,
 				long_options, &option_index);
 		if (c == EOF) {
-- 
1.6.3.3

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

* [PATCH 3/3] flash_eraseall: make -? option the same as --help
  2010-06-17  8:42 ` [PATCH 2/3] flash_eraseall: move constants out of for loop Shevchenko Andriy (EXT-Teleca/Helsinki)
@ 2010-06-17  8:42   ` Shevchenko Andriy (EXT-Teleca/Helsinki)
  2010-06-22 17:31     ` Mike Frysinger
  2010-06-22 17:33   ` [PATCH 2/3] flash_eraseall: move constants out of for loop Mike Frysinger
  1 sibling, 1 reply; 8+ messages in thread
From: Shevchenko Andriy (EXT-Teleca/Helsinki) @ 2010-06-17  8:42 UTC (permalink / raw)
  To: Bityutskiy Artem (Nokia-D/Helsinki)
  Cc: Shevchenko Andriy (EXT-Teleca/Helsinki)

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 flash_eraseall.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/flash_eraseall.c b/flash_eraseall.c
index f6319d1..ebd329b 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -192,8 +192,6 @@ int main (int argc, char *argv[])
 
 void process_options (int argc, char *argv[])
 {
-	int error = 0;
-
 	static const char *short_options = "jq";
 	static const struct option long_options[] = {
 		{"help", no_argument, 0, 0},
@@ -233,15 +231,13 @@ void process_options (int argc, char *argv[])
 				jffs2 = 1;
 				break;
 			case '?':
-				error = 1;
+				display_help();
 				break;
 		}
 	}
+
 	if (optind == argc) {
 		fprintf(stderr, "%s: no MTD device specified\n", exe_name);
-		error = 1;
-	}
-	if (error) {
 		fprintf(stderr, "Try `%s --help' for more information.\n",
 				exe_name);
 		exit(1);
-- 
1.6.3.3

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

* Re: [PATCH 3/3] flash_eraseall: make -? option the same as --help
  2010-06-17  8:42   ` [PATCH 3/3] flash_eraseall: make -? option the same as --help Shevchenko Andriy (EXT-Teleca/Helsinki)
@ 2010-06-22 17:31     ` Mike Frysinger
  0 siblings, 0 replies; 8+ messages in thread
From: Mike Frysinger @ 2010-06-22 17:31 UTC (permalink / raw)
  To: Shevchenko Andriy (EXT-Teleca/Helsinki)
  Cc: Bityutskiy Artem (Nokia-D/Helsinki), linux-mtd

On Thu, Jun 17, 2010 at 04:42, Shevchenko Andriy wrote:
> --- a/flash_eraseall.c
> +++ b/flash_eraseall.c
> @@ -192,8 +192,6 @@ int main (int argc, char *argv[])
>
>  void process_options (int argc, char *argv[])
>  {
> -       int error = 0;
> -
>        static const char *short_options = "jq";
>        static const struct option long_options[] = {
>                {"help", no_argument, 0, 0},
> @@ -233,15 +231,13 @@ void process_options (int argc, char *argv[])
>                                jffs2 = 1;
>                                break;
>                        case '?':
> -                               error = 1;
> +                               display_help();
>                                break;
>                }
>        }

NAK.  this isnt "-?", that's the error case of getopt.  look at the
invocation of getopt here ... ? is not a valid char.

also, your patch bombing seems screwed up as linux-mtd was bcc-ed.
-mike

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

* Re: [PATCH 2/3] flash_eraseall: move constants out of for loop
  2010-06-17  8:42 ` [PATCH 2/3] flash_eraseall: move constants out of for loop Shevchenko Andriy (EXT-Teleca/Helsinki)
  2010-06-17  8:42   ` [PATCH 3/3] flash_eraseall: make -? option the same as --help Shevchenko Andriy (EXT-Teleca/Helsinki)
@ 2010-06-22 17:33   ` Mike Frysinger
  2010-06-23  0:23     ` Jamie Lokier
  1 sibling, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2010-06-22 17:33 UTC (permalink / raw)
  To: Shevchenko Andriy (EXT-Teleca/Helsinki)
  Cc: Bityutskiy Artem (Nokia-D/Helsinki), linux-mtd

On Thu, Jun 17, 2010 at 04:42, Shevchenko Andriy wrote:
> --- a/flash_eraseall.c
> +++ b/flash_eraseall.c
> @@ -194,21 +194,21 @@ void process_options (int argc, char *argv[])
>  {
>        int error = 0;
>
> +       static const char *short_options = "jq";
> +       static const struct option long_options[] = {
> +               {"help", no_argument, 0, 0},
> +               {"version", no_argument, 0, 0},
> +               {"jffs2", no_argument, 0, 'j'},
> +               {"quiet", no_argument, 0, 'q'},
> +               {"silent", no_argument, 0, 'q'},
> +
> +               {0, 0, 0, 0},
> +       };
> +
>        exe_name = argv[0];
>
>        for (;;) {
>                int option_index = 0;
> -               static const char *short_options = "jq";
> -               static const struct option long_options[] = {
> -                       {"help", no_argument, 0, 0},
> -                       {"version", no_argument, 0, 0},
> -                       {"jffs2", no_argument, 0, 'j'},
> -                       {"quiet", no_argument, 0, 'q'},
> -                       {"silent", no_argument, 0, 'q'},
> -
> -                       {0, 0, 0, 0},
> -               };
> -
>                int c = getopt_long(argc, argv, short_options,
>                                long_options, &option_index);
>                if (c == EOF) {

NAK: no explanation why you're doing this, and current code has the
variables scoped to where they actually get used.

i wonder though why this code even bothers with "static".
-mike

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

* Re: [PATCH 2/3] flash_eraseall: move constants out of for loop
  2010-06-22 17:33   ` [PATCH 2/3] flash_eraseall: move constants out of for loop Mike Frysinger
@ 2010-06-23  0:23     ` Jamie Lokier
  2010-06-23  2:11       ` Mike Frysinger
  0 siblings, 1 reply; 8+ messages in thread
From: Jamie Lokier @ 2010-06-23  0:23 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: Bityutskiy Artem (Nokia-D/Helsinki), linux-mtd,
	Shevchenko Andriy (EXT-Teleca/Helsinki)

Mike Frysinger wrote:
> NAK: no explanation why you're doing this, and current code has the
> variables scoped to where they actually get used.
> 
> i wonder though why this code even bothers with "static".

The array is static to avoid compiling to code which fills in the
array at runtime.  I.e. it makes the code smaller, to the same size as
if they were globals.  And then, only because its static, the const
can put them in the .rodata section, reducing unshared data size.

Because they're static there's no benefit to moving them to another
scope.

-- Jamie

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

* Re: [PATCH 2/3] flash_eraseall: move constants out of for loop
  2010-06-23  0:23     ` Jamie Lokier
@ 2010-06-23  2:11       ` Mike Frysinger
  2010-06-24  0:39         ` Jamie Lokier
  0 siblings, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2010-06-23  2:11 UTC (permalink / raw)
  To: Jamie Lokier
  Cc: Bityutskiy Artem (Nokia-D/Helsinki), linux-mtd,
	Shevchenko Andriy (EXT-Teleca/Helsinki)

On Tue, Jun 22, 2010 at 20:23, Jamie Lokier wrote:
> Mike Frysinger wrote:
>> i wonder though why this code even bothers with "static".
>
> The array is static to avoid compiling to code which fills in the
> array at runtime.  I.e. it makes the code smaller, to the same size as
> if they were globals.  And then, only because its static, the const
> can put them in the .rodata section, reducing unshared data size.

if it were generated on the stack at runtime, the .text is shared too

> Because they're static there's no benefit to moving them to another
> scope.

that's sort of what i expected, but i found it odd that it isnt:
    static const char * const short_options = "jq";
-mike

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

* Re: [PATCH 2/3] flash_eraseall: move constants out of for loop
  2010-06-23  2:11       ` Mike Frysinger
@ 2010-06-24  0:39         ` Jamie Lokier
  0 siblings, 0 replies; 8+ messages in thread
From: Jamie Lokier @ 2010-06-24  0:39 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: Bityutskiy Artem (Nokia-D/Helsinki), linux-mtd,
	Shevchenko Andriy (EXT-Teleca/Helsinki)

Mike Frysinger wrote:
> On Tue, Jun 22, 2010 at 20:23, Jamie Lokier wrote:
> > Mike Frysinger wrote:
> >> i wonder though why this code even bothers with "static".
> >
> > The array is static to avoid compiling to code which fills in the
> > array at runtime.  I.e. it makes the code smaller, to the same size as
> > if they were globals.  And then, only because its static, the const
> > can put them in the .rodata section, reducing unshared data size.
> 
> if it were generated on the stack at runtime, the .text is shared too

Shared, but larger than the static-const data it replaces.

> > Because they're static there's no benefit to moving them to another
> > scope.
> 
> that's sort of what i expected, but i found it odd that it isnt:
>     static const char * const short_options = "jq";

You're right, I missed that.
I'd have used this myself:

static const char short_options[] = "jq";

-- Jamie

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

end of thread, other threads:[~2010-06-24  0:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-17  8:42 [PATCH 1/3] mkfs.ubifs: check output first Shevchenko Andriy (EXT-Teleca/Helsinki)
2010-06-17  8:42 ` [PATCH 2/3] flash_eraseall: move constants out of for loop Shevchenko Andriy (EXT-Teleca/Helsinki)
2010-06-17  8:42   ` [PATCH 3/3] flash_eraseall: make -? option the same as --help Shevchenko Andriy (EXT-Teleca/Helsinki)
2010-06-22 17:31     ` Mike Frysinger
2010-06-22 17:33   ` [PATCH 2/3] flash_eraseall: move constants out of for loop Mike Frysinger
2010-06-23  0:23     ` Jamie Lokier
2010-06-23  2:11       ` Mike Frysinger
2010-06-24  0:39         ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).