提交 09dc28ac 编写于 作者: J Jason Gerecke 提交者: Jiri Kosina

HID: wacom: Improve generic name generation

The 'wacom_update_name' function is responsible for producing names for
the input device nodes based on the hardware device name. Commit f2209d4a
added the ability to strip off prefixes like "Wacom Co.,Ltd." where the
prefix was immediately (and redundantly) followed by "Wacom". The
2nd-generation Intuos Pro 2 has such a prefix, but with a small error
(the period and comma are swapped) that prevents the existing code from
matching it. We're loath to extend the number of cases out endlessly and
so instead try to be smarter about name generation.

We observe that the cause of the redundant prefixes is HID combining the
manufacturer and product strings of USB devices together. By using the
original product name (with "Wacom" prefixed, if it does not already
exist in the string) we can bypass the gyrations to find and remove
redundant prefixes. Other devices either don't have a manufacturer string
that needs to be removed (Bluetooth, uhid) or should have their name
generated from scratch (I2C).
Signed-off-by: NJason Gerecke <jason.gerecke@wacom.com>
Acked-By: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 fc2237a7
...@@ -2025,41 +2025,37 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix) ...@@ -2025,41 +2025,37 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
/* Generic devices name unspecified */ /* Generic devices name unspecified */
if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) { if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
if (strstr(wacom->hdev->name, "Wacom") || char *product_name = wacom->hdev->name;
strstr(wacom->hdev->name, "wacom") ||
strstr(wacom->hdev->name, "WACOM")) {
/* name is in HID descriptor, use it */
strlcpy(name, wacom->hdev->name, sizeof(name));
/* strip out excess whitespaces */
while (1) {
char *gap = strstr(name, " ");
if (gap == NULL)
break;
/* shift everything including the terminator */
memmove(gap, gap+1, strlen(gap));
}
/* strip off excessive prefixing */ if (hid_is_using_ll_driver(wacom->hdev, &usb_hid_driver)) {
if (strstr(name, "Wacom Co.,Ltd. Wacom ") == name) { struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent);
int n = strlen(name); struct usb_device *dev = interface_to_usbdev(intf);
int x = strlen("Wacom Co.,Ltd. "); product_name = dev->product;
memmove(name, name+x, n-x+1); }
}
if (strstr(name, "Wacom Co., Ltd. Wacom ") == name) {
int n = strlen(name);
int x = strlen("Wacom Co., Ltd. ");
memmove(name, name+x, n-x+1);
}
/* get rid of trailing whitespace */ if (wacom->hdev->bus == BUS_I2C) {
if (name[strlen(name)-1] == ' ') snprintf(name, sizeof(name), "%s %X",
name[strlen(name)-1] = '\0'; features->name, wacom->hdev->product);
} else if (strstr(product_name, "Wacom") ||
strstr(product_name, "wacom") ||
strstr(product_name, "WACOM")) {
strlcpy(name, product_name, sizeof(name));
} else { } else {
/* no meaningful name retrieved. use product ID */ snprintf(name, sizeof(name), "Wacom %s", product_name);
snprintf(name, sizeof(name),
"%s %X", features->name, wacom->hdev->product);
} }
/* strip out excess whitespaces */
while (1) {
char *gap = strstr(name, " ");
if (gap == NULL)
break;
/* shift everything including the terminator */
memmove(gap, gap+1, strlen(gap));
}
/* get rid of trailing whitespace */
if (name[strlen(name)-1] == ' ')
name[strlen(name)-1] = '\0';
} else { } else {
strlcpy(name, features->name, sizeof(name)); strlcpy(name, features->name, sizeof(name));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册