1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-28 15:33:42 +02:00

mec1308.c: 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

TEST=builds and ninja test from 51487
BUG=b:185191942

Change-Id: I6d62d43dd8b6ebc595f9fd747e0f4cd80f3c10da
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52597
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Anastasia Klimchuk 2021-04-26 15:19:11 +10:00 committed by Nico Huber
parent 8baf98d2ea
commit cfb5308de3

View File

@ -496,9 +496,6 @@ int mec1308_init(void)
goto init_err_exit; goto init_err_exit;
} }
if (register_shutdown(mec1308_shutdown, ctx_data))
goto init_err_exit;
/* /*
* Enter SPI Pass-Thru Mode after commands which do not require access * Enter SPI Pass-Thru Mode after commands which do not require access
* to SPI ROM are complete. We'll start by doing the exit_passthru_mode * to SPI ROM are complete. We'll start by doing the exit_passthru_mode
@ -507,15 +504,22 @@ int mec1308_init(void)
mec1308_exit_passthru_mode(ctx_data); mec1308_exit_passthru_mode(ctx_data);
if (enter_passthru_mode(ctx_data)) if (enter_passthru_mode(ctx_data))
goto init_err_exit; goto init_err_cleanup_exit;
internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */ internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */
spi_master_mec1308.data = ctx_data; spi_master_mec1308.data = ctx_data;
if (register_shutdown(mec1308_shutdown, ctx_data))
goto init_err_cleanup_exit;
register_spi_master(&spi_master_mec1308); register_spi_master(&spi_master_mec1308);
msg_pdbg("%s(): successfully initialized mec1308\n", __func__); msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
return 0; return 0;
init_err_cleanup_exit:
mec1308_shutdown(ctx_data);
return 1;
init_err_exit: init_err_exit:
free(ctx_data); free(ctx_data);
return 1; return 1;