Commit 44b5250b authored by Jason Gerecke's avatar Jason Gerecke Committed by Jiri Kosina

HID: wacom: Simplify 'wacom_update_name'

A little bit of cleanup work for 'wacom_update_name' to make it easier on
the eyes. Creates a temporary 'name' variable on which we'll perform our
edits. Once the name is in its final form, it will be copied (with
appropriate suffix) to 'wacom_wac->name' and 'wacom_wac->pad_name'.
Signed-off-by: default avatarJason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 05e8fd92
...@@ -1417,6 +1417,7 @@ static void wacom_update_name(struct wacom *wacom) ...@@ -1417,6 +1417,7 @@ static void wacom_update_name(struct wacom *wacom)
{ {
struct wacom_wac *wacom_wac = &wacom->wacom_wac; struct wacom_wac *wacom_wac = &wacom->wacom_wac;
struct wacom_features *features = &wacom_wac->features; struct wacom_features *features = &wacom_wac->features;
char name[WACOM_NAME_MAX];
/* 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)) {
...@@ -1424,41 +1425,43 @@ static void wacom_update_name(struct wacom *wacom) ...@@ -1424,41 +1425,43 @@ static void wacom_update_name(struct wacom *wacom)
strstr(wacom->hdev->name, "wacom") || strstr(wacom->hdev->name, "wacom") ||
strstr(wacom->hdev->name, "WACOM")) { strstr(wacom->hdev->name, "WACOM")) {
/* name is in HID descriptor, use it */ /* name is in HID descriptor, use it */
strlcpy(wacom_wac->name, wacom->hdev->name, strlcpy(name, wacom->hdev->name, sizeof(name));
sizeof(wacom_wac->name));
/* strip out excess whitespaces */ /* strip out excess whitespaces */
while (1) { while (1) {
char *gap = strstr(wacom_wac->name, " "); char *gap = strstr(name, " ");
if (gap == NULL) if (gap == NULL)
break; break;
/* shift everything including the terminator */ /* shift everything including the terminator */
memmove(gap, gap+1, strlen(gap)); memmove(gap, gap+1, strlen(gap));
} }
/* get rid of trailing whitespace */ /* get rid of trailing whitespace */
if (wacom_wac->name[strlen(wacom_wac->name)-1] == ' ') if (name[strlen(name)-1] == ' ')
wacom_wac->name[strlen(wacom_wac->name)-1] = '\0'; name[strlen(name)-1] = '\0';
} else { } else {
/* no meaningful name retrieved. use product ID */ /* no meaningful name retrieved. use product ID */
snprintf(wacom_wac->name, sizeof(wacom_wac->name), snprintf(name, sizeof(name),
"%s %X", features->name, wacom->hdev->product); "%s %X", features->name, wacom->hdev->product);
} }
} else { } else {
strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); strlcpy(name, features->name, sizeof(name));
} }
/* Append the device type to the name */ /* Append the device type to the name */
snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
"%s Pad", wacom_wac->name); "%s Pad", name);
if (features->device_type == BTN_TOOL_PEN) { if (features->device_type == BTN_TOOL_PEN) {
strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX); snprintf(wacom_wac->name, sizeof(wacom_wac->name),
"%s Pen", name);
} }
else if (features->device_type == BTN_TOOL_FINGER) { else if (features->device_type == BTN_TOOL_FINGER) {
if (features->touch_max) if (features->touch_max)
strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX); snprintf(wacom_wac->name, sizeof(wacom_wac->name),
"%s Finger", name);
else else
strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX); snprintf(wacom_wac->name, sizeof(wacom_wac->name),
"%s Pad", name);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment