Skip to content

Commit 09dc28a

Browse files
jigpuJiri Kosina
authored and
Jiri Kosina
committed
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 f2209d4 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: Jason Gerecke <[email protected]> Acked-By: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent fc2237a commit 09dc28a

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

Diff for: drivers/hid/wacom_sys.c

+27-31
Original file line numberDiff line numberDiff line change
@@ -2025,41 +2025,37 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix)
20252025

20262026
/* Generic devices name unspecified */
20272027
if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
2028-
if (strstr(wacom->hdev->name, "Wacom") ||
2029-
strstr(wacom->hdev->name, "wacom") ||
2030-
strstr(wacom->hdev->name, "WACOM")) {
2031-
/* name is in HID descriptor, use it */
2032-
strlcpy(name, wacom->hdev->name, sizeof(name));
2033-
2034-
/* strip out excess whitespaces */
2035-
while (1) {
2036-
char *gap = strstr(name, " ");
2037-
if (gap == NULL)
2038-
break;
2039-
/* shift everything including the terminator */
2040-
memmove(gap, gap+1, strlen(gap));
2041-
}
2028+
char *product_name = wacom->hdev->name;
20422029

2043-
/* strip off excessive prefixing */
2044-
if (strstr(name, "Wacom Co.,Ltd. Wacom ") == name) {
2045-
int n = strlen(name);
2046-
int x = strlen("Wacom Co.,Ltd. ");
2047-
memmove(name, name+x, n-x+1);
2048-
}
2049-
if (strstr(name, "Wacom Co., Ltd. Wacom ") == name) {
2050-
int n = strlen(name);
2051-
int x = strlen("Wacom Co., Ltd. ");
2052-
memmove(name, name+x, n-x+1);
2053-
}
2030+
if (hid_is_using_ll_driver(wacom->hdev, &usb_hid_driver)) {
2031+
struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent);
2032+
struct usb_device *dev = interface_to_usbdev(intf);
2033+
product_name = dev->product;
2034+
}
20542035

2055-
/* get rid of trailing whitespace */
2056-
if (name[strlen(name)-1] == ' ')
2057-
name[strlen(name)-1] = '\0';
2036+
if (wacom->hdev->bus == BUS_I2C) {
2037+
snprintf(name, sizeof(name), "%s %X",
2038+
features->name, wacom->hdev->product);
2039+
} else if (strstr(product_name, "Wacom") ||
2040+
strstr(product_name, "wacom") ||
2041+
strstr(product_name, "WACOM")) {
2042+
strlcpy(name, product_name, sizeof(name));
20582043
} else {
2059-
/* no meaningful name retrieved. use product ID */
2060-
snprintf(name, sizeof(name),
2061-
"%s %X", features->name, wacom->hdev->product);
2044+
snprintf(name, sizeof(name), "Wacom %s", product_name);
20622045
}
2046+
2047+
/* strip out excess whitespaces */
2048+
while (1) {
2049+
char *gap = strstr(name, " ");
2050+
if (gap == NULL)
2051+
break;
2052+
/* shift everything including the terminator */
2053+
memmove(gap, gap+1, strlen(gap));
2054+
}
2055+
2056+
/* get rid of trailing whitespace */
2057+
if (name[strlen(name)-1] == ' ')
2058+
name[strlen(name)-1] = '\0';
20632059
} else {
20642060
strlcpy(name, features->name, sizeof(name));
20652061
}

0 commit comments

Comments
 (0)