Skip to contentSkip to conversation

uvcvideo: Add iFunction or iInterface to device names.

PATCH In review Peter Boström 2 participants 2 messages Apr 19, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 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 | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +21 -3
index 04bf35063c4c..ae22fcf0a529 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 function;
 	int ret;
 
 	if (id->idVendor && id->idProduct)
@@ -2029,9 +2030,26 @@ static int uvc_probe(struct usb_interface *intf,
 		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));
+			 "UVC Camera (%04x:%04x)",
+			 le16_to_cpu(udev->descriptor.idVendor),
+			 le16_to_cpu(udev->descriptor.idProduct));
+
+	/*
+	 * 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.
+	 */
+	function = intf->cur_altsetting->desc.iInterface;
+	if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
+		function = intf->intf_assoc->iFunction;
+	if (function != 0) {
+		size_t len;
+
+		strlcat(dev->name, ": ", sizeof(dev->name));
+		len = strlen(dev->name);
+		usb_string(udev, function, dev->name + len,
+			   sizeof(dev->name) - len);
+	}
 
 	/* Parse the Video Class control descriptor. */
 	if (uvc_parse_control(dev) < 0) {
Signature · 1 line
2.12.2.816.g2cccc81164-goog
maintainer Reviewed-by on v4 1/1
#1 lore raw

Hi Peter,

Thank you for the patch.

Quoted 34 lines · On Wednesday 19 Apr 2017 16:45:27 Peter Boström wrote:

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 | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/media/usb/uvc/uvc_driver.c index 04bf35063c4c..ae22fcf0a529 100644

drivers/media/usb/uvc/uvc_driver.c +3 -3
@@ -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 function;
 	int ret;
 
 	if (id->idVendor && id->idProduct)
@@ -2029,9 +2030,26 @@ static int uvc_probe(struct usb_interface *intf,
 		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));
+			 "UVC Camera (%04x:%04x)",
+			 le16_to_cpu(udev->descriptor.idVendor),

drivers/media/usb/uvc/uvc_driver.c static int uvc_probe(struct usb_interface *intf, · line 2044

Quoted 10 lines
drivers/media/usb/uvc/uvc_driver.c +10 -0
+			 le16_to_cpu(udev->descriptor.idProduct));
+
+	/*
+	 * 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.
+	 */
+	function = intf->cur_altsetting->desc.iInterface;
+	if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
+		function = intf->intf_assoc->iFunction;

Nitpicking, I'd prefer writing this as

	if (intf->intf_assoc && intf->intf_assoc->iFunction != 0)
		function = intf->intf_assoc->iFunction;
	else
		function = intf->cur_altsetting->desc.iInterface;

to clearly show what is the preferred case and what is the fallback. I'll fix that when applying, no need to resubmit the patch.

Quoted 11 lines
drivers/media/usb/uvc/uvc_driver.c +8 -0
+	if (function != 0) {
+		size_t len;
+
+		strlcat(dev->name, ": ", sizeof(dev->name));
+		len = strlen(dev->name);
+		usb_string(udev, function, dev->name + len,
+			   sizeof(dev->name) - len);
+	}
 
 	/* Parse the Video Class control descriptor. */
 	if (uvc_parse_control(dev) < 0) {
Signature · 3 lines
Regards,

Laurent Pinchart