From patchwork Mon Jul 24 16:46:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9859805 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 97261600F5 for ; Mon, 24 Jul 2017 16:46:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8906128573 for ; Mon, 24 Jul 2017 16:46:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DA8128585; Mon, 24 Jul 2017 16:46:38 +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 18B9628573 for ; Mon, 24 Jul 2017 16:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754897AbdGXQqh (ORCPT ); Mon, 24 Jul 2017 12:46:37 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:35257 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753950AbdGXQqg (ORCPT ); Mon, 24 Jul 2017 12:46:36 -0400 Received: by mail-qk0-f193.google.com with SMTP id k2so2969781qkf.2 for ; Mon, 24 Jul 2017 09:46:36 -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:in-reply-to:references; bh=EnGz3HoVPsZ2U0PVrZCLpQ6hrOq57AbiK7wCnZcx0Fc=; b=JZ8SxUN3A37brxns0Z+sFcnlWA4Lz4oZOq9UhMV7qAaHJYpIIIWSKe1sxuCm+7q9RF ErVYizDrfR2FKfMOCnVFUu4C1ES8IqqJpDUk9+ivGia/gWLfyGKSpm3/XZ+FmQquKnn2 YEioYFXnT288hewbCMSJrW0jBxpmabhICkrLeDuZ3gK4PWymggXnLXp5715vCRk5ucvk t/7vfOUMa1XRDm1lHNIHA1zuPdPwTDPJxDPj+UrXhtiK3lEdnZZrYQimkIRENmUzgh9C HABeo9swlvw/JDatJ5QM8muwsl86+M+J/WonBL7H6LTnz5D1YllKy4OUsOiHTenJQCPc Oaag== 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:in-reply-to :references; bh=EnGz3HoVPsZ2U0PVrZCLpQ6hrOq57AbiK7wCnZcx0Fc=; b=DJO6DJ0L8dYnBehqwz7nZ3qNjd0AVVe/0VnwBH4jQyBj0YjvYB3jW+WlEQCQ/9UtPZ LdQnJpdtwDb1Ge5h6vgkr2mTjj/rwIbhefJVGNan8aIy0a+aRKbz0BJ99tlghRI5ejj+ zXIYD6VBxf4zJMbhC5FjaDBcEEAtiiD23vPtV66k8r559p5Mi94F5XhBTzploLH6Uw/V sx4zkJLMmbylngMnN2w42GUgxa4ISDrj/8LpaQG5aCMP/X9fLvq4amEkjhG6ubmQVby7 YDjaAPM6jcyy8b+JyjrtFXIQ8Rc9DAsyovtsANC1jw/kX5IHnzxIeUiZDm4JAeoJl/ms KdJg== X-Gm-Message-State: AIVw1106Q0drLgEu5pIqpBoOg/+1BvdtOUOtJcF1QAkhw1bkO4gIqOXg klvlUJQtjFQ5RmqAcQQ= X-Received: by 10.55.42.104 with SMTP id q101mr19999861qkh.84.1500914795345; Mon, 24 Jul 2017 09:46:35 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id d125sm8244239qkg.43.2017.07.24.09.46.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 09:46:34 -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 v4 2/2] HID: wacom: Improve generic name generation Date: Mon, 24 Jul 2017 09:46:19 -0700 Message-Id: <20170724164619.29228-2-killertofu@gmail.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170724164619.29228-1-killertofu@gmail.com> References: <20170724164619.29228-1-killertofu@gmail.com> 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 Acked-By: Benjamin Tissoires --- drivers/hid/wacom_sys.c | 58 +++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 0022c0dac88a..236fd54aa938 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2026,41 +2026,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 (hid_is_using_ll_driver(wacom->hdev, &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)); }