1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

dediprog: Separate shutdown from failed init cleanup

Shutdown function was covering two different jobs here: 1) the actual
shutdown which is run at the end of the driver's lifecycle and
2) cleanup in cases when initialisation failed. Now, shutdown is only
doing its main job (#1), and the driver itself is doing cleanup
when init fails (#2).

The good thing is that now resources are released/closed immediately
in cases when init fails (vs shutdown function which was run at some
point later), and the driver leaves clean space after itself if init
fails.

And very importantly this unlocks API change which plans to move
register_shutdown inside register master API, see
https://review.coreboot.org/c/flashrom/+/51761

BUG=b:185191942
TEST=builds

Change-Id: I3273da907614a042d50090338c337dfd64695354
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55887
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Anastasia Klimchuk 2021-06-28 17:03:52 +10:00 committed by Angel Pons
parent 92b30ba800
commit 6814e2c282

View File

@ -1227,16 +1227,13 @@ static int dediprog_init(void)
msg_pinfo("Using dediprog id SF%06d.\n", found_id); msg_pinfo("Using dediprog id SF%06d.\n", found_id);
} }
if (register_shutdown(dediprog_shutdown, NULL))
return 1;
/* Try reading the devicestring. If that fails and the device is old (FW < 6.0.0, which we can not know) /* Try reading the devicestring. If that fails and the device is old (FW < 6.0.0, which we can not know)
* then we need to try the "set voltage" command and then attempt to read the devicestring again. */ * then we need to try the "set voltage" command and then attempt to read the devicestring again. */
if (dediprog_check_devicestring()) { if (dediprog_check_devicestring()) {
if (dediprog_set_voltage()) if (dediprog_set_voltage())
return 1; goto init_err_cleanup_exit;
if (dediprog_check_devicestring()) if (dediprog_check_devicestring())
return 1; goto init_err_cleanup_exit;
} }
/* SF100/SF200 uses one in/out endpoint, SF600 uses separate in/out endpoints */ /* SF100/SF200 uses one in/out endpoint, SF600 uses separate in/out endpoints */
@ -1261,11 +1258,11 @@ static int dediprog_init(void)
dediprog_set_spi_speed(spispeed_idx) || dediprog_set_spi_speed(spispeed_idx) ||
dediprog_set_spi_voltage(millivolt)) { dediprog_set_spi_voltage(millivolt)) {
dediprog_set_leds(LED_ERROR); dediprog_set_leds(LED_ERROR);
return 1; goto init_err_cleanup_exit;
} }
if (dediprog_standalone_mode()) if (dediprog_standalone_mode())
return 1; goto init_err_cleanup_exit;
if ((dediprog_devicetype == DEV_SF100) || if ((dediprog_devicetype == DEV_SF100) ||
(dediprog_devicetype == DEV_SF600 && protocol() == PROTOCOL_V3)) (dediprog_devicetype == DEV_SF600 && protocol() == PROTOCOL_V3))
@ -1274,10 +1271,17 @@ static int dediprog_init(void)
if (protocol() >= PROTOCOL_V2) if (protocol() >= PROTOCOL_V2)
spi_master_dediprog.features |= SPI_MASTER_4BA; spi_master_dediprog.features |= SPI_MASTER_4BA;
if (register_shutdown(dediprog_shutdown, NULL))
goto init_err_cleanup_exit;
if (register_spi_master(&spi_master_dediprog, NULL) || dediprog_set_leds(LED_NONE)) if (register_spi_master(&spi_master_dediprog, NULL) || dediprog_set_leds(LED_NONE))
return 1; return 1; /* shutdown function does cleanup */
return 0; return 0;
init_err_cleanup_exit:
dediprog_shutdown(NULL);
return 1;
} }
const struct programmer_entry programmer_dediprog = { const struct programmer_entry programmer_dediprog = {