From 8e6ba005d40914cd327cba366b2650af1d7db3a7 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 25 Apr 2021 21:29:22 +0200 Subject: [PATCH] st2-cardem-pcsc: Fix goto-in-while mess There's some code that wasnts to goto within the while loop, and there's some other code that wants to goto after the while loop. Don't jump from outside the while loop into the while loop. Change-Id: Ic2a94ad034dd259f15712687443b569f0d18ff3f --- host/src/simtrace2-cardem-pcsc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/host/src/simtrace2-cardem-pcsc.c b/host/src/simtrace2-cardem-pcsc.c index 543780f7..931d9d76 100644 --- a/host/src/simtrace2-cardem-pcsc.c +++ b/host/src/simtrace2-cardem-pcsc.c @@ -545,20 +545,20 @@ int main(int argc, char **argv) transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm); if (!transp->usb_devh) { fprintf(stderr, "can't open USB device\n"); - goto close_exit; + goto close; } rc = libusb_claim_interface(transp->usb_devh, if_num); if (rc < 0) { fprintf(stderr, "can't claim interface %d; rc=%d\n", if_num, rc); - goto close_exit; + goto close; } rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out, &transp->usb_ep.in, &transp->usb_ep.irq_in); if (rc < 0) { fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc); - goto close_exit; + goto close; } allocate_and_submit_irq(ci); @@ -587,13 +587,20 @@ int main(int argc, char **argv) ret = 0; libusb_release_interface(transp->usb_devh, 0); -close_exit: - if (transp->usb_devh) + +close: + if (transp->usb_devh) { libusb_close(transp->usb_devh); + transp->usb_devh = NULL; + } if (keep_running) sleep(1); } while (keep_running); +close_exit: + if (transp->usb_devh) + libusb_close(transp->usb_devh); + libusb_exit(NULL); do_exit: return ret;