1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-28 23:43:42 +02:00

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>
This commit is contained in:
Angel Pons 2022-09-14 16:45:10 +02:00
parent ca61c3dd3e
commit 813c68ad9c

View File

@ -38,7 +38,6 @@ const char flashrom_version[] = FLASHROM_VERSION;
const char *chip_to_probe = NULL; const char *chip_to_probe = NULL;
static const struct programmer_entry *programmer = NULL; static const struct programmer_entry *programmer = NULL;
static char *programmer_param = NULL;
/* /*
* Programmers supporting multiple buses can have differing size limits on * 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. */ /* Default to allowing writes. Broken programmers set this to 0. */
programmer_may_write = true; programmer_may_write = true;
struct programmer_cfg cfg;
if (param) { if (param) {
programmer_param = strdup(param); cfg.params = strdup(param);
if (!programmer_param) { if (!cfg.params) {
msg_perr("Out of memory!\n"); msg_perr("Out of memory!\n");
return ERROR_FATAL; return ERROR_FATAL;
} }
} else { } else {
programmer_param = NULL; cfg.params = NULL;
} }
msg_pdbg("Initializing %s programmer\n", programmer->name); msg_pdbg("Initializing %s programmer\n", programmer->name);
ret = programmer->init(NULL); ret = programmer->init(&cfg);
if (programmer_param && strlen(programmer_param)) { if (cfg.params && strlen(cfg.params)) {
if (ret != 0) { if (ret != 0) {
/* It is quite possible that any unhandled programmer parameter would have been valid, /* 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. * 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", msg_pwarn("Unhandled programmer parameters (possibly due to another failure): %s\n",
programmer_param); cfg.params);
} else { } else {
/* Actual programmer init was successful, but the user specified an invalid or unusable /* Actual programmer init was successful, but the user specified an invalid or unusable
* (for the current programmer configuration) parameter. * (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"); msg_perr("Aborting.\n");
ret = ERROR_FATAL; ret = ERROR_FATAL;
} }
} }
free(programmer_param); free(cfg.params);
programmer_param = NULL;
return ret; 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) 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) static int check_block_eraser(const struct flashctx *flash, int k, int log)