From 8237581c5594e631d7a390f935790d96b7b59b2e Mon Sep 17 00:00:00 2001 From: ooonea Date: Tue, 6 Oct 2026 16:11:22 +0200 Subject: usb: clean up RX transfers when resubmission fails A failed resubmission leaves an inactive transfer in rx_xfers. Cancelling it cannot produce a callback, so usb_disconnect waits indefinitely. Route resubmission failures through the existing cleanup path. Assisted-by: OpenAI Codex --- src/usb.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/usb.c') diff --git a/src/usb.c b/src/usb.c index 85d3854..4ea1de7 100644 --- a/src/usb.c +++ b/src/usb.c @@ -226,7 +226,10 @@ static void rx_callback(struct libusb_transfer *xfer) usbmuxd_log(LL_SPEW, "RX callback dev %d-%d len %d status %d", dev->bus, dev->address, xfer->actual_length, xfer->status); if(xfer->status == LIBUSB_TRANSFER_COMPLETED) { device_data_input(dev, xfer->buffer, xfer->actual_length); - libusb_submit_transfer(xfer); + int res = libusb_submit_transfer(xfer); + if (res == 0) + return; + usbmuxd_log(LL_ERROR, "Failed to resubmit RX transfer to device %d-%d: %s", dev->bus, dev->address, libusb_error_name(res)); } else { switch(xfer->status) { case LIBUSB_TRANSFER_COMPLETED: //shut up compiler @@ -255,15 +258,15 @@ static void rx_callback(struct libusb_transfer *xfer) // this should never be reached. break; } + } - free(xfer->buffer); - collection_remove(&dev->rx_xfers, xfer); - libusb_free_transfer(xfer); + free(xfer->buffer); + collection_remove(&dev->rx_xfers, xfer); + libusb_free_transfer(xfer); - // we can't usb_disconnect here due to a deadlock, so instead mark it as dead and reap it after processing events - // we'll do device_remove there too - dev->alive = 0; - } + // we can't usb_disconnect here due to a deadlock, so instead mark it as dead and reap it after processing events + // we'll do device_remove there too + dev->alive = 0; } // Start a read-callback loop for this device -- cgit v1.1-32-gdbae