mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 07:23:43 +02:00
stlinkv3_spi.c: Clean up properly on all init error paths
If register_spi_master() fails, going to init exit cleanup is not needed because at that point shutdown function has already been registered and it does the job. BUG=b:185191942 TEST=builds Change-Id: I9fabf48068635593bc86006c9642d8569eee8447 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/54190 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Miklós Márton <martonmiklosqdev@gmail.com>
This commit is contained in:
parent
fbc38c7158
commit
cee470ecef
@ -464,6 +464,7 @@ int stlinkv3_spi_init(void)
|
|||||||
char *speed_str = NULL;
|
char *speed_str = NULL;
|
||||||
char *serialno = NULL;
|
char *serialno = NULL;
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
libusb_init(&usb_ctx);
|
libusb_init(&usb_ctx);
|
||||||
if (!usb_ctx) {
|
if (!usb_ctx) {
|
||||||
@ -485,7 +486,7 @@ int stlinkv3_spi_init(void)
|
|||||||
else
|
else
|
||||||
msg_perr("Could not find any connected STLINK-V3\n");
|
msg_perr("Could not find any connected STLINK-V3\n");
|
||||||
free(serialno);
|
free(serialno);
|
||||||
goto err_exit;
|
goto init_err_exit;
|
||||||
}
|
}
|
||||||
free(serialno);
|
free(serialno);
|
||||||
|
|
||||||
@ -498,23 +499,30 @@ int stlinkv3_spi_init(void)
|
|||||||
msg_perr("Please pass the parameter "
|
msg_perr("Please pass the parameter "
|
||||||
"with a simple non-zero number in kHz\n");
|
"with a simple non-zero number in kHz\n");
|
||||||
free(speed_str);
|
free(speed_str);
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto init_err_exit;
|
||||||
}
|
}
|
||||||
free(speed_str);
|
free(speed_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stlinkv3_spi_open(sck_freq_kHz))
|
if (stlinkv3_spi_open(sck_freq_kHz))
|
||||||
goto err_exit;
|
goto init_err_exit;
|
||||||
|
|
||||||
if (register_shutdown(stlinkv3_spi_shutdown, NULL))
|
if (register_shutdown(stlinkv3_spi_shutdown, NULL))
|
||||||
goto err_exit;
|
goto init_err_cleanup_exit;
|
||||||
|
|
||||||
if (register_spi_master(&spi_programmer_stlinkv3, NULL))
|
if (register_spi_master(&spi_programmer_stlinkv3, NULL))
|
||||||
goto err_exit;
|
return 1; /* shutdown function does cleanup */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_exit:
|
init_err_cleanup_exit:
|
||||||
libusb_exit(usb_ctx);
|
stlinkv3_spi_shutdown(NULL);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
init_err_exit:
|
||||||
|
if (stlinkv3_handle)
|
||||||
|
libusb_close(stlinkv3_handle);
|
||||||
|
libusb_exit(usb_ctx);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user