[PATCH 1/2] hid2hci: iterate libusb devices twice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi:

After the previous cleanup submitted to hid2hci, a race condition has
been exposed with regard to libusb.  Even though we know the bus and
devnum are existing, the call to usb_find_devices isn't necessarily
finding it on the first time after the device is introduced to the bus
by the BT killswitch.  I'm not too keen upon iterating something twice
as a solution, it does solve the problem until a method is introduced in
usb_device_open_from_udev that doesn't require libusb's iteration of the
bus in the first place.

Regards
-- 
Mario Limonciello
*Dell | Linux Engineering*
mario_limonciello@xxxxxxxx
Even though we know that the device is on the proper bus, libusb
doesn't always find it on the first try.  Once we find the right
bus, if we iterate it twice, we tend to find the device.
=== modified file 'extras/hid2hci/hid2hci.c'
--- extras/hid2hci/hid2hci.c	2009-07-24 16:06:22 +0000
+++ extras/hid2hci/hid2hci.c	2009-07-27 20:45:34 +0000
@@ -161,6 +161,7 @@
 	const char *str;
 	int busnum;
 	int devnum;
+	int trynum;
 
 	str = udev_device_get_sysattr_value(usb_dev, "busnum");
 	if (str == NULL)
@@ -174,7 +175,6 @@
 
 	usb_init();
 	usb_find_busses();
-	usb_find_devices();
 
 	for (bus = usb_get_busses(); bus; bus = bus->next) {
 		struct usb_device *dev;
@@ -182,9 +182,11 @@
 		if (strtol(bus->dirname, NULL, 10) != busnum)
 			continue;
 
-		for (dev = bus->devices; dev; dev = dev->next) {
-			if (dev->devnum == devnum)
-				return dev;
+		for (trynum = 0; trynum < 2; trynum++) {
+			usb_find_devices();
+			for (dev = bus->devices; dev; dev = dev->next)
+				if (dev->devnum == devnum)
+					return dev;
 		}
 	}
 

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux