From patchwork Tue Mar 28 21:15:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9650515 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 48183602C8 for ; Tue, 28 Mar 2017 21:16:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35D4B283F3 for ; Tue, 28 Mar 2017 21:16:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27D7A28405; Tue, 28 Mar 2017 21:16:28 +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 8355A283F3 for ; Tue, 28 Mar 2017 21:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755804AbdC1VQN (ORCPT ); Tue, 28 Mar 2017 17:16:13 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34264 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752497AbdC1VQM (ORCPT ); Tue, 28 Mar 2017 17:16:12 -0400 Received: by mail-pg0-f67.google.com with SMTP id o123so21364264pga.1 for ; Tue, 28 Mar 2017 14:16:06 -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=0941OqiWN00axwjzM08mO1clbZxjE09BohMMxDT0KrE=; b=b7RdNDlMsjCF25IRputO1b7UDLC2+bvwLp3u0INnOvNEeMCkjvjnIM/z7KV6DO5zDO LKYQ2SMuVwl1ENOAZZuTZrJ+J8wzgaaiCmUEJh74At1sTHAOw5O6ZG31r6KoQ9laCWci 8TCrYeEn4/3rrN/fnKaAycvlkmgi16jgp++fRJmPz7aca9RuEZYiAHsN5IYVcOx7JcUs W+7/mcD/AKDC+josWaKBnQtbeXdpuCi3sveVHR1v/flJCBLFiTcsp2tgRQpXAFda6Eob 7uXQV+rr4ROOxnc3oaH8gpoCRtGbGOEslEU7Xsz1G5NgJyXsXmns2Rmw9YIuHJjbtpQi 3nkg== 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=0941OqiWN00axwjzM08mO1clbZxjE09BohMMxDT0KrE=; b=S7RAQivRsYra2BHf7rcb3nDwn6kR7sUp7JGVqB0O0fnoVeeFenso7hPrFapRFJGdJ/ TV7pQMfvgtZ/LiiHc3kyPcYPI6cwBKwi+E/nIw/sZmtMixCpfVh+tO+GmxYcrCk+U0xF MG0XkCgQC5tdexP9A4hgwQ+XT0OMyUFzEzMExlC/2YpFZ7rHfaPX/ssNF/Z3gScO5XpC NcWaWZaSFVQPY/a/wm/5JKv1IAf5DHW/+Gz9Lkk0UN8+bAYj9tZAQMO+apK8LiFvmtl9 VqhtBWl1z3N3Nnmy82hDIzRC4a4qZ4uVWw+gX/CiIQNJfWKUoQuCK9NMzefnLPgmifn+ byJQ== X-Gm-Message-State: AFeK/H1YwDRDQvL4qYbd4VqGpkLPLXnjbKLh377KD6p/KDhgyPUv2ApdUbnb2qAYCChqKg== X-Received: by 10.84.230.230 with SMTP id e93mr38737813plk.187.1490735760512; Tue, 28 Mar 2017 14:16:00 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id x15sm9096766pgo.56.2017.03.28.14.15.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 14:15:59 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Benjamin Tissoires , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH] HID: wacom: Improve generic name generation Date: Tue, 28 Mar 2017 14:15:31 -0700 Message-Id: <20170328211531.4641-1-killertofu@gmail.com> X-Mailer: git-send-email 2.12.0 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. For devices connected by other busses, the problem either doesn't exist (e.g. BUS_BLUETOOTH) or the name should be replaced with a generic one entirely (e.g. BUS_I2C, BUS_INTEL_ISHTP). Signed-off-by: Jason Gerecke --- drivers/hid/wacom_sys.c | 65 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 037b9c04745a..ad5d8722fa84 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2026,41 +2026,42 @@ 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 (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) { + struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent); + struct usb_device *dev = interface_to_usbdev(intf); + product_name = dev->product; + } + 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)); }