linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] hid2hci: iterate libusb devices twice
@ 2009-07-27 21:19 Mario Limonciello
  2009-07-27 21:32 ` Marcel Holtmann
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Mario Limonciello @ 2009-07-27 21:19 UTC (permalink / raw)
  To: linux-hotplug


[-- Attachment #1.1: Type: text/plain, Size: 625 bytes --]

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@dell.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: iterate.diff --]
[-- Type: text/x-patch; name="iterate.diff", Size: 1070 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-07-30 17:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-27 21:19 [PATCH 1/2] hid2hci: iterate libusb devices twice Mario Limonciello
2009-07-27 21:32 ` Marcel Holtmann
2009-07-28  0:12 ` Kay Sievers
2009-07-28 18:12 ` Mario Limonciello
2009-07-29 16:30 ` Mario Limonciello
2009-07-29 18:34 ` Mario_Limonciello
2009-07-29 22:14 ` Kay Sievers
2009-07-30 14:37 ` Alan Stern
2009-07-30 15:27 ` Kay Sievers
2009-07-30 15:37 ` Kay Sievers
2009-07-30 16:00 ` Alan Stern
2009-07-30 17:03 ` Mario Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).