From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mario Limonciello Date: Thu, 30 Jul 2009 17:07:21 +0000 Subject: [PATCH] hid2hci: Remove usb_find_busses and usb_find_devices calls Message-Id: <4A71D349.8030206@dell.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="------------enigBBF2F696ADC9CD4BA3D43114" List-Id: To: linux-hotplug@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigBBF2F696ADC9CD4BA3D43114 Content-Type: multipart/mixed; boundary="------------070306000000040205050407" This is a multi-part message in MIME format. --------------070306000000040205050407 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi: As a follow up to the thread titled "[PATCH 1/2] hid2hci: iterate libusb devices twice", I've redone that patch to remove the hacks that were added to work around the bug that has a kernel solution. This patch removes the calls to usb_find_busses and usb_find_devices and instead stuffs the necessary bits into a single usb_device so that the other libusb calls work later on. Thanks, --=20 Mario Limonciello *Dell | Linux Engineering* mario_limonciello@dell.com --------------070306000000040205050407 Content-Type: text/x-patch; name="iterate.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="iterate.diff" =3D=3D=3D modified file 'extras/hid2hci/hid2hci.c' --- extras/hid2hci/hid2hci.c 2009-07-24 16:06:22 +0000 +++ extras/hid2hci/hid2hci.c 2009-07-30 17:00:07 +0000 @@ -150,44 +150,46 @@ return err; } =20 -/* - * The braindead libusb needs to scan and open all devices, just to - * to find the device we already have. This needs to be fixed in libusb - * or it will be ripped out and we carry our own code. - */ static struct usb_device *usb_device_open_from_udev(struct udev_device *= usb_dev) { struct usb_bus *bus; + struct usb_device *dev; const char *str; - int busnum; - int devnum; + char num[4]; + + usb_init(); + + bus =3D malloc(sizeof(*bus)); + dev =3D malloc(sizeof(*dev)); + + if (!bus || !dev) + return NULL; + + memset((void *)bus, 0, sizeof(*bus)); + memset((void *)dev, 0, sizeof(*dev)); =20 str =3D udev_device_get_sysattr_value(usb_dev, "busnum"); if (str =3D=3D NULL) - return NULL; - busnum =3D strtol(str, NULL, 0); + goto err; + snprintf(num, sizeof(num), "%03i",(int)strtol(str,NULL,0)); + strncpy(bus->dirname, num, sizeof(bus->dirname) - 1); + bus->dirname[sizeof(bus->dirname) - 1] =3D 0; + dev->bus =3D bus; =20 str =3D udev_device_get_sysattr_value(usb_dev, "devnum"); if (str =3D=3D NULL) - return NULL; - devnum =3D strtol(str, NULL, 0); - - usb_init(); - usb_find_busses(); - usb_find_devices(); - - for (bus =3D usb_get_busses(); bus; bus =3D bus->next) { - struct usb_device *dev; - - if (strtol(bus->dirname, NULL, 10) !=3D busnum) - continue; - - for (dev =3D bus->devices; dev; dev =3D dev->next) { - if (dev->devnum =3D=3D devnum) - return dev; - } - } - + goto err; + dev->devnum =3D strtol(str, NULL, 0); + + snprintf(num, sizeof(num), "%03i",dev->devnum); + strncpy(dev->filename, num, sizeof(dev->filename) - 1); + dev->filename[sizeof(dev->filename) - 1] =3D 0; + + return dev; + +err: + free(dev); + free(bus); return NULL; } =20 @@ -205,7 +207,10 @@ dev =3D usb_device_open_from_udev(udev_dev); if (dev =3D=3D NULL) return NULL; - return usb_open(dev); + handle =3D usb_open(dev); + free(dev->bus); + free(dev); + return handle; } =20 /* find matching sibling of the current usb_device, they share the same= hub */ @@ -247,8 +252,11 @@ continue; /* only look at the first matching device */ dev =3D usb_device_open_from_udev(udev_parent); - if (dev !=3D NULL) + if (dev !=3D NULL) { handle =3D usb_open(dev); + free(dev->bus); + free(dev); + } udev_device_unref(udev_device); break; } --------------070306000000040205050407-- --------------enigBBF2F696ADC9CD4BA3D43114 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpx00kACgkQ2CrZjkA73Yt41wCfXv5j19wf4ImP7caXcec1VaS4 aKcAniAS4XoGHfJpLnbLML6joUqPDPYX =XCDr -----END PGP SIGNATURE----- --------------enigBBF2F696ADC9CD4BA3D43114--