From: Mario Limonciello <mario_limonciello@dell.com>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH 1/2] hid2hci: iterate libusb devices twice
Date: Mon, 27 Jul 2009 21:19:57 +0000 [thread overview]
Message-ID: <4A6E19FD.7040908@dell.com> (raw)
[-- 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 --]
next reply other threads:[~2009-07-27 21:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-27 21:19 Mario Limonciello [this message]
2009-07-27 21:32 ` [PATCH 1/2] hid2hci: iterate libusb devices twice 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A6E19FD.7040908@dell.com \
--to=mario_limonciello@dell.com \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).