From patchwork Wed May 17 17:52:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9731757 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 B267560230 for ; Wed, 17 May 2017 17:52:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A59F428389 for ; Wed, 17 May 2017 17:52:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B77283FE; Wed, 17 May 2017 17:52:26 +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 8087128389 for ; Wed, 17 May 2017 17:52:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751761AbdEQRwY (ORCPT ); Wed, 17 May 2017 13:52:24 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:35885 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751395AbdEQRwY (ORCPT ); Wed, 17 May 2017 13:52:24 -0400 Received: by mail-qk0-f194.google.com with SMTP id y128so2671693qka.3 for ; Wed, 17 May 2017 10:52:23 -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=VfjGE/EdfK4zQC6zYByahrCtI7kxdX+7jVs9bnU+PA0=; b=hAIHhBeZihO7ZNj0jXQ2MA43zLeYb9nubNmyQx6aan+6AFOlYxIbYc4kWm/4L/NV4F La9oHhPWPemf4Z/hx89snMQV3H/DZPJyGwrw5OeZoT/nnnXnKT5seoNSyrfI+U7CR92a 8VZpxw6op1FjXqu6jppIrP4mW4b94uCtNoOF+CpEo0cWTvzqOtZjuHnRFSqEqfpHCXMp K/vJL13TBBZHWjiYnye1XRakgjPI9MPpcnKlOXSf4An9v6uKUNeO+buCdn88O7Ati09z QbobGfeJr/U/Js9diGIA5b67gu7tjW3x3G/cZWjAN0cgacOF5CGmQM4EyC3rXgT8imxW 2I2w== 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=VfjGE/EdfK4zQC6zYByahrCtI7kxdX+7jVs9bnU+PA0=; b=uT80VBt9tvjYLZJgEXvirIBSu957m/YuvBvhJUFC5o2zi263S9LUoTEcH1xQyKDEEd +PjVWEdvT/yKd/flls15kMN2YTleQ/J3iBdw3/vHKRRWZouZF7IK48uy7RcfSIR/GcKr pq5ZuSJ6RVUaX7kkun2ABJbmAEcSzZXCyLlNty8t8bu5SyeSmFXmTXjLT5BFSAYylVeX z/RvhW2yq2zes/G7hU7DB6dQpQ1mZD+WvCD5bPR4TKVpibSoHnSrk2ceugzp1d4o158t uyKbBLHpWMqHeEX17qKct+KVTB0hGyahVRVEYbEBZ8jU3+lWIdb2REyL4SERDb6Zu4RY fl4w== X-Gm-Message-State: AODbwcCf1TD/GVdmTvi+I2mfHSrFg+dKN1sSJYLnboO6YmO3PoAu6vkN kpuDnAurB9naxA== X-Received: by 10.55.164.149 with SMTP id n143mr4532669qke.205.1495043541751; Wed, 17 May 2017 10:52:21 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id t136sm1870816qke.40.2017.05.17.10.52.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 10:52:20 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH v2] HID: wacom: Improve generic name generation Date: Wed, 17 May 2017 10:52:08 -0700 Message-Id: <20170517175208.14233-1-killertofu@gmail.com> X-Mailer: git-send-email 2.12.2 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 --- drivers/hid/wacom_sys.c | 90 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 838c1ebfffa9..c68458e44139 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -14,6 +14,7 @@ #include "wacom_wac.h" #include "wacom.h" #include +#include #define WAC_MSG_RETRIES 5 #define WAC_CMD_RETRIES 10 @@ -2020,6 +2021,29 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev) return size; } + +static int __wacom_is_usb_parent(struct usb_device *usbdev, void *ptr) +{ + struct wacom *wacom = ptr; + struct device *parent = wacom->hdev->dev.parent; + struct usb_host_config *config = usbdev->actconfig; + int i; + + for (i = 0; i < config->desc.bNumInterfaces; i++) { + if (&config->interface[i]->dev == parent) + return 1; + } + return 0; +} + +/* + * Distinguish between real USB devices and uhid-created doppelgangers + */ +static bool wacom_is_real_usb(struct wacom *wacom) { + return wacom->hdev->bus == BUS_USB && + usb_for_each_dev(wacom, __wacom_is_usb_parent); +} + static void wacom_update_name(struct wacom *wacom, const char *suffix) { struct wacom_wac *wacom_wac = &wacom->wacom_wac; @@ -2028,41 +2052,47 @@ 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 = NULL; - /* 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 (wacom->hdev->bus == BUS_USB) { + if (wacom_is_real_usb(wacom)) { + struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent); + struct usb_device *dev = interface_to_usbdev(intf); + product_name = dev->product; } - 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); + else { + product_name = wacom->hdev->name; } + } + else if (wacom->hdev->bus == BUS_BLUETOOTH) { + product_name = wacom->hdev->name; + } - /* get rid of trailing whitespace */ - if (name[strlen(name)-1] == ' ') - name[strlen(name)-1] = '\0'; - } else { - /* no meaningful name retrieved. use product ID */ - snprintf(name, sizeof(name), - "%s %X", features->name, wacom->hdev->product); + if (!product_name) { + 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 { + 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)); }