From patchwork Wed Jun 28 21:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9815539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 83FD560365 for ; Wed, 28 Jun 2017 21:19:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6675327FAD for ; Wed, 28 Jun 2017 21:19:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5743E28179; Wed, 28 Jun 2017 21:19:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B114127FAD for ; Wed, 28 Jun 2017 21:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751533AbdF1VTb (ORCPT ); Wed, 28 Jun 2017 17:19:31 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36452 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751515AbdF1VTa (ORCPT ); Wed, 28 Jun 2017 17:19:30 -0400 Received: by mail-qk0-f194.google.com with SMTP id r62so9322932qkf.3 for ; Wed, 28 Jun 2017 14:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SzW7LbpWndBM6itWJjNHXKj9OC9D30DJExcJDmagF14=; b=f3pByo+/ZOWVrhsIPN/7XV/fM6HXARQA86Q1ZNUTWXJ658AtCzi4w0uAUlEyoh1XnS bsul2Goe5RnrxdxNpaUCHnPqwLmz4uHgJV6nNQ+x8ZVRv9rK4sxkZOVOziIrFI6A6prF dKXvbY3FWqw+8YDDiFSEWfIAVaVbOnB9ajOSB9/0KlXyP3/NsklO+YiKtFERU9ogwvP7 d9hC1admstaiabg4DKyUUg+OpG5t7xAAqAItiQ/fcJZuKb4iyIrfSfnCmElDaIw7C2+j vBNlX3GuO/E3AS1OXPAZz4aNixgQzxpUy9KPpdHO6fHwAnCuOYt4OuCzPi1lajEE9Zs1 IJGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SzW7LbpWndBM6itWJjNHXKj9OC9D30DJExcJDmagF14=; b=F86jIyDkPdC/yqIi9ww2mpMgsrG1QhG52heEkF16aKx3NFXNDkc1nQKCX6OedkeoQ2 0HnCQ8YJhXj6cZpO7x9X1cIJ9LgQCQHCCZClkewpGeYTnr05SMtSM+wOYutinBGpnqph ysV2ZxtO2ji32PTtRF6IboKwUE7z0Vhx34+hAMB2AcPXH5QxdQEuOB+z0OpUCkVw9e0e PcqlECg9J/XhLaHwbc0AKCcPWGxfeMP37JheKtAH/Rq+n48vXmYrtJPeWwcJ7XL0frO8 LPuZoWb+yA5hsqssZ7ySEvBlxDoBi6gxaYb3f15uKam7llgaz26akouWpCkr07px+1aL O8Ow== X-Gm-Message-State: AKS2vOxEmm4Fq5Q/uqsQEroa3M4BzkWUw54XzYeZ7RAZhvpbvt05YMXB IQ/z31P9cdHExT1RqGU= X-Received: by 10.55.160.12 with SMTP id j12mr14569063qke.87.1498684769035; Wed, 28 Jun 2017 14:19:29 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id m36sm2549684qte.30.2017.06.28.14.19.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 14:19:28 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires Cc: Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH v3] HID: wacom: Improve generic name generation Date: Wed, 28 Jun 2017 14:19:21 -0700 Message-Id: <20170628211921.5638-1-killertofu@gmail.com> X-Mailer: git-send-email 2.13.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Changes from v2: * Use export/extern to directly gain access to the usb_hid_driver struct for comparison to ll_driver (rather than scanning through the list of USB devices for a matching parent). drivers/hid/usbhid/hid-core.c | 1 + drivers/hid/wacom_sys.c | 60 +++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 83772fa7d92a..4a7a306995a9 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -1269,6 +1269,7 @@ static struct hid_ll_driver usb_hid_driver = { .output_report = usbhid_output_report, .idle = usbhid_idle, }; +EXPORT_SYMBOL_GPL(usb_hid_driver); static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *id) { diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 0022c0dac88a..94d493c724c8 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -22,6 +22,8 @@ #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP) +extern struct hid_ll_driver usb_hid_driver; + static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf, size_t size, unsigned int retries) { @@ -2026,41 +2028,37 @@ static void wacom_update_name(struct wacom *wacom, const char *suffix) /* Generic devices name unspecified */ if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) { - if (strstr(wacom->hdev->name, "Wacom") || - 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)); - } + char *product_name = wacom->hdev->name; - /* strip off excessive prefixing */ - 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); - } - 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); - } + if (wacom->hdev->ll_driver == &usb_hid_driver) { + struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent); + struct usb_device *dev = interface_to_usbdev(intf); + product_name = dev->product; + } - /* get rid of trailing whitespace */ - if (name[strlen(name)-1] == ' ') - name[strlen(name)-1] = '\0'; + if (wacom->hdev->bus == BUS_I2C) { + snprintf(name, sizeof(name), "%s %X", + 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 { - /* no meaningful name retrieved. use product ID */ - snprintf(name, sizeof(name), - "%s %X", features->name, wacom->hdev->product); + snprintf(name, sizeof(name), "Wacom %s", product_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)); + } + + /* get rid of trailing whitespace */ + if (name[strlen(name)-1] == ' ') + name[strlen(name)-1] = '\0'; } else { strlcpy(name, features->name, sizeof(name)); }