Anastasia Klimchuk has uploaded this change for review.

View Change

stlinkv3_spi.c: Cleanup properly on all init error paths

Do a cleanup: close handle and exit usb context in cases when init
fails.

If register_spi_master() fails, going to err_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>
---
M stlinkv3_spi.c
1 file changed, 7 insertions(+), 3 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/90/54190/1
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 7e8336e..110e97c 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -464,6 +464,7 @@
char *speed_str = NULL;
char *serialno = NULL;
char *endptr = NULL;
+ int ret = 1;

libusb_init(&usb_ctx);
if (!usb_ctx) {
@@ -498,7 +499,8 @@
msg_perr("Please pass the parameter "
"with a simple non-zero number in kHz\n");
free(speed_str);
- return -1;
+ ret = -1;
+ goto err_exit;
}
free(speed_str);
}
@@ -510,11 +512,13 @@
goto err_exit;

if (register_spi_master(&spi_programmer_stlinkv3))
- goto err_exit;
+ return 1; /* shutdown function does cleanup */

return 0;

err_exit:
+ if (stlinkv3_handle)
+ libusb_close(stlinkv3_handle);
libusb_exit(usb_ctx);
- return 1;
+ return ret;
}

To view, visit change 54190. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I9fabf48068635593bc86006c9642d8569eee8447
Gerrit-Change-Number: 54190
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-MessageType: newchange