From a7580f1ff24b119f5795d2a307254c40ab721aa9 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 14 Oct 2013 09:40:23 +1100 Subject: [PATCH 1/2] Do not use locking on usb callback function pthread signalling to prevent deadlock with libusb's own event lock. --- usbutils.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/usbutils.c b/usbutils.c index 2ab34d4e..436475bf 100644 --- a/usbutils.c +++ b/usbutils.c @@ -2213,9 +2213,7 @@ static void LIBUSB_CALL transfer_callback(struct libusb_transfer *transfer) { struct usb_transfer *ut = transfer->user_data; - mutex_lock(&ut->mutex); pthread_cond_signal(&ut->cond); - mutex_unlock(&ut->mutex); } /* Wait for callback function to tell us it has finished the USB transfer, but @@ -2237,7 +2235,6 @@ static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int libusb_cancel_transfer(transfer); /* Now wait for the callback function to be invoked. */ - mutex_lock(&ut->mutex); pthread_cond_wait(&ut->cond, &ut->mutex); } ret = transfer->status; From 9ca22ed4933582772090a10c957870820f8aa07c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 14 Oct 2013 10:05:49 +1100 Subject: [PATCH 2/2] Use the one LIBUSB_ERROR_TIMEOUT for cancelled transactions since this error is explicitly tested for in various drivers. --- usbutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usbutils.c b/usbutils.c index 436475bf..f9cb2281 100644 --- a/usbutils.c +++ b/usbutils.c @@ -2239,7 +2239,7 @@ static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int } ret = transfer->status; if (ret == LIBUSB_TRANSFER_CANCELLED) - ret = LIBUSB_TRANSFER_TIMED_OUT; + ret = LIBUSB_ERROR_TIMEOUT; /* No need to sort out mutexes here since they won't be reused */ *transferred = transfer->actual_length; @@ -2585,7 +2585,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz); out_unlock: - if (err && err != LIBUSB_ERROR_TIMEOUT && err != LIBUSB_TRANSFER_TIMED_OUT) { + if (err && err != LIBUSB_ERROR_TIMEOUT) { applog(LOG_WARNING, "%s %i usb read error: %s", cgpu->drv->name, cgpu->device_id, libusb_error_name(err)); if (cgpu->usbinfo.continuous_ioerr_count > USB_RETRY_MAX)