Angel Pons has submitted this change. ( https://review.coreboot.org/c/flashrom/+/67649 )
Change subject: flashrom.c: Drop `programmer_param` global variable ......................................................................
flashrom.c: Drop `programmer_param` global variable
The `programmer_param` global variable is only valid within the scope of the `programmer_init()` function, which calls a programmer-specific init function that calls `extract_programmer_param_str()` to obtain the value of programmer-specific parameters.
Get rid of this global variable by piping the "programmer_param" string through a function parameter specifically added for this purpose in the past, but was not used yet.
Change-Id: I59397451ea625bd431b15848bad5ec7cb926f22d Signed-off-by: Angel Pons th3fanbus@gmail.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/67649 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Nico Huber nico.h@gmx.de Reviewed-by: Edward O'Callaghan quasisec@chromium.org Reviewed-by: Thomas Heijligen src@posteo.de --- M flashrom.c 1 file changed, 35 insertions(+), 11 deletions(-)
Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, but someone else must approve Thomas Heijligen: Looks good to me, approved Edward O'Callaghan: Looks good to me, approved
diff --git a/flashrom.c b/flashrom.c index f8c5e73..2604594 100644 --- a/flashrom.c +++ b/flashrom.c @@ -38,7 +38,6 @@ const char *chip_to_probe = NULL;
static const struct programmer_entry *programmer = NULL; -static char *programmer_param = NULL;
/* * Programmers supporting multiple buses can have differing size limits on @@ -150,36 +149,37 @@ /* Default to allowing writes. Broken programmers set this to 0. */ programmer_may_write = true;
+ struct programmer_cfg cfg; + if (param) { - programmer_param = strdup(param); - if (!programmer_param) { + cfg.params = strdup(param); + if (!cfg.params) { msg_perr("Out of memory!\n"); return ERROR_FATAL; } } else { - programmer_param = NULL; + cfg.params = NULL; }
msg_pdbg("Initializing %s programmer\n", programmer->name); - ret = programmer->init(NULL); - if (programmer_param && strlen(programmer_param)) { + ret = programmer->init(&cfg); + if (cfg.params && strlen(cfg.params)) { if (ret != 0) { /* It is quite possible that any unhandled programmer parameter would have been valid, * but an error in actual programmer init happened before the parameter was evaluated. */ msg_pwarn("Unhandled programmer parameters (possibly due to another failure): %s\n", - programmer_param); + cfg.params); } else { /* Actual programmer init was successful, but the user specified an invalid or unusable * (for the current programmer configuration) parameter. */ - msg_perr("Unhandled programmer parameters: %s\n", programmer_param); + msg_perr("Unhandled programmer parameters: %s\n", cfg.params); msg_perr("Aborting.\n"); ret = ERROR_FATAL; } } - free(programmer_param); - programmer_param = NULL; + free(cfg.params); return ret; }
@@ -294,7 +294,7 @@
char *extract_programmer_param_str(const struct programmer_cfg *cfg, const char *param_name) { - return extract_param(&programmer_param, param_name, ","); + return extract_param(&cfg->params, param_name, ","); }
static int check_block_eraser(const struct flashctx *flash, int k, int log)