Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp420803yba; Wed, 3 Apr 2019 11:17:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIHOYOcnJaWO+kRvsA/9lTJV1C4mI4J+so90JU6zxlyp5eUpdjlOms6bitdbIfA2BFuYEH X-Received: by 2002:a62:482:: with SMTP id 124mr864776pfe.191.1554315469095; Wed, 03 Apr 2019 11:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554315469; cv=none; d=google.com; s=arc-20160816; b=ay7gtKATNJ9TC76iQJcPq4hrNFYlaH6bjjwYnNyQMQg1awEwdEbuSJq0d5pxFG1S7x jPXC0AeMlP0uf5h2ii4RLiPu3qd5qBwrxOEf5vUFf0FqKXCxGylrYDTFE/etMKKi7DCh z1Xa9N9ncsdt2QOKPSQje3O0qs4p4PdySSmFvC+nwx59wdtzG+vQjCOTfAIx22yRUjWP k4SgWgtFMcVb1lkaHEaICmMzV/weMek7loHLYkbmrfXiLNKGUp9b+Ek3wLyUJS5vKATx xGvyATMwuMWhZvD37IfYyI1fsJ9kMe8TA/yPPcQI39Ckk/5FL8vTf8k9Ka0szEItmiSU dwDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3gEgRK4OgXC5g0LnmPAwaAVG1D2rzi0B/jXz3s7AndQ=; b=QyLoSdA4zSOXCM0+y5VSX9PTLVNgbIJtD3VobI70eHuOspEICgGUM811XI4WklT3oy SiobzD+VYpW2zaDilGJU6VmOFEMZ3mIfSFuJ9jsVOeAUYF30Y3nqAHy09OyPyz61dDDB k2atCqJdswMaqPi12id6CuHyfu/tl35hZuoRKKhvPIJvQC/ZKf/O1yIstrJsy0V4veYq a6GR0j6qBR+tncAQa2Ye196H1dwYc0K9ph3OPQa8+PD9RsW7N2HrCpy5f2DcD0F7nofm V+luHKX1pFbWNKWlTqei9gASTtV+vifgm2qsUmKAieDVBk4rfSORY28Ce2hteyOU/11k kQqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OpeGXLFv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19si9431607pga.100.2019.04.03.11.17.33; Wed, 03 Apr 2019 11:17:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OpeGXLFv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbfDCSQr (ORCPT + 99 others); Wed, 3 Apr 2019 14:16:47 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34971 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfDCSQr (ORCPT ); Wed, 3 Apr 2019 14:16:47 -0400 Received: by mail-pg1-f194.google.com with SMTP id g8so8730883pgf.2; Wed, 03 Apr 2019 11:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=3gEgRK4OgXC5g0LnmPAwaAVG1D2rzi0B/jXz3s7AndQ=; b=OpeGXLFvJFVliRnAZwEKPEnpTEEKD425WL/UX+OOvMlVVQG4+UCwxNitRvME6oohHl C3W9QLBwD9xsUpBRuLcu2xp9t4yiHXAuQICpTyHiSJQcTrqvNyw8G/sicZO1Z2LFSr0X qMbp9v2UuVZtVCry83zMVOWXPhkcBZygqj45qyQWmNI7kdM4UyA3ok3VqQGWOC+rm6Lz 7b1Cdoin553+N2+AxcElcA/edRPf1h7gRvIcZXgoSxoe4P3GLFn1w10re4cfNMmVP7vv ZoDFXJEnoOo/H6E7Tq6GJ7etbikte+/Rb8ptEUvr0Mg6z9a0ED9HyJAM63oiJcRzUAqH B8Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3gEgRK4OgXC5g0LnmPAwaAVG1D2rzi0B/jXz3s7AndQ=; b=T6kblM3bPUGvMF5hXBbLty68iOQElHMG1IrijaX4vdZffTGRT9O0aMcugUTq1q1y/S g4EEVP2ezWJeejHh0da/AYei8k/L12Jr6GrsZVfSIva7e8UGuInWMmxhalsLsJwPxlxE 9BQjUwRwQJAxofmbWaZ0GEmHh4RYDgekUhIVRWDBob/EXixHAiA6NiurrnfAhEH2vX8a ni9uoUjZVescUUXYyOuMN+ryoaVnb2lR+8KayL9hIv+UyNJRp1TQzRN/KNdlix3hrk2A +yBR2Geo/WFsTFi683TCUwNS+Bc8wqSnaHuRoVpIr2NMHubEEcLEgTotUR0gGbLvC83m 9WRQ== X-Gm-Message-State: APjAAAXTdoXn2J0M6DtdKv8QIQJbAKY+AkNYiIcKoxP/YMRO9Kxcc19Y OehGR28jBmlz2LcZgYJyLVk= X-Received: by 2002:a63:e70c:: with SMTP id b12mr1027672pgi.399.1554315405753; Wed, 03 Apr 2019 11:16:45 -0700 (PDT) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id b8sm19197648pgq.33.2019.04.03.11.16.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Apr 2019 11:16:44 -0700 (PDT) Date: Wed, 3 Apr 2019 11:16:43 -0700 From: "dmitry.torokhov@gmail.com" To: Ken Sloat Cc: "josephl@nvidia.com" , "linux-input@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [BUG REPORT] linux-input: keyboard: gpio_keys: False Button Press Event on Wake Message-ID: <20190403181643.GC53104@dtor-ws> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ken, On Wed, Apr 03, 2019 at 05:50:09PM +0000, Ken Sloat wrote: > Hello Dmitry, > > I may have found a potential bug in the "gpio_keys" driver. FYI, I am > running the 4.14 LTS kernel on my system, but from my understanding of > the issue, it seems that this would still occur in the latest version > of the kernel. > > The problem: In the 4.14 LTS kernel, both key press and release events > can generate a wake event. In the 5.x kernel, wake events are > configurable for press only, release only or "both" (see > "wakeup-event-action" binding). The issue can occur in the "both" case > or release/deasserted case. Let's imagine that a system is suspended > when a gpio key button is pressed, and subsequently resumed when the > button is released. If we look at the sequence of actions and events > reported by the input system, we can see the potential problem: > > Button Pressed > Event Value 1 > System Suspend > Button Released > System Wake & Resume > Event Value 0 > Event Value 1 > Event Value 0 > > As you can see the input system will report an extra button > event/press. This appears to be caused in gpio_keys_gpio_isr by the > following statement: > > if (bdata->suspended && > (button->type == 0 || button->type == EV_KEY)) { > /* > * Simulate wakeup key press in case the key has > * already released by the time we got interrupt > * handler to run. > */ > input_report_key(bdata->input, button->code, 1); > } > > This code does not seem to take into account that the wake event may > have been caused by a button release action, and just assumes we must > have a button press. > > This can obviously be problematic in the use case I mentioned, as the > system would be put in a constant loop between waking and sleeping. > While there are other ways to deal with or react to this issue in the > userspace, it seems that the driver should probably take this into > account. > I believe the expectation is that we do not go to sleep with button still pressed, as we expect it to be released momentarily. Given that we do not know which edge woke us it is not clear if we can avoid simulating the keypress event, as this definitely causes "missed press", at least on some Android devices, where by the time we get to run this ISR user has already released the button. Thanks. -- Dmitry