From patchwork Mon Apr 17 23:05:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_Bostr=C3=B6m?= X-Patchwork-Id: 9684637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7B6B4600F6 for ; Mon, 17 Apr 2017 23:06:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5904B252D5 for ; Mon, 17 Apr 2017 23:06:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AF0526490; Mon, 17 Apr 2017 23:06:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49344252D5 for ; Mon, 17 Apr 2017 23:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756877AbdDQXF5 (ORCPT ); Mon, 17 Apr 2017 19:05:57 -0400 Received: from mail-qt0-f180.google.com ([209.85.216.180]:34681 "EHLO mail-qt0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753810AbdDQXF4 (ORCPT ); Mon, 17 Apr 2017 19:05:56 -0400 Received: by mail-qt0-f180.google.com with SMTP id c45so112495558qtb.1 for ; Mon, 17 Apr 2017 16:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZrMjP++fRddP4s51Lvbui7s3duyQ3OmyeqJEjHH1608=; b=Lc+U5GAAXEZXEGaBrsFAwpojW7J1WScTnY/7AS8NrYRFspt4IA8h144K7uhLienrHk 7CTgZHN42UAdNZYyAwiPnN2a50VY5eKRU7KBRjPvQyNoB3LfANAXUvKuxvfMBzs8EqAy K3tWWn6jF2sthawo0QkaloDoieTQjHTen2K6MBa48e9sn/PUVHNr2rx0GodSntyHfDVw yTVPRH1/ecGxXS6vSqk2eqLOBxOhL0GMNULXMMpfaK+KVuhI8Xw5p9p24SygjWPhGuvZ yq90Cxcg52V9/5ipe04caQiLZX74Wp/q7B1JL9jvx62qRJZVpOJSqUPZy3mVAJ5qW63D 8kBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZrMjP++fRddP4s51Lvbui7s3duyQ3OmyeqJEjHH1608=; b=LEIVwal7k/O4pVS5ChAbMSswtbeKvw1WjLA8hGemJT91Jxwg32DmEsnM7s1TfiJVnF Xv9LvMSz/RNVc1Epr4gfrsxM/ryAFmwpYoVl9i4YneU7BHbGQ5ChgQl7COj0AgxAR8lH faDbD6xPh1FDIJ7oot//B+/qZ3H53K3/YtxmcSWEF4s7AZQ+8hxjTyvSAZx02GPisXA2 hnG9TeT1OmCS98cEzzWErCCvRgonDgl/iv4slbnVuUpaiWP+IeVeeMrfQBZWtcbfOre3 2A8pZ7deHMCoO41tKEZZbn0Vxabfn+13kCzPLeg2Zad6nAkjVmC7W3uAi9TYRkrxWlK5 5mwQ== X-Gm-Message-State: AN3rC/4LKfpBoA8GtjJ7mHBJf0Rpfh+MhssQ7pdw35vRLmWc4zKwxkgl WY3FaT9ma+JjR948hTI2uw== X-Received: by 10.200.45.167 with SMTP id p36mr12292146qta.265.1492470355300; Mon, 17 Apr 2017 16:05:55 -0700 (PDT) Received: from pbos7.nyc.corp.google.com ([100.101.230.172]) by smtp.gmail.com with ESMTPSA id f203sm8306105qka.11.2017.04.17.16.05.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Apr 2017 16:05:54 -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 v2] [media] uvcvideo: Add iFunction or iInterface to device names. Date: Mon, 17 Apr 2017 19:05:42 -0400 Message-Id: <20170417230542.3724-1-pbos@google.com> X-Mailer: git-send-email 2.12.2.762.g0e3151a226-goog MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 37 ++++++++++++++++++++++++++++++------- drivers/media/usb/uvc/uvcvideo.h | 2 +- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 04bf35063c4c..3a00313772a0 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 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) { diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 4205e7a423f0..905e40a90fa2 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -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;