From patchwork Mon Oct 26 13:21:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 285768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF207C2D0A3 for ; Mon, 26 Oct 2020 13:39:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AB7A21BE5 for ; Mon, 26 Oct 2020 13:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1780361AbgJZNjH (ORCPT ); Mon, 26 Oct 2020 09:39:07 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:33907 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1773077AbgJZNjH (ORCPT ); Mon, 26 Oct 2020 09:39:07 -0400 X-Greylist: delayed 1063 seconds by postgrey-1.27 at vger.kernel.org; Mon, 26 Oct 2020 09:39:07 EDT Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kX2R6-0007Kr-9q; Mon, 26 Oct 2020 14:21:20 +0100 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1kX2R5-0005Rj-4O; Mon, 26 Oct 2020 14:21:19 +0100 From: Oleksij Rempel To: Dmitry Torokhov , Alexandru Ardelean Cc: David Jander , Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH v1] Input: touchscreen: ads7846.c: Fix race that causes missing releases Date: Mon, 26 Oct 2020 14:21:17 +0100 Message-Id: <20201026132117.20887-1-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-input@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: David Jander If touchscreen is released while busy reading HWMON device, the release can be missed. The IRQ thread is not started because no touch is active and BTN_TOUCH release event is never sent. Fixes: f5a28a7d4858f94a ("Input: ads7846 - avoid pen up/down when reading hwmon") Co-Developed-by: David Jander Signed-off-by: David Jander Signed-off-by: Oleksij Rempel --- drivers/input/touchscreen/ads7846.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index ea31956f3a90..0236a119c52d 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -211,10 +211,26 @@ static void ads7846_stop(struct ads7846 *ts) } } +static int get_pendown_state(struct ads7846 *ts); + /* Must be called with ts->lock held */ static void ads7846_restart(struct ads7846 *ts) { + unsigned int pdstate; + if (!ts->disabled && !ts->suspended) { + /* Check if pen was released since last stop */ + if (ts->pendown && !get_pendown_state(ts)) { + struct input_dev *input = ts->input; + + input_report_key(input, BTN_TOUCH, 0); + input_report_abs(input, ABS_PRESSURE, 0); + input_sync(input); + + ts->pendown = false; + dev_vdbg(&ts->spi->dev, "UP\n"); + } + /* Tell IRQ thread that it may poll the device. */ ts->stopped = false; mb();