[PATCH] hid2hci: Remove usb_find_busses and usb_find_devices calls

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

 



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,
-- 
Mario Limonciello
*Dell | Linux Engineering*
mario_limonciello@xxxxxxxx
=== 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;
 }
 
-/*
- * 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 = malloc(sizeof(*bus));
+	dev = malloc(sizeof(*dev));
+
+	if (!bus || !dev)
+		return NULL;
+
+	memset((void *)bus, 0, sizeof(*bus));
+	memset((void *)dev, 0, sizeof(*dev));
 
 	str = udev_device_get_sysattr_value(usb_dev, "busnum");
 	if (str == NULL)
-		return NULL;
-	busnum = 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] = 0;
+	dev->bus = bus;
 
 	str = udev_device_get_sysattr_value(usb_dev, "devnum");
 	if (str == NULL)
-		return NULL;
-	devnum = strtol(str, NULL, 0);
-
-	usb_init();
-	usb_find_busses();
-	usb_find_devices();
-
-	for (bus = usb_get_busses(); bus; bus = bus->next) {
-		struct usb_device *dev;
-
-		if (strtol(bus->dirname, NULL, 10) != busnum)
-			continue;
-
-		for (dev = bus->devices; dev; dev = dev->next) {
-			if (dev->devnum == devnum)
-				return dev;
-		}
-	}
-
+		goto err;
+	dev->devnum = 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] = 0;
+
+	return dev;
+
+err:
+	free(dev);
+	free(bus);
 	return NULL;
 }
 
@@ -205,7 +207,10 @@
 		dev = usb_device_open_from_udev(udev_dev);
 		if (dev == NULL)
 			return NULL;
-		return usb_open(dev);
+		handle = usb_open(dev);
+		free(dev->bus);
+		free(dev);
+		return handle;
 	}
 
 	/* 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 = usb_device_open_from_udev(udev_parent);
-			if (dev != NULL)
+			if (dev != NULL) {
 				handle = usb_open(dev);
+				free(dev->bus);
+				free(dev);
+			}
 			udev_device_unref(udev_device);
 			break;
 		}

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