From patchwork Thu Apr 6 17:58:25 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: 9667981 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 909576021C for ; Thu, 6 Apr 2017 17:58:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA6DB28395 for ; Thu, 6 Apr 2017 17:58:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D669285B8; Thu, 6 Apr 2017 17:58:46 +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 4078E28395 for ; Thu, 6 Apr 2017 17:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754161AbdDFR6o (ORCPT ); Thu, 6 Apr 2017 13:58:44 -0400 Received: from mail-qt0-f176.google.com ([209.85.216.176]:36829 "EHLO mail-qt0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753506AbdDFR6n (ORCPT ); Thu, 6 Apr 2017 13:58:43 -0400 Received: by mail-qt0-f176.google.com with SMTP id r45so42768850qte.3 for ; Thu, 06 Apr 2017 10:58:41 -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=tm8lUTTlLj4QE5Ara8cvwzSAK14jsrE0HAanaQ8SE5k=; b=vgLm7OqjgZGh0d0RefnEZ3D7o/RLOaqr/U3e8if46cXYlREnQpWjQMf8X6RbdX7lpA rCXDDLZukyyc2MCTtit3RoE9dlKlrkC5WWbjTZpOEuFQDgKUeBMMR/ScD3LsftlCvou3 ZgP3hvrTg8BZGf+nW/PSBqe+KDSeKpgVsDThhGolxyn55OzKXNyUUiNRa2/dNPZzti1M S2e7TgnBmMnYEnFFu65ptJX5FxTl6cMlTYR0oJ5tFdu8z/NbVqq01V0Pd5xYrKIvQX/w dQ3uPxefHHk+3I1q+nOUofmFK6c4Nd0WOPI6jTsU8ZXHGt85MqbqFJNxiJwWdtp9U0CP ydNA== 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=tm8lUTTlLj4QE5Ara8cvwzSAK14jsrE0HAanaQ8SE5k=; b=rv9QZ+tOLe5D0gFZ2GwmPmn6ar3LfRvA32JsP8IeeAVP/IXuVnIzp1kd2Ph7YnOReA GaqivzVrC1dR/6o7hNCs1fPryAl+ia28osgsYTl0q/kDP4U+cpdHILyCnwrpIAaY75GJ FAEYy1Rfs63jNDGCkGhXCWXxhWcOAmBS1CW4qnGFOQtZDxoC1ZXOL52mAT6l8wj5OXV4 7BW9uG3CWIA3heekzAcEKoosCbHnS4HiQgJDsGoBVrZAhxngDs0akdVzEJQzTnyp/yh1 HO1DWHVWTIjXdhdytQkO5+jCWUSbRCfLpQGFs8LlYIJAc+/FkHsP1LWjoyICg523Zvb0 DCBA== X-Gm-Message-State: AFeK/H0Hy46Fz62E4A10FViP6boB+Yk0kSbE5uGrYgadGcNnXjtZ8yVopgADaFnXY10oPbZn X-Received: by 10.237.59.198 with SMTP id s6mr39874109qte.161.1491501520762; Thu, 06 Apr 2017 10:58:40 -0700 (PDT) Received: from pbos7.nyc.corp.google.com ([100.101.230.172]) by smtp.gmail.com with ESMTPSA id o92sm1400731qkh.48.2017.04.06.10.58.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Apr 2017 10:58:39 -0700 (PDT) From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= To: linux-media@vger.kernel.org Cc: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Subject: [PATCH] [media] uvcvideo: Add iFunction or iInterface to device names. Date: Thu, 6 Apr 2017 13:58:25 -0400 Message-Id: <20170406175825.90406-1-pbos@google.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-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 | 43 +++++++++++++++++++++++++++++++------- drivers/media/usb/uvc/uvcvideo.h | 4 +++- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 04bf35063c4c..66adf8a77e56 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1998,6 +1998,8 @@ static int uvc_probe(struct usb_interface *intf, { struct usb_device *udev = interface_to_usbdev(intf); struct uvc_device *dev; + char additional_name_buf[UVC_DEVICE_NAME_SIZE]; + const char *additional_name = NULL; int ret; if (id->idVendor && id->idProduct) @@ -2025,13 +2027,40 @@ 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)); + /* + * 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. + */ + if (intf->intf_assoc && intf->intf_assoc->iFunction != 0) { + usb_string(udev, intf->intf_assoc->iFunction, + additional_name_buf, sizeof(additional_name_buf)); + additional_name = additional_name_buf; + } else if (intf->cur_altsetting->desc.iInterface != 0) { + usb_string(udev, intf->cur_altsetting->desc.iInterface, + additional_name_buf, sizeof(additional_name_buf)); + additional_name = additional_name_buf; + } + + if (additional_name) { + if (udev->product) { + snprintf(dev->name, sizeof(dev->name), "%s: %s", + udev->product, additional_name); + } else { + snprintf(dev->name, sizeof(dev->name), + "UVC Camera: %s (%04x:%04x)", + additional_name, + le16_to_cpu(udev->descriptor.idVendor), + le16_to_cpu(udev->descriptor.idProduct)); + } + } else if (udev->product) { + 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)); + } /* 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..0cbedaee6e19 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -541,13 +541,15 @@ struct uvc_streaming { } clock; }; +#define UVC_DEVICE_NAME_SIZE 64 + struct uvc_device { struct usb_device *udev; struct usb_interface *intf; unsigned long warnings; __u32 quirks; int intfnum; - char name[32]; + char name[UVC_DEVICE_NAME_SIZE]; struct mutex lock; /* Protects users */ unsigned int users;