diff options
author | YH Lin <yueherngl@google.com> | 2022-02-23 12:00:48 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-02-24 21:29:55 +0000 |
commit | ca1aa19bc80a0455ba49608ca0a19a9c516c9673 (patch) | |
tree | c4198f23cbcbf2dafc25483048580381a1868af2 /host | |
parent | f1eb49bf1980afe9c195d99911198126ffcf7329 (diff) | |
download | vboot-ca1aa19bc80a0455ba49608ca0a19a9c516c9673.tar.gz |
futility: check flashrom return code and bail with error
During the flashrom initialization sequence the return code is not
being checked therefore there's a potential that the code moves
forward with read/write operation even with outstanding error.
This CL checks the return code and bail with error.
BUG=b:217629892
TEST=Test futility update with multiple instances of flashrom running.
BRANCH=None
Signed-off-by: YH Lin <yueherngl@chromium.org>
Change-Id: I0768232f6af35290ad7b3d9f479ee299bf9400e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3485520
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/flashrom_drv.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/host/lib/flashrom_drv.c b/host/lib/flashrom_drv.c index 883b6d35..dfc9c83d 100644 --- a/host/lib/flashrom_drv.c +++ b/host/lib/flashrom_drv.c @@ -63,9 +63,15 @@ int flashrom_read_image(struct firmware_image *image, const char *region, flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb); - r |= flashrom_init(1); - r |= flashrom_programmer_init(&prog, programmer, params); - r |= flashrom_flash_probe(&flashctx, prog, NULL); + if (flashrom_init(1) + || flashrom_programmer_init(&prog, programmer, params)) { + r = -1; + goto err_init; + } + if (flashrom_flash_probe(&flashctx, prog, NULL)) { + r = -1; + goto err_probe; + } len = flashrom_flash_getsize(flashctx); @@ -101,11 +107,14 @@ int flashrom_read_image(struct firmware_image *image, const char *region, r |= flashrom_image_read(flashctx, image->data, len); err_cleanup: - r |= flashrom_programmer_shutdown(prog); flashrom_layout_release(layout); flashrom_flash_release(flashctx); - free(tmp); +err_probe: + r |= flashrom_programmer_shutdown(prog); + +err_init: + free(tmp); return r; } @@ -128,9 +137,15 @@ int flashrom_write_image(const struct firmware_image *image, flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb); - r |= flashrom_init(1); - r |= flashrom_programmer_init(&prog, programmer, params); - r |= flashrom_flash_probe(&flashctx, prog, NULL); + if (flashrom_init(1) + || flashrom_programmer_init(&prog, programmer, params)) { + r = -1; + goto err_init; + } + if (flashrom_flash_probe(&flashctx, prog, NULL)) { + r = -1; + goto err_probe; + } len = flashrom_flash_getsize(flashctx); if (len == 0) { @@ -181,10 +196,13 @@ int flashrom_write_image(const struct firmware_image *image, diff_image ? diff_image->data : NULL); err_cleanup: - r |= flashrom_programmer_shutdown(prog); flashrom_layout_release(layout); flashrom_flash_release(flashctx); - free(tmp); +err_probe: + r |= flashrom_programmer_shutdown(prog); + +err_init: + free(tmp); return r; } |