summaryrefslogtreecommitdiffstats
path: root/dediprog.c
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-06-28 17:03:52 +1000
committerAngel Pons <th3fanbus@gmail.com>2021-06-30 08:12:54 +0000
commit6814e2c2820cb065db195c07cf51749f6ae85137 (patch)
tree5cf5abd32d5fdcc235932329d73511aae40a7765 /dediprog.c
parent92b30ba80001e13356ef7e5d87738fb226dddc40 (diff)
downloadflashrom-6814e2c2820cb065db195c07cf51749f6ae85137.tar.gz
flashrom-6814e2c2820cb065db195c07cf51749f6ae85137.tar.bz2
flashrom-6814e2c2820cb065db195c07cf51749f6ae85137.zip
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>
Diffstat (limited to 'dediprog.c')
-rw-r--r--dediprog.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/dediprog.c b/dediprog.c
index 6a2d1f27b..b47e8e94f 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1227,16 +1227,13 @@ static int dediprog_init(void)
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)
* then we need to try the "set voltage" command and then attempt to read the devicestring again. */
if (dediprog_check_devicestring()) {
if (dediprog_set_voltage())
- return 1;
+ goto init_err_cleanup_exit;
if (dediprog_check_devicestring())
- return 1;
+ goto init_err_cleanup_exit;
}
/* 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_voltage(millivolt)) {
dediprog_set_leds(LED_ERROR);
- return 1;
+ goto init_err_cleanup_exit;
}
if (dediprog_standalone_mode())
- return 1;
+ goto init_err_cleanup_exit;
if ((dediprog_devicetype == DEV_SF100) ||
(dediprog_devicetype == DEV_SF600 && protocol() == PROTOCOL_V3))
@@ -1274,10 +1271,17 @@ static int dediprog_init(void)
if (protocol() >= PROTOCOL_V2)
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))
- return 1;
+ return 1; /* shutdown function does cleanup */
return 0;
+
+init_err_cleanup_exit:
+ dediprog_shutdown(NULL);
+ return 1;
}
const struct programmer_entry programmer_dediprog = {