Blame SOURCES/ccid-1.4.10-max-cpu-bug.patch

68895e
diff -up ./src/ccid_usb.c.max_cpu_bug ./src/ccid_usb.c
68895e
--- ./src/ccid_usb.c.max_cpu_bug	2012-06-22 00:25:20.000000000 -0700
68895e
+++ ./src/ccid_usb.c	2016-06-29 17:17:11.284337349 -0700
68895e
@@ -154,6 +154,36 @@ status_t OpenUSB(unsigned int reader_ind
68895e
 } /* OpenUSB */
68895e
 
68895e
 
68895e
+ /*****************************************************************************
68895e
+  *
68895e
+  *                                      close_libusb_if_needed
68895e
+  *                                      (pulled from upstream ccid_usb)
68895e
+  *
68895e
+  ****************************************************************************/
68895e
+ static void close_libusb_if_needed(void)
68895e
+ {
68895e
+         int i, to_exit = TRUE;
68895e
+ 
68895e
+         if (NULL == ctx)
68895e
+                 return;
68895e
+ 
68895e
+         /* if at least 1 reader is still in use we do not exit libusb */
68895e
+         for (i=0; i
68895e
+         {
68895e
+                 if (usbDevice[i].dev_handle != NULL)
68895e
+                         to_exit = FALSE;
68895e
+         }
68895e
+ 
68895e
+         if (to_exit)
68895e
+         {
68895e
+                 DEBUG_INFO("libusb_exit");
68895e
+                 libusb_exit(ctx);
68895e
+                 ctx = NULL;
68895e
+         }
68895e
+} /* close_libusb_if_needed */
68895e
+ 
68895e
+
68895e
+
68895e
 /*****************************************************************************
68895e
  *
68895e
  *					OpenUSBByName
68895e
@@ -609,8 +639,8 @@ again:
68895e
 end:
68895e
 	if (usbDevice[reader_index].dev_handle == NULL)
68895e
 	{
68895e
-		/* does not work for libusb <= 1.0.8 */
68895e
-		/* libusb_exit(ctx); */
68895e
+	    close_libusb_if_needed();
68895e
+
68895e
 		if (claim_failed)
68895e
 			return STATUS_COMM_ERROR;
68895e
 		return STATUS_NO_SUCH_DEVICE;
68895e
@@ -628,6 +658,9 @@ end1:
68895e
 	/* free bundle list */
68895e
 	bundleRelease(&plist);
68895e
 
68895e
+	if (return_value != STATUS_SUCCESS)
68895e
+		close_libusb_if_needed();
68895e
+
68895e
 	return return_value;
68895e
 } /* OpenUSBByName */
68895e
 
68895e
@@ -776,13 +809,13 @@ status_t CloseUSB(unsigned int reader_in
68895e
 			usbDevice[reader_index].interface);
68895e
 		(void)libusb_close(usbDevice[reader_index].dev_handle);
68895e
 
68895e
-		/* does not work for libusb <= 1.0.8 */
68895e
-		/* libusb_exit(ctx); */
68895e
 	}
68895e
 
68895e
 	/* mark the resource unused */
68895e
 	usbDevice[reader_index].dev_handle = NULL;
68895e
 	usbDevice[reader_index].interface = 0;
68895e
+	
68895e
+	close_libusb_if_needed();
68895e
 
68895e
 	return STATUS_SUCCESS;
68895e
 } /* CloseUSB */