Edward O'Callaghan has uploaded this change for review.

View Change

programmer_table.c: Move name to entry to own function

Change-Id: I5da3861b47d0d0b527e7cde5dd61bb696de6fedb
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M include/programmer.h
M libflashrom.c
M programmer_table.c
3 files changed, 32 insertions(+), 10 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/20/72820/1
diff --git a/include/programmer.h b/include/programmer.h
index db32b2c..84d8fa9 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -53,6 +53,7 @@

extern const struct programmer_entry *const programmer_table[];
extern const size_t programmer_table_size;
+const struct programmer_entry *programmer_name_to_entry(const char *name);

/* programmer drivers */
extern const struct programmer_entry programmer_atahpt;
diff --git a/libflashrom.c b/libflashrom.c
index 2e89fe5..090dbd4 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -193,18 +193,11 @@
int flashrom_programmer_init(struct flashrom_programmer **const flashprog,
const char *const prog_name, const char *const prog_param)
{
- unsigned prog;
-
- for (prog = 0; prog < programmer_table_size; prog++) {
- if (strcmp(prog_name, programmer_table[prog]->name) == 0)
- break;
- }
- if (prog >= programmer_table_size) {
- msg_ginfo("Error: Unknown programmer \"%s\". Valid choices are:\n", prog_name);
- list_programmers_linebreak(0, 80, 0);
+ const struct programmer_entry *entry = programmer_name_to_entry(prog_name);
+ if (!entry) {
return 1;
}
- return programmer_init(programmer_table[prog], prog_param);
+ return programmer_init(entry, prog_param);
}

int flashrom_programmer_shutdown(struct flashrom_programmer *const flashprog)
diff --git a/programmer_table.c b/programmer_table.c
index d58a155..46f7c61 100644
--- a/programmer_table.c
+++ b/programmer_table.c
@@ -12,6 +12,8 @@
* GNU General Public License for more details.
*/

+#include <string.h>
+
#include "programmer.h"

const struct programmer_entry *const programmer_table[] = {
@@ -174,3 +176,19 @@
};

const size_t programmer_table_size = ARRAY_SIZE(programmer_table);
+
+const struct programmer_entry *programmer_name_to_entry(const char *name)
+{
+ unsigned prog;
+
+ for (prog = 0; prog < programmer_table_size; prog++) {
+ if (strcmp(name, programmer_table[prog]->name) == 0)
+ break;
+ }
+ if (prog >= programmer_table_size) {
+ msg_ginfo("Error: Unknown programmer \"%s\". Valid choices are:\n", name);
+ list_programmers_linebreak(0, 80, 0);
+ return NULL;
+ }
+ return programmer_table[prog];
+}

To view, visit change 72820. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I5da3861b47d0d0b527e7cde5dd61bb696de6fedb
Gerrit-Change-Number: 72820
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange