aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2015-06-15 21:01:41 -0400
committerJiri Kosina <jkosina@suse.cz>2015-06-18 04:42:38 -0400
commit44b5250b97a0e5c3a257430ea28b10cf73899bd4 (patch)
tree9f22f0cb562c33a462c7af8326261a3af22f708f
parent05e8fd9202247ac6cdc26f6bafb5453120065490 (diff)
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: Jason Gerecke <jason.gerecke@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/wacom_sys.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index eea18a6cbdc7..bdf31c97fa2a 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1417,6 +1417,7 @@ static void wacom_update_name(struct wacom *wacom)
1417{ 1417{
1418 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 1418 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1419 struct wacom_features *features = &wacom_wac->features; 1419 struct wacom_features *features = &wacom_wac->features;
1420 char name[WACOM_NAME_MAX];
1420 1421
1421 /* Generic devices name unspecified */ 1422 /* Generic devices name unspecified */
1422 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) { 1423 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
@@ -1424,41 +1425,43 @@ static void wacom_update_name(struct wacom *wacom)
1424 strstr(wacom->hdev->name, "wacom") || 1425 strstr(wacom->hdev->name, "wacom") ||
1425 strstr(wacom->hdev->name, "WACOM")) { 1426 strstr(wacom->hdev->name, "WACOM")) {
1426 /* name is in HID descriptor, use it */ 1427 /* name is in HID descriptor, use it */
1427 strlcpy(wacom_wac->name, wacom->hdev->name, 1428 strlcpy(name, wacom->hdev->name, sizeof(name));
1428 sizeof(wacom_wac->name));
1429 1429
1430 /* strip out excess whitespaces */ 1430 /* strip out excess whitespaces */
1431 while (1) { 1431 while (1) {
1432 char *gap = strstr(wacom_wac->name, " "); 1432 char *gap = strstr(name, " ");
1433 if (gap == NULL) 1433 if (gap == NULL)
1434 break; 1434 break;
1435 /* shift everything including the terminator */ 1435 /* shift everything including the terminator */
1436 memmove(gap, gap+1, strlen(gap)); 1436 memmove(gap, gap+1, strlen(gap));
1437 } 1437 }
1438 /* get rid of trailing whitespace */ 1438 /* get rid of trailing whitespace */
1439 if (wacom_wac->name[strlen(wacom_wac->name)-1] == ' ') 1439 if (name[strlen(name)-1] == ' ')
1440 wacom_wac->name[strlen(wacom_wac->name)-1] = '\0'; 1440 name[strlen(name)-1] = '\0';
1441 } else { 1441 } else {
1442 /* no meaningful name retrieved. use product ID */ 1442 /* no meaningful name retrieved. use product ID */
1443 snprintf(wacom_wac->name, sizeof(wacom_wac->name), 1443 snprintf(name, sizeof(name),
1444 "%s %X", features->name, wacom->hdev->product); 1444 "%s %X", features->name, wacom->hdev->product);
1445 } 1445 }
1446 } else { 1446 } else {
1447 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); 1447 strlcpy(name, features->name, sizeof(name));
1448 } 1448 }
1449 1449
1450 /* Append the device type to the name */ 1450 /* Append the device type to the name */
1451 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), 1451 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1452 "%s Pad", wacom_wac->name); 1452 "%s Pad", name);
1453 1453
1454 if (features->device_type == BTN_TOOL_PEN) { 1454 if (features->device_type == BTN_TOOL_PEN) {
1455 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX); 1455 snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1456 "%s Pen", name);
1456 } 1457 }
1457 else if (features->device_type == BTN_TOOL_FINGER) { 1458 else if (features->device_type == BTN_TOOL_FINGER) {
1458 if (features->touch_max) 1459 if (features->touch_max)
1459 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX); 1460 snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1461 "%s Finger", name);
1460 else 1462 else
1461 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX); 1463 snprintf(wacom_wac->name, sizeof(wacom_wac->name),
1464 "%s Pad", name);
1462 } 1465 }
1463} 1466}
1464 1467