Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/69516 )
Change subject: flashrom.c: Use goto in err path of prepare_flash_access() ......................................................................
flashrom.c: Use goto in err path of prepare_flash_access()
A goto is useful in the special case of error paths in C for making control flow and cleanups easier to manage.
Change-Id: Ie4f885d7f01fc78e6e431e96435757108bbf0005 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M flashrom.c 1 file changed, 23 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/16/69516/1
diff --git a/flashrom.c b/flashrom.c index 5483af3..b1782d9 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1688,18 +1688,20 @@ const bool read_it, const bool write_it, const bool erase_it, const bool verify_it) { + int ret = 1; + if (chip_safety_check(flash, flash->flags.force, read_it, write_it, erase_it, verify_it)) { msg_cerr("Aborting.\n"); - return 1; + goto err_out; }
if (layout_sanity_checks(flash)) { msg_cerr("Requested regions can not be handled. Aborting.\n"); - return 1; + goto err_out; }
if (map_flash(flash) != 0) - return 1; + goto err_out;
/* Initialize chip_restore_fn_count before chip unlock calls. */ flash->chip_restore_fn_count = 0; @@ -1718,24 +1720,26 @@ if ((flash->chip->feature_bits & FEATURE_4BA_NATIVE) != FEATURE_4BA_NATIVE || !spi_master_4ba(flash)) { msg_cerr("Programmer doesn't support this chip. Aborting.\n"); - return 1; + goto err_out; } }
/* Enable/disable 4-byte addressing mode if flash chip supports it */ if (flash->chip->feature_bits & (FEATURE_4BA_ENTER | FEATURE_4BA_ENTER_WREN | FEATURE_4BA_ENTER_EAR7)) { - int ret; if (spi_master_4ba(flash)) ret = spi_enter_4ba(flash); else ret = spi_exit_4ba(flash); if (ret) { msg_cerr("Failed to set correct 4BA mode! Aborting.\n"); - return 1; + goto err_out; } }
return 0; + +err_out: + return ret; }
void finalize_flash_access(struct flashctx *const flash)