From patchwork Sun Jul 15 01:06:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John S Gruber X-Patchwork-Id: 10524929 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 A63736028E for ; Sun, 15 Jul 2018 01:06:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EE2B289EE for ; Sun, 15 Jul 2018 01:06:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7391D28A0D; Sun, 15 Jul 2018 01:06:34 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 162B4289EE for ; Sun, 15 Jul 2018 01:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731950AbeGOB13 (ORCPT ); Sat, 14 Jul 2018 21:27:29 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:41073 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731885AbeGOB13 (ORCPT ); Sat, 14 Jul 2018 21:27:29 -0400 Received: by mail-oi0-f68.google.com with SMTP id k12-v6so68718313oiw.8 for ; Sat, 14 Jul 2018 18:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:in-reply-to:references:date:message-id:subject:to; bh=Cyff5ZDAljJB2q/b6oSjpFNPcmyk7DiuV5K1MtrWWIc=; b=RQkeqLYz09/Vwre7I69P97l3+lHcizGhHM0MbeVQbHkS1To6RC+jyaRxK0uMl2V9pX EyRtJwc0XFQY6b9KOioZUKUpsXP3DbEsDOOHG+oE567I8vvBwCD/WYFH/1VIivr7DETC wfHPvvqiRcbaBgPMXAd5FyeIbqGpkib/77/PbqGeS8Q3H54zghMPsrmjd5yA8nAt5DED UjPgKSqUiBBToO98YQlfxRon9OCD7DUav7Dt0VkhSD0QGqRO0UgiMz+WP9pkqng30hDC /o+LG/0OdXnVZCE6tQ6HejzrI6FNv9QayHSV9lhlqw87zyMupXH1zwY+Ii8HLmndBc3o DDDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:in-reply-to:references:date :message-id:subject:to; bh=Cyff5ZDAljJB2q/b6oSjpFNPcmyk7DiuV5K1MtrWWIc=; b=FB0KXGJVPyh0tzHePuv3v2WIyTv99D5Kf3qpXsf8hmxlMU7b9EKk4ArqWuJPaY5Uz1 s06IUX8Qid/kOjhFgk1O+Ylxk1TzYAXDrEJDLPfqkGo9IAowY7meZv55hYpgGiDZoN3U n8Q8XKIx94KNYlVNv/qVk3C8WQVb3FvHhp8rMI5LgexipiUJGbj8RFAa4Ksb7K+uDU7c o6dozptT4HEOb/D+cvstOzc968eTOA/QiGGh9fgE8IYp3Eui7/v81phi0da+OswniNvJ nV2hsTWURcduRZNHSgzwz7KlGKCIjoHkmdYZZtyUzrKzAceysiQRenzvVWfMfm7uhdEG zmRA== X-Gm-Message-State: AOUpUlHNMIpmQUGDuyURmkiVeTJolYeqi8OKj/UmZOoi6Uk8S40/LI0G XDr+y2vKNmyEkrAjNd9etC8IF72/yC7LE/oM2d8= X-Google-Smtp-Source: AAOMgpcofSgiCZAEkkPfV8Qu6vMYZWcX71DRonBaC/pbhac7FouNIvOhrZolqKA96U2hPWNEEMUltQPgtxfdcAjBWc4= MIME-Version: 1.0 X-Received: by 2002:aca:3546:: with SMTP id c67-v6mr13419520oia.249.1531616792030; Sat, 14 Jul 2018 18:06:32 -0700 (PDT) Received: from 329980741037 named unknown by gmailapi.google.com with HTTPREST; Sat, 14 Jul 2018 18:06:31 -0700 From: John S Gruber X-Mailer: git-send-email 1.9.1 In-Reply-To: <1531616776-7401-1-git-send-email-JohnSGruber@gmail.com> References: <1531616776-7401-1-git-send-email-JohnSGruber@gmail.com> Date: Sat, 14 Jul 2018 18:06:31 -0700 Message-ID: Subject: [PATCH 2/2] HID: redragon Add additional verification to rdesc modification quirk To: Jiri Kosina , Robert Munteanu , linux-input@vger.kernel.org, benjamin.tissoires@redhat.com, JohnSGruber@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 There are many devices using the vendor_id 0c45 and device_id of 760b combination. Also the two bytes 0x81 0x00 aren't rare for a report description. For these reasons the report description being altered by the quirk should be verified more completely If I'm understanding this correctly, I believe for an array field the report_size should be greater or equal to ceil(log2(usage_maximum - usage_minimum + 1)). That's 3 bits for these 8 shift keys, 0xe0-0xe7. Therefore the incorrect report description can't be valid for any device. Check the actual count of the rdesc and compare the entire field description to reduce the chance of patching the wrong thing by inadvertence. Signed-off-by: John S Gruber --- drivers/hid/hid-redragon.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c index 85a5fbb..6e506cb 100644 --- a/drivers/hid/hid-redragon.c +++ b/drivers/hid/hid-redragon.c @@ -18,6 +18,21 @@ #include "hid-ids.h" +static __u8 asura_redragon_badfield[] = { + 0x05, 0x01, /* Usage Page (GenericDesktop) */ + 0x09, 0x06, /* Usage (Keyboard) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x85, 0x04, /* Report ID (4) */ + 0x05, 0x07, /* Usage Page (Keyboard) */ + 0x19, 0xe0, /* Usage Minimum (0xe0) Left Control */ + 0x29, 0xe7, /* Usage Maximum (0xe7) Right GUI */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x75, 0x01, /* Report Size (1) */ + 0x95, 0x08, /* Report Count(8) */ + 0x81, 0x00 /* Input Array [Should be Input Var] */ +}; + /* * The Redragon Asura keyboard sends an incorrect HID descriptor. @@ -36,7 +51,9 @@ static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) { - if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) { + if (*rsize == 169 && + memcmp(&rdesc[78], asura_redragon_badfield, + sizeof(asura_redragon_badfield)) == 0) { dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n"); rdesc[101] = 0x02; }