scd: Fix cancel INTERRUPT transfer.
authorNIIBE Yutaka <gniibe@fsij.org>
Sun, 29 Jan 2017 23:19:32 +0000 (08:19 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Sun, 29 Jan 2017 23:19:32 +0000 (08:19 +0900)
* scd/ccid-driver.c (do_close_reader): Don't lock events, but check the
return value of libusb_cancel_transfer.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
scd/ccid-driver.c

index bbdd697..305c9d2 100644 (file)
@@ -2116,33 +2116,24 @@ do_close_reader (ccid_driver_t handle)
     {
       if (handle->transfer)
         {
-          /* By locking libusb events, make sure handle->transfer is
-             canceled properly;  Don't cancel completed transfer.  */
-#ifdef USE_NPTH
-          npth_unprotect ();
-#endif
-          libusb_lock_events (NULL);
-#ifdef USE_NPTH
-          npth_protect ();
-#endif
           if (!handle->powered_off)
             {
-              libusb_cancel_transfer (handle->transfer);
-              libusb_unlock_events (NULL);
+              DEBUGOUT ("libusb_cancel_transfer\n");
 
-              while (!handle->powered_off)
-                {
+              rc = libusb_cancel_transfer (handle->transfer);
+              if (rc != LIBUSB_ERROR_NOT_FOUND)
+                while (!handle->powered_off)
+                  {
+                    DEBUGOUT ("libusb_handle_events_completed\n");
 #ifdef USE_NPTH
-                  npth_unprotect ();
+                    npth_unprotect ();
 #endif
-                  libusb_handle_events_completed (NULL, &handle->powered_off);
+                    libusb_handle_events_completed (NULL, &handle->powered_off);
 #ifdef USE_NPTH
-                  npth_protect ();
+                    npth_protect ();
 #endif
-                }
+                  }
             }
-          else
-            libusb_unlock_events (NULL);
 
           libusb_free_transfer (handle->transfer);
         }