From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-qt0-f171.google.com ([209.85.216.171]:34832 "EHLO mail-qt0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935028AbdDSUpj (ORCPT ); Wed, 19 Apr 2017 16:45:39 -0400 Received: by mail-qt0-f171.google.com with SMTP id y33so30120262qta.2 for ; Wed, 19 Apr 2017 13:45:38 -0700 (PDT) From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, =?UTF-8?q?Peter=20Bostr=C3=B6m?= Subject: [PATCH v4] [media] uvcvideo: Add iFunction or iInterface to device names. Date: Wed, 19 Apr 2017 16:45:27 -0400 Message-Id: <20170419204527.113504-1-pbos@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-media-owner@vger.kernel.org List-ID: 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. Signed-off-by: Peter Boström --- drivers/media/usb/uvc/uvc_driver.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 04bf35063c4c..ae22fcf0a529 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -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) { -- 2.12.2.816.g2cccc81164-goog