A properly written app will cancel any outstanding transfers, before
calling libusb_close(), and when an app does not, we complain loudly about
it.

But currently if a device gets unplugged while transfers are outstanding,
and the app detects this disconnect by getting a LIBUSB_ERROR_NO_DEVICE,
the app cannot shutdown in a clean way without libusbx complaining, either
the app does not cancel them, and libusb_close() complains, or the app does
cancel them, and it gets:
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000000] [00000a26] libusbx: error [libusb_cancel_transfer] cancel transfer 
failed error -4
[ 0.000100] [00000a26] libusbx: error [libusb_cancel_transfer] cancel transfer 
failed error -4
<etc>

This patch therefor makes libusb_cancel_transfer not log an error when the
cancel fails with LIBUSB_ERROR_NO_DEVICE, so that apps can properly clean
things up on device disconnect without flooding the console with these errors.

Signed-off-by: Hans de Goede <hdego...@redhat.com>
---
 libusb/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libusb/io.c b/libusb/io.c
index 8a8bc67..1338981 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1417,7 +1417,8 @@ int API_EXPORTED libusb_cancel_transfer(struct 
libusb_transfer *transfer)
        usbi_mutex_lock(&itransfer->lock);
        r = usbi_backend->cancel_transfer(itransfer);
        if (r < 0) {
-               if (r != LIBUSB_ERROR_NOT_FOUND)
+               if (r != LIBUSB_ERROR_NOT_FOUND &&
+                   r != LIBUSB_ERROR_NO_DEVICE)
                        usbi_err(TRANSFER_CTX(transfer),
                                "cancel transfer failed error %d", r);
                else
-- 
1.7.12


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to