Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/68238 )
Change subject: rayer_spi.c: Roll up programmer type search logic into func ......................................................................
rayer_spi.c: Roll up programmer type search logic into func
Roll up the programmer type table search and match logic into it's own function and lexically scope the 'rayer_spi_types' table into the function while we are here.
Change-Id: Id226ea61132ecc30fd8696e1d8ea50373e752cac Signed-off-by: Edward O'Callaghan quasisec@google.com --- M rayer_spi.c 1 file changed, 47 insertions(+), 24 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/38/68238/1
diff --git a/rayer_spi.c b/rayer_spi.c index 14eb0ea..6984099 100644 --- a/rayer_spi.c +++ b/rayer_spi.c @@ -174,16 +174,6 @@ .miso_bit = 7, };
-static const struct rayer_programmer rayer_spi_types[] = { - {"rayer", NT, "RayeR SPIPGM", &rayer_spipgm}, - {"xilinx", NT, "Xilinx Parallel Cable III (DLC 5)", &xilinx_dlc5}, - {"byteblastermv", OK, "Altera ByteBlasterMV", &altera_byteblastermv}, - {"stk200", NT, "Atmel STK200/300 adapter", &atmel_stk200}, - {"wiggler", OK, "Wiggler LPT", &wiggler_lpt}, - {"spi_tt", NT, "SPI Tiny Tools (SPI_TT LPT)", &spi_tt}, - {0}, -}; - static void rayer_bitbang_set_cs(int val, void *spi_data) { struct rayer_spi_data *data = spi_data; @@ -278,9 +268,37 @@ return 0; }
+static const struct rayer_programmer *find_progtype(const char *prog_type) +{ + if (!prog_type) + return NULL; + + const struct rayer_programmer rayer_spi_types[] = { + {"rayer", NT, "RayeR SPIPGM", &rayer_spipgm}, + {"xilinx", NT, "Xilinx Parallel Cable III (DLC 5)", &xilinx_dlc5}, + {"byteblastermv", OK, "Altera ByteBlasterMV", &altera_byteblastermv}, + {"stk200", NT, "Atmel STK200/300 adapter", &atmel_stk200}, + {"wiggler", OK, "Wiggler LPT", &wiggler_lpt}, + {"spi_tt", NT, "SPI Tiny Tools (SPI_TT LPT)", &spi_tt}, + {0}, + }; + const struct rayer_programmer *prog = rayer_spi_types; + for (; prog->type != NULL; prog++) { + if (strcasecmp(prog_type, prog->type) == 0) { + break; + } + } + + if (!prog->type) { + msg_perr("Error: Invalid device type specified.\n"); + return NULL; + } + + return prog; +} + static int rayer_spi_init(const struct programmer_cfg *cfg) { - const struct rayer_programmer *prog = rayer_spi_types; struct rayer_pinout *pinout = NULL; uint16_t lpt_iobase; char *prog_type; @@ -291,19 +309,10 @@ if (get_params(cfg, &lpt_iobase, &prog_type) < 0) return 1;
- if (prog_type) { - for (; prog->type != NULL; prog++) { - if (strcasecmp(prog_type, prog->type) == 0) { - break; - } - } - free(prog_type); - - if (prog->type == NULL) { - msg_perr("Error: Invalid device type specified.\n"); - return 1; - } - } + const struct rayer_programmer *prog = find_progtype(prog_type); + free(prog_type); + if (!prog) + return 1;
msg_pdbg("Using address 0x%x as I/O base for parallel port access.\n", lpt_iobase);