Angel Pons has uploaded this change for review.

View Change

rayer_spi.c: Get rid of temporary `prog_type` string

Make the `get_params()` function provide a pointer to `struct
rayer_programmer` directly, instead of having a `prog_type` string
passed around three functions.

Change-Id: I83e34382ee9814f224025e21e5099fdab73cee8c
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
---
M rayer_spi.c
1 file changed, 58 insertions(+), 50 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/39/68239/1
diff --git a/rayer_spi.c b/rayer_spi.c
index 6984099..8ebfb2d 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -225,49 +225,6 @@
.half_period = 0,
};

-static int get_params(const struct programmer_cfg *cfg, uint16_t *lpt_iobase, char **prog_type)
-{
- /* Pick a default value for the I/O base. */
- *lpt_iobase = 0x378;
- /* no programmer type specified. */
- *prog_type = NULL;
-
- /* Non-default port requested? */
- char *arg = extract_programmer_param_str(cfg, "iobase");
- if (arg) {
- char *endptr = NULL;
- unsigned long tmp = strtoul(arg, &endptr, 0);
- /* Port 0, port >0x10000, unaligned ports and garbage strings
- * are rejected.
- */
- if (!tmp || (tmp >= 0x10000) || (tmp & 0x3) ||
- (*endptr != '\0')) {
- /* Using ports below 0x100 is a really bad idea, and
- * should only be done if no port between 0x100 and
- * 0xfffc works due to routing issues.
- */
- msg_perr("Error: iobase= specified, but the I/O base "
- "given was invalid.\nIt must be a multiple of "
- "0x4 and lie between 0x100 and 0xfffc.\n");
- free(arg);
- return -1;
- } else {
- *lpt_iobase = (uint16_t)tmp;
- msg_pinfo("Non-default I/O base requested. This will "
- "not change the hardware settings.\n");
- }
- free(arg);
- }
-
- arg = extract_programmer_param_str(cfg, "type");
- if (arg) {
- *prog_type = strdup(arg);
- free(arg);
- }
-
- return 0;
-}
-
static const struct rayer_programmer *find_progtype(const char *prog_type)
{
if (!prog_type)
@@ -297,21 +254,58 @@
return prog;
}

+static int get_params(const struct programmer_cfg *cfg, uint16_t *lpt_iobase,
+ const struct rayer_programmer **prog)
+{
+ /* Pick a default value for the I/O base. */
+ *lpt_iobase = 0x378;
+ /* no programmer type specified. */
+ *prog = NULL;
+
+ /* Non-default port requested? */
+ char *arg = extract_programmer_param_str(cfg, "iobase");
+ if (arg) {
+ char *endptr = NULL;
+ unsigned long tmp = strtoul(arg, &endptr, 0);
+ /* Port 0, port >0x10000, unaligned ports and garbage strings
+ * are rejected.
+ */
+ if (!tmp || (tmp >= 0x10000) || (tmp & 0x3) ||
+ (*endptr != '\0')) {
+ /* Using ports below 0x100 is a really bad idea, and
+ * should only be done if no port between 0x100 and
+ * 0xfffc works due to routing issues.
+ */
+ msg_perr("Error: iobase= specified, but the I/O base "
+ "given was invalid.\nIt must be a multiple of "
+ "0x4 and lie between 0x100 and 0xfffc.\n");
+ free(arg);
+ return -1;
+ } else {
+ *lpt_iobase = (uint16_t)tmp;
+ msg_pinfo("Non-default I/O base requested. This will "
+ "not change the hardware settings.\n");
+ }
+ free(arg);
+ }
+
+ arg = extract_programmer_param_str(cfg, "type");
+ *prog = find_progtype(arg);
+ free(arg);
+
+ return *prog ? 0 : -1;
+}
+
static int rayer_spi_init(const struct programmer_cfg *cfg)
{
+ const struct rayer_programmer *prog;
struct rayer_pinout *pinout = NULL;
uint16_t lpt_iobase;
- char *prog_type;

if (rget_io_perms())
return 1;

- if (get_params(cfg, &lpt_iobase, &prog_type) < 0)
- return 1;
-
- const struct rayer_programmer *prog = find_progtype(prog_type);
- free(prog_type);
- if (!prog)
+ if (get_params(cfg, &lpt_iobase, &prog) < 0)
return 1;

msg_pdbg("Using address 0x%x as I/O base for parallel port access.\n",

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I83e34382ee9814f224025e21e5099fdab73cee8c
Gerrit-Change-Number: 68239
Gerrit-PatchSet: 1
Gerrit-Owner: Angel Pons <th3fanbus@gmail.com>
Gerrit-MessageType: newchange