Skip to content

Commit 5ce9051

Browse files
libusb: stop read_thread from looping indefinitely (signal11#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: signal11#456
1 parent 4e63d6d commit 5ce9051

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libusb/hid.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ static void read_callback(struct libusb_transfer *transfer)
967967

968968
static void *read_thread(void *param)
969969
{
970+
int res;
970971
hid_device *dev = param;
971972
uint8_t *buf;
972973
const size_t length = dev->input_ep_max_packet_size;
@@ -985,14 +986,18 @@ static void *read_thread(void *param)
985986

986987
/* Make the first submission. Further submissions are made
987988
from inside read_callback() */
988-
libusb_submit_transfer(dev->transfer);
989+
res = libusb_submit_transfer(dev->transfer);
990+
if(res < 0) {
991+
LOG("libusb_submit_transfer failed: %d %s. Stopping read_thread from running\n", res, libusb_error_name(res));
992+
dev->shutdown_thread = 1;
993+
dev->transfer_loop_finished = 1;
994+
}
989995

990996
/* Notify the main thread that the read thread is up and running. */
991997
pthread_barrier_wait(&dev->barrier);
992998

993999
/* Handle all the events. */
9941000
while (!dev->shutdown_thread) {
995-
int res;
9961001
res = libusb_handle_events(usb_context);
9971002
if (res < 0) {
9981003
/* There was an error. */

0 commit comments

Comments
 (0)