[flashrom] [PATCH] Check for duplicate -i arguments.
Stefan Tauner
stefan.tauner at student.tuwien.ac.at
Sat Feb 25 22:18:13 CET 2012
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 at student.tuwien.ac.at>
---
layout.c | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
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]);
--
1.7.1
More information about the flashrom
mailing list