From 813c68ad9cf2bc61b9923b3eab429ed318359281 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Wed, 14 Sep 2022 16:45:10 +0200 Subject: 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 Reviewed-on: https://review.coreboot.org/c/flashrom/+/67649 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Edward O'Callaghan Reviewed-by: Thomas Heijligen --- flashrom.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/flashrom.c b/flashrom.c index f8c5e730..26045943 100644 --- a/flashrom.c +++ b/flashrom.c @@ -38,7 +38,6 @@ const char flashrom_version[] = FLASHROM_VERSION; 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 @@ int programmer_init(const struct programmer_entry *prog, const char *param) /* 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 @@ static char *extract_param(char *const *haystack, const char *needle, const char 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) -- cgit v1.2.3