From owner-freebsd-usb@freebsd.org Sat Sep 1 15:20:30 2018 Return-Path: Delivered-To: freebsd-usb@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B494BFF2429 for ; Sat, 1 Sep 2018 15:20:30 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 52A2E8FEAC for ; Sat, 1 Sep 2018 15:20:30 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 12B07FF2428; Sat, 1 Sep 2018 15:20:30 +0000 (UTC) Delivered-To: usb@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E4E9FFF2427 for ; Sat, 1 Sep 2018 15:20:29 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 745AA8FEAB for ; Sat, 1 Sep 2018 15:20:29 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 883652F4E9 for ; Sat, 1 Sep 2018 15:20:28 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id w81FKS4Q097834 for ; Sat, 1 Sep 2018 15:20:28 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id w81FKSSt097831 for usb@FreeBSD.org; Sat, 1 Sep 2018 15:20:28 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: usb@FreeBSD.org Subject: [Bug 231076] libusb_cancel_transfer() does NOT cancel a transfer after the USB device is removed Date: Sat, 01 Sep 2018 15:20:28 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: usb X-Bugzilla-Version: 10.4-STABLE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: ludovic.rousseau+freebsd@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: usb@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Sep 2018 15:20:30 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D231076 Bug ID: 231076 Summary: libusb_cancel_transfer() does NOT cancel a transfer after the USB device is removed Product: Base System Version: 10.4-STABLE Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: usb Assignee: usb@FreeBSD.org Reporter: ludovic.rousseau+freebsd@gmail.com I am the author of the CCID driver: a driver for smart card readers complia= nt to the USB CCID specification. My driver uses /usr/lib/libusb.so.3 $ ldd /usr/local/lib/pcsc/drivers/ifd-ccid.bundle/Contents/FreeBSD/libccid.= so=20 /usr/local/lib/pcsc/drivers/ifd-ccid.bundle/Contents/FreeBSD/libccid.so: libusb.so.3 =3D> /usr/lib/libusb.so.3 (0x2821c000) libthr.so.3 =3D> /lib/libthr.so.3 (0x2822d000) libc.so.7 =3D> /lib/libc.so.7 (0x2807a000) In my driver I use a transfer on an USB interrupt pipe to wait for card movements events (a card is inserted or removed in the reader) with a timeo= ut of 10 minutes. I use the asynchronous calls of libusb. The source of my function InterruptRead() is available at https://github.com/LudovicRousseau/CCID/blob/master/src/ccid_usb.c#L1294 When a USB reader is removed I have to cleanup and unload the driver so it cancels any transfer on the interrupt pipe. To do that I use libusb_cancel_transfer() in my function InterruptStop(). see https://github.com/LudovicRousseau/CCID/blob/master/src/ccid_usb.c#L1380 My problem is that libusb_cancel_transfer() returns with LIBUSB_ERROR_NOT_F= OUND (because the USB device has been removed and is no more present?) and the current transfer is NOT cancelled. My driver is still blocked in the libusb_handle_events_completed() waiting for the function to return. I looked at the FreeBSD libusb code. The error code LIBUSB_ERROR_NOT_FOUND = is returned just at the beginning of the libusb_cancel_transfer() function at https://github.com/freebsd/freebsd/blob/master/lib/libusb/libusb10.c#L1501 I have no patch to propose. Maybe libusb_cancel_transfer() should try to wake up libusb_handle_events_completed() even if the USB device is no more present. The problem is very easy to reproduce on my side. --=20 You are receiving this mail because: You are the assignee for the bug.=