From patchwork Wed Nov 7 22:27:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 10673143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E24215A6 for ; Wed, 7 Nov 2018 22:27:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EBD42D1C0 for ; Wed, 7 Nov 2018 22:27:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52CBF2D331; Wed, 7 Nov 2018 22:27:36 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C153F2D1C0 for ; Wed, 7 Nov 2018 22:27:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728065AbeKHIAA (ORCPT ); Thu, 8 Nov 2018 03:00:00 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33307 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727495AbeKHIAA (ORCPT ); Thu, 8 Nov 2018 03:00:00 -0500 Received: by mail-pf1-f195.google.com with SMTP id v68-v6so4734475pfk.0 for ; Wed, 07 Nov 2018 14:27:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hErWVvVfq+l1Lhw6i7dkgVe6YlWD+RYolV83NWx0t70=; b=W669+dd2gXUy/GLOHJHuZBiSVkD0H0R6bEkU4q2iePeJSs92MQQzGIyJL9B1q1FZlM h6O8RtFQxa96Dwynh57Au7XRz9gTaRM4/M0RmRDYhfDCq8leMd/uiWlz5V/b8zcF2Zt0 uVzUhYKSEPGKuFYPq7e0D2MdKXn7cLQUsiW4c= 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:mime-version :content-transfer-encoding; bh=hErWVvVfq+l1Lhw6i7dkgVe6YlWD+RYolV83NWx0t70=; b=UrMAyqDt6mnfkMLaQmxc5622pSrygt/DAD/BoCfDc+ch6VliDOPTrr0uZESihDwN9j ErCDLF5+K2Wu3uGZzLEd4bkVvAZO/gLOoLJdwAfdE7Rzv/JSQkHn1lRE1FtCoNYT9wMp Al5IlOGFW/FI1DzJ4HnQK/FCtZ7jpHEZCEiY69dfJdmHJIAxPiDVgjV9a3mSJtHQ2HZt fA0DacAEcBvJVGCqTLEi+S70MF+qAC+5TolU84QisrTgzM4tgVceTSfJ9svdOtPexTVL xg44FMl8I41wvjtH+J0geRi9jW+FibqgcLQuJkRDD7KES7zo9Z7VGeJyb+P0UDpFHaNy +n2Q== X-Gm-Message-State: AGRZ1gL7IHcFP3lY99jEE7jV/bBwl3TfeaVuLxafE/saCwcx54bVaRdo RakC3MwrNG/SNLG3aO5KjkkNtA== X-Google-Smtp-Source: AJdET5fNzvFAiqFTFyKWaTgIMxcA3X+UmZK4NulEwXUrLVPTDTe403t7ZF571DOILoiMAMtHnNq0ow== X-Received: by 2002:a63:561b:: with SMTP id k27mr1787801pgb.271.1541629653794; Wed, 07 Nov 2018 14:27:33 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id 89-v6sm1934373pfq.10.2018.11.07.14.27.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 14:27:32 -0800 (PST) From: Brian Norris To: Dmitry Torokhov Cc: Enric Balletbo i Serra , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Doug Anderson Subject: [PATCH] input: cros_ec_keyb: fix button/switch capability reports Date: Wed, 7 Nov 2018 14:27:29 -0800 Message-Id: <20181107222729.170234-1-briannorris@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog MIME-Version: 1.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 cros_ec_keyb_bs array lists buttons and switches together, expecting that its users will match the appropriate type and bit fields. But cros_ec_keyb_register_bs() only checks the 'bit' field, which causes misreported input capabilities in some cases. For example, tablets (e.g., Scarlet -- a.k.a. Acer Chromebook Tab 10) were reporting a SW_LID capability, because EC_MKBP_POWER_BUTTON and EC_MKBP_LID_OPEN happen to share the same bit. (This has comedic effect on a tablet, in which a power-management daemon then thinks this "lid" is closed, and so puts the system to sleep as soon as it boots!) To fix this, check both the 'ev_type' and 'bit' fields before reporting the capability. Tested with a lid (Kevin / Samsung Chromebook Plus) and without a lid (Scarlet / Acer Chromebook Tab 10). This error got introduced when porting the feature from the downstream Chromium OS kernel to be upstreamed. Fixes: cdd7950e7aa4 ("input: cros_ec_keyb: Add non-matrix buttons and switches") Cc: Cc: Douglas Anderson Cc: Enric Balletbo i Serra Signed-off-by: Brian Norris --- drivers/input/keyboard/cros_ec_keyb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index 81be6f781f0b..d56001181598 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -493,7 +493,8 @@ static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev) for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) { const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i]; - if (buttons & BIT(map->bit)) + if ((map->ev_type == EV_KEY && (buttons & BIT(map->bit))) || + (map->ev_type == EV_SW && (switches & BIT(map->bit)))) input_set_capability(idev, map->ev_type, map->code); }