From: "Peter Boström" <pbos@google.com>
To: linux-media@vger.kernel.org
Cc: "Peter Boström" <pbos@google.com>
Subject: [PATCH] [media] uvcvideo: Add iFunction or iInterface to device names.
Date: Thu, 6 Apr 2017 13:58:25 -0400 [thread overview]
Message-ID: <20170406175825.90406-1-pbos@google.com> (raw)
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 <pbos@google.com>
---
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;
--
2.12.2.715.g7642488e1d-goog
next reply other threads:[~2017-04-06 17:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-06 17:58 Peter Boström [this message]
2017-04-06 18:28 ` [PATCH] [media] uvcvideo: Add iFunction or iInterface to device names Peter Boström
2017-04-17 21:56 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170406175825.90406-1-pbos@google.com \
--to=pbos@google.com \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.