Angel Pons submitted this change.

View Change


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
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(-)

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)

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I59397451ea625bd431b15848bad5ec7cb926f22d
Gerrit-Change-Number: 67649
Gerrit-PatchSet: 2
Gerrit-Owner: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged