[PATCH 2/6] Don't print errors when cancel_transfer fails with NOT_FOUND

Hans de Goede hdegoede at redhat.com
Wed Mar 21 11:09:01 EDT 2012


As stated in the documentation for libusb_cancel_transfer,
LIBUSB_ERROR_NOT_FOUND is an expected return value for
libusb_cancel_transfer (under certain circumstances) printing
an error each time this happens therefor is undesirable.

More so because under Linux IOCTL_USBFS_DISCARDURB sets errno
to EINVAL when the kernel could not find the urb in the kernels
urbs in flight list. Which means that the urb has already completed
at the host controller level, but it has not necessarily already
been reaped. IOW under Linux libusb_cancel_transfer may yield a
result of LIBUSB_ERROR_NOT_FOUND *before* the transfer's callback
has been called! So there is no way for an application to avoid
calling libusb_cancel_transfer on already completed transfers.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 libusb/io.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libusb/io.c b/libusb/io.c
index bb04a8f..c9df0cf 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1353,8 +1353,11 @@ int API_EXPORTED libusb_cancel_transfer(struct libusb_transfer *transfer)
 	usbi_mutex_lock(&itransfer->lock);
 	r = usbi_backend->cancel_transfer(itransfer);
 	if (r < 0) {
-		usbi_err(TRANSFER_CTX(transfer),
-			"cancel transfer failed error %d", r);
+		if (r != LIBUSB_ERROR_NOT_FOUND)
+			usbi_err(TRANSFER_CTX(transfer),
+				"cancel transfer failed error %d", r);
+		else
+			usbi_dbg("cancel transfer failed error %d", r);
 
 		if (r == LIBUSB_ERROR_NO_DEVICE)
 			itransfer->flags |= USBI_TRANSFER_DEVICE_DISAPPEARED;
-- 
1.7.9.3




More information about the libusbx mailing list