libusb: stop read_thread from looping indefinitely (#457)

- When `libusb_submit_transfer` in `read_thread` fails, `read_callback` never gets called and never sets `transfer_loop_finished` to true, causing `read_thread` to loop indefinitely;

- Do not attempt to run a read loop if the initial `libusb_submit_transfer` fails fixes the issue;

Fixes: #456
This commit is contained in:
Matt Silva
2022-09-28 10:08:27 -04:00
committed by GitHub
parent 4e63d6dfc3
commit 5ce9051e2f
+7 -2
View File
@@ -967,6 +967,7 @@ static void read_callback(struct libusb_transfer *transfer)
static void *read_thread(void *param)
{
int res;
hid_device *dev = param;
uint8_t *buf;
const size_t length = dev->input_ep_max_packet_size;
@@ -985,14 +986,18 @@ static void *read_thread(void *param)
/* Make the first submission. Further submissions are made
from inside read_callback() */
libusb_submit_transfer(dev->transfer);
res = libusb_submit_transfer(dev->transfer);
if(res < 0) {
LOG("libusb_submit_transfer failed: %d %s. Stopping read_thread from running\n", res, libusb_error_name(res));
dev->shutdown_thread = 1;
dev->transfer_loop_finished = 1;
}
/* Notify the main thread that the read thread is up and running. */
pthread_barrier_wait(&dev->barrier);
/* Handle all the events. */
while (!dev->shutdown_thread) {
int res;
res = libusb_handle_events(usb_context);
if (res < 0) {
/* There was an error. */