Skip to contentSkip to conversation

uvcvideo: Add iFunction or iInterface to device names.

PATCH Superseded Peter Boström 1 participant 1 message Apr 17, 2017

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 uvcvideo: Add iFunction or iInterface to device names.

Permits distinguishing between two /dev/videoX entries from the same physical UVC device (that naturally share the same iProduct name).

This change matches current Windows behavior by prioritizing iFunction over iInterface, but unlike Windows it displays both iProduct and iFunction/iInterface strings when both are available.

---
 drivers/media/usb/uvc/uvc_driver.c | 37 ++++++++++++++++++++++++++++++-------
 drivers/media/usb/uvc/uvcvideo.h   |  2 +-
 2 files changed, 31 insertions(+), 8 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +30 -7
index 04bf35063c4c..3a00313772a0 100644
@@ -1998,6 +1998,7 @@ static int uvc_probe(struct usb_interface *intf,
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	struct uvc_device *dev;
+	int additional_name;
 	int ret;
 
 	if (id->idVendor && id->idProduct)
@@ -2025,13 +2026,35 @@ static int uvc_probe(struct usb_interface *intf,
 	dev->quirks = (uvc_quirks_param == -1)
 		    ? id->driver_info : uvc_quirks_param;
 
-	if (udev->product != NULL)
-		strlcpy(dev->name, udev->product, sizeof dev->name);
-	else
-		snprintf(dev->name, sizeof dev->name,
-			"UVC Camera (%04x:%04x)",
-			le16_to_cpu(udev->descriptor.idVendor),
-			le16_to_cpu(udev->descriptor.idProduct));
+	strlcpy(dev->name, udev->product ? udev->product : "UVC Camera",
+		sizeof(dev->name));
+
+	/*
+	 * Add iFunction or iInterface to names when available as additional
+	 * distinguishers between interfaces. iFunction is prioritized over
+	 * iInterface which matches Windows behavior at the point of writing.
+	 */
+	additional_name = intf->cur_altsetting->desc.iInterface;
+	if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
+		additional_name = intf->intf_assoc->iFunction;
+	if (additional_name != 0) {
+		size_t len;
+
+		strlcat(dev->name, ": ", sizeof(dev->name));
+		len = strlen(dev->name);
+		usb_string(udev, additional_name, dev->name + len,
+			   sizeof(dev->name) - len);
+	}
+
+	/* Append descriptors to unknown UVC products. */
+	if (!udev->product) {
+		size_t len = strlen(dev->name);
+
+		snprintf(dev->name + len, sizeof(dev->name) - len,
+			 " (%04x:%04x)",
+			 le16_to_cpu(udev->descriptor.idVendor),
+			 le16_to_cpu(udev->descriptor.idProduct));
+	}
 
 	/* Parse the Video Class control descriptor. */
 	if (uvc_parse_control(dev) < 0) {
drivers/media/usb/uvc/uvcvideo.h +1 -1
index 4205e7a423f0..905e40a90fa2 100644
@@ -547,7 +547,7 @@ struct uvc_device {
 	unsigned long warnings;
 	__u32 quirks;
 	int intfnum;
-	char name[32];
+	char name[64];
 
 	struct mutex lock;		/* Protects users */
 	unsigned int users;
Signature · 1 line
2.12.2.762.g0e3151a226-goog