Patchwork Check for duplicate -i arguments.

login
register
about
Submitter Stefan Tauner
Date 2012-02-25 21:18:13
Message ID <1330204693-9688-1-git-send-email-stefan.tauner@student.tuwien.ac.at>
Download mbox | patch
Permalink /patch/3569/
State Accepted
Commit r1523
Headers show

Comments

Stefan Tauner - 2012-02-25 21:18:13
And a tiny cleanup.
---
./flashrom -p dummy:emulate=M25P10.RES  -c M25P10 -i blub -i blub
flashrom v0.9.5-r1505 on Linux 2.6.35-32-generic (x86_64), built with libpci 3.1.7, GCC 4.4.5, little endian
flashrom is free software, get the source code at http://www.flashrom.org

Duplicate region name: "blub".
Please run "flashrom --help" for usage info.

Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
---
 layout.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
Uwe Hermann - 2012-04-14 23:26:35
On Sat, Feb 25, 2012 at 10:18:13PM +0100, Stefan Tauner wrote:
> And a tiny cleanup.
> ---
> ./flashrom -p dummy:emulate=M25P10.RES  -c M25P10 -i blub -i blub
> flashrom v0.9.5-r1505 on Linux 2.6.35-32-generic (x86_64), built with libpci 3.1.7, GCC 4.4.5, little endian
> flashrom is free software, get the source code at http://www.flashrom.org
> 
> Duplicate region name: "blub".
> Please run "flashrom --help" for usage info.
> 
> Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>

Looks good and seems to work fine here.

Acked-by: Uwe Hermann <uwe@hermann-uwe.de>


> +/* returns the index of the entry (or a negative value if it is not found) */

Should start with capital letter and end with full-stop.


Uwe.
Stefan Tauner - 2012-04-15 14:11:19
On Sun, 15 Apr 2012 01:26:35 +0200
Uwe Hermann <uwe@hermann-uwe.de> wrote:

> On Sat, Feb 25, 2012 at 10:18:13PM +0100, Stefan Tauner wrote:
> > And a tiny cleanup.
> > ---
> > ./flashrom -p dummy:emulate=M25P10.RES  -c M25P10 -i blub -i blub
> > flashrom v0.9.5-r1505 on Linux 2.6.35-32-generic (x86_64), built with libpci 3.1.7, GCC 4.4.5, little endian
> > flashrom is free software, get the source code at http://www.flashrom.org
> > 
> > Duplicate region name: "blub".
> > Please run "flashrom --help" for usage info.
> > 
> > Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
> 
> Looks good and seems to work fine here.
> 
> Acked-by: Uwe Hermann <uwe@hermann-uwe.de>

thank you!
committed in r1523.

> > +/* returns the index of the entry (or a negative value if it is not found) */
> 
> Should start with capital letter and end with full-stop.

true, but OTOH *all* of them in that file are in this form...
i have kept them as is for now (including the new one) and plan to
change them together in a later layout.c or formatting patch.

Patch

diff --git a/layout.c b/layout.c
index 90d3cce..293ae8b 100644
--- a/layout.c
+++ b/layout.c
@@ -201,6 +201,17 @@  int read_romlayout(char *name)
 }
 #endif
 
+/* returns the index of the entry (or a negative value if it is not found) */
+int find_include_arg(const char *const name)
+{
+	unsigned int i;
+	for (i = 0; i < num_include_args; i++) {
+		if (!strcmp(include_args[i], name))
+			return i;
+	}
+	return -1;
+}
+
 /* register an include argument (-i) for later processing */
 int register_include_arg(char *name)
 {
@@ -214,6 +225,11 @@  int register_include_arg(char *name)
 		return 1;
 	}
 
+	if (find_include_arg(name) != -1) {
+		msg_gerr("Duplicate region name: \"%s\".\n", name);
+		return 1;
+	}
+
 	include_args[num_include_args] = name;
 	num_include_args++;
 	return 0;
@@ -250,15 +266,15 @@  int process_include_args(void)
 	if (num_include_args == 0)
 		return 0;
 
+	if (!romimages) {
+		msg_gerr("Region requested (with -i \"%s\"), "
+			 "but no layout data is available.\n",
+			 include_args[0]);
+		return 1;
+	}
+
 	for (i = 0; i < num_include_args; i++) {
 		/* User has specified an area, but no layout file is loaded. */
-		if (!romimages) {
-			msg_gerr("Region requested (with -i \"%s\"), "
-				 "but no layout data is available.\n",
-				 include_args[i]);
-			return 1;
-		}
-
 		if (find_romentry(include_args[i]) < 0) {
 			msg_gerr("Invalid region specified: \"%s\"\n",
 				 include_args[i]);