Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/67401 )
Change subject: flashrom.c: Deconflate bad cfg validation from param residue check ......................................................................
flashrom.c: Deconflate bad cfg validation from param residue check
In practice the programmer's init() entry point fails either as a result of a bad configuration early or bad initalisation late. While the param residue check is an othogonal issue and therefore deconflate the two checks.
Change-Id: I0fba6bbbe4b685b210d1cba17e7b5815c5c01a45 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M flashrom.c 1 file changed, 27 insertions(+), 21 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/01/67401/1
diff --git a/flashrom.c b/flashrom.c index 6c38e62..e124e71 100644 --- a/flashrom.c +++ b/flashrom.c @@ -124,26 +124,6 @@ return rc; }
-static int get_param_residue(const char *prog_params, int ret) -{ - if (prog_params && strlen(prog_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", prog_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", prog_params); - msg_perr("Aborting.\n"); - ret = ERROR_FATAL; - } - } - return ret; -} - int programmer_init(const struct programmer_entry *prog, const char *param) { if (prog == NULL) { @@ -169,7 +149,18 @@ msg_pdbg("Initializing %s programmer\n", prog->name); const struct programmer_cfg cfg = { .params = strdup(param) }; int ret = prog->init(&cfg); - ret = get_param_residue(cfg.params, ret); + if (ret != 0) { + msg_pwarn("Invalid programmer configuration or initalisation.\n"); + goto bad_init; + } + if (cfg.params && strlen(cfg.params)) { + msg_perr("Unhandled programmer parameters: %s\n", cfg.params); + msg_perr("Aborting.\n"); + ret = ERROR_FATAL; + goto bad_init; + } + +bad_init: free(cfg.params); return ret; }