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

pickit2_spi.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
BUG=b:185191942

Change-Id: I1b672b33169a7a1b6ceab190ad3f48c2f35c3a1f
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52773
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Anastasia Klimchuk 2021-04-30 11:25:44 +10:00 committed by Nico Huber
parent b3b860154d
commit e4261e3425

View File

@ -458,34 +458,33 @@ int pickit2_spi_init(void)
return 1; return 1;
} }
if (register_shutdown(pickit2_shutdown, NULL) != 0) { if (pickit2_get_firmware_version())
return 1; goto init_err_cleanup_exit;
}
if (pickit2_get_firmware_version()) {
return 1;
}
/* Command Set SPI Speed */ /* Command Set SPI Speed */
if (pickit2_set_spi_speed(spispeed_idx)) { if (pickit2_set_spi_speed(spispeed_idx))
return 1; goto init_err_cleanup_exit;
}
/* Command Set SPI Voltage */ /* Command Set SPI Voltage */
msg_pdbg("Setting voltage to %i mV.\n", millivolt); msg_pdbg("Setting voltage to %i mV.\n", millivolt);
if (pickit2_set_spi_voltage(millivolt) != 0) { if (pickit2_set_spi_voltage(millivolt) != 0)
return 1; goto init_err_cleanup_exit;
}
/* Perform basic setup. /* Perform basic setup.
* Configure pin directions and logic levels, turn Vdd on, turn busy LED on and clear buffers. */ * Configure pin directions and logic levels, turn Vdd on, turn busy LED on and clear buffers. */
int transferred; int transferred;
if (libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf, CMD_LENGTH, &transferred, DFLT_TIMEOUT) != 0) { if (libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf, CMD_LENGTH, &transferred, DFLT_TIMEOUT) != 0) {
msg_perr("Command Setup failed!\n"); msg_perr("Command Setup failed!\n");
return 1; goto init_err_cleanup_exit;
} }
if (register_shutdown(pickit2_shutdown, NULL))
goto init_err_cleanup_exit;
register_spi_master(&spi_master_pickit2); register_spi_master(&spi_master_pickit2);
return 0; return 0;
init_err_cleanup_exit:
pickit2_shutdown(NULL);
return 1;
} }