linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases
@ 2020-10-27 10:54 Oleksij Rempel
  2020-11-09 11:00 ` Oleksij Rempel
  2020-11-11 19:07 ` Dmitry Torokhov
  0 siblings, 2 replies; 5+ messages in thread
From: Oleksij Rempel @ 2020-10-27 10:54 UTC (permalink / raw)
  To: Dmitry Torokhov, Alexandru Ardelean
  Cc: David Jander, Oleksij Rempel, kernel, linux-kernel, linux-input

From: David Jander <david@protonic.nl>

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 <david@protonic.nl>
Signed-off-by: David Jander <david@protonic.nl>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/input/touchscreen/ads7846.c | 44 +++++++++++++++++------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index f2dc2c8ab5ec..4164a9834b59 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -199,6 +199,26 @@ struct ads7846 {
 #define	REF_ON	(READ_12BIT_DFR(x, 1, 1))
 #define	REF_OFF	(READ_12BIT_DFR(y, 0, 0))
 
+static int get_pendown_state(struct ads7846 *ts)
+{
+	if (ts->get_pendown_state)
+		return ts->get_pendown_state();
+
+	return !gpio_get_value(ts->gpio_pendown);
+}
+
+static void ads7846_report_pen_up(struct ads7846 *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");
+}
+
 /* Must be called with ts->lock held */
 static void ads7846_stop(struct ads7846 *ts)
 {
@@ -215,6 +235,10 @@ static void ads7846_stop(struct ads7846 *ts)
 static void ads7846_restart(struct ads7846 *ts)
 {
 	if (!ts->disabled && !ts->suspended) {
+		/* Check if pen was released since last stop */
+		if (ts->pendown && !get_pendown_state(ts))
+			ads7846_report_pen_up(ts);
+
 		/* Tell IRQ thread that it may poll the device. */
 		ts->stopped = false;
 		mb();
@@ -606,14 +630,6 @@ static const struct attribute_group ads784x_attr_group = {
 
 /*--------------------------------------------------------------------------*/
 
-static int get_pendown_state(struct ads7846 *ts)
-{
-	if (ts->get_pendown_state)
-		return ts->get_pendown_state();
-
-	return !gpio_get_value(ts->gpio_pendown);
-}
-
 static void null_wait_for_sync(void)
 {
 }
@@ -868,16 +884,8 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
 				   msecs_to_jiffies(TS_POLL_PERIOD));
 	}
 
-	if (ts->pendown && !ts->stopped) {
-		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");
-	}
+	if (ts->pendown && !ts->stopped)
+		ads7846_report_pen_up(ts);
 
 	return IRQ_HANDLED;
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases
  2020-10-27 10:54 [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases Oleksij Rempel
@ 2020-11-09 11:00 ` Oleksij Rempel
  2020-11-11 19:07 ` Dmitry Torokhov
  1 sibling, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2020-11-09 11:00 UTC (permalink / raw)
  To: Dmitry Torokhov, Alexandru Ardelean
  Cc: David Jander, kernel, linux-kernel, linux-input

Hello Dmitry,

ping for this patch. Are there some changes needed?

Regards,
Oleksij

On Tue, Oct 27, 2020 at 11:54:16AM +0100, Oleksij Rempel wrote:
> From: David Jander <david@protonic.nl>
> 
> 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 <david@protonic.nl>
> Signed-off-by: David Jander <david@protonic.nl>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/input/touchscreen/ads7846.c | 44 +++++++++++++++++------------
>  1 file changed, 26 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index f2dc2c8ab5ec..4164a9834b59 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -199,6 +199,26 @@ struct ads7846 {
>  #define	REF_ON	(READ_12BIT_DFR(x, 1, 1))
>  #define	REF_OFF	(READ_12BIT_DFR(y, 0, 0))
>  
> +static int get_pendown_state(struct ads7846 *ts)
> +{
> +	if (ts->get_pendown_state)
> +		return ts->get_pendown_state();
> +
> +	return !gpio_get_value(ts->gpio_pendown);
> +}
> +
> +static void ads7846_report_pen_up(struct ads7846 *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");
> +}
> +
>  /* Must be called with ts->lock held */
>  static void ads7846_stop(struct ads7846 *ts)
>  {
> @@ -215,6 +235,10 @@ static void ads7846_stop(struct ads7846 *ts)
>  static void ads7846_restart(struct ads7846 *ts)
>  {
>  	if (!ts->disabled && !ts->suspended) {
> +		/* Check if pen was released since last stop */
> +		if (ts->pendown && !get_pendown_state(ts))
> +			ads7846_report_pen_up(ts);
> +
>  		/* Tell IRQ thread that it may poll the device. */
>  		ts->stopped = false;
>  		mb();
> @@ -606,14 +630,6 @@ static const struct attribute_group ads784x_attr_group = {
>  
>  /*--------------------------------------------------------------------------*/
>  
> -static int get_pendown_state(struct ads7846 *ts)
> -{
> -	if (ts->get_pendown_state)
> -		return ts->get_pendown_state();
> -
> -	return !gpio_get_value(ts->gpio_pendown);
> -}
> -
>  static void null_wait_for_sync(void)
>  {
>  }
> @@ -868,16 +884,8 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
>  				   msecs_to_jiffies(TS_POLL_PERIOD));
>  	}
>  
> -	if (ts->pendown && !ts->stopped) {
> -		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");
> -	}
> +	if (ts->pendown && !ts->stopped)
> +		ads7846_report_pen_up(ts);
>  
>  	return IRQ_HANDLED;
>  }
> -- 
> 2.28.0
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases
  2020-10-27 10:54 [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases Oleksij Rempel
  2020-11-09 11:00 ` Oleksij Rempel
@ 2020-11-11 19:07 ` Dmitry Torokhov
  2020-11-12 11:48   ` Oleksij Rempel
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2020-11-11 19:07 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Alexandru Ardelean, David Jander, kernel, linux-kernel, linux-input

Hi Oleksij,

On Tue, Oct 27, 2020 at 11:54:16AM +0100, Oleksij Rempel wrote:
> From: David Jander <david@protonic.nl>
> 
> 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 <david@protonic.nl>

Since the patch is nominally attributed to David (via the From: tag)
I'll be changing Co-developed-by tag to your name, OK?

> Signed-off-by: David Jander <david@protonic.nl>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases
  2020-11-11 19:07 ` Dmitry Torokhov
@ 2020-11-12 11:48   ` Oleksij Rempel
  2020-11-18  0:31     ` Dmitry Torokhov
  0 siblings, 1 reply; 5+ messages in thread
From: Oleksij Rempel @ 2020-11-12 11:48 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Alexandru Ardelean, David Jander, kernel, linux-kernel, linux-input

On Wed, Nov 11, 2020 at 11:07:40AM -0800, Dmitry Torokhov wrote:
> Hi Oleksij,
> 
> On Tue, Oct 27, 2020 at 11:54:16AM +0100, Oleksij Rempel wrote:
> > From: David Jander <david@protonic.nl>
> > 
> > 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 <david@protonic.nl>
> 
> Since the patch is nominally attributed to David (via the From: tag)
> I'll be changing Co-developed-by tag to your name, OK?

OK.

> 
> > Signed-off-by: David Jander <david@protonic.nl>
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Regards,
Oleksij

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases
  2020-11-12 11:48   ` Oleksij Rempel
@ 2020-11-18  0:31     ` Dmitry Torokhov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2020-11-18  0:31 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Alexandru Ardelean, David Jander, kernel, linux-kernel, linux-input

On Thu, Nov 12, 2020 at 12:48:51PM +0100, Oleksij Rempel wrote:
> On Wed, Nov 11, 2020 at 11:07:40AM -0800, Dmitry Torokhov wrote:
> > Hi Oleksij,
> > 
> > On Tue, Oct 27, 2020 at 11:54:16AM +0100, Oleksij Rempel wrote:
> > > From: David Jander <david@protonic.nl>
> > > 
> > > 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 <david@protonic.nl>
> > 
> > Since the patch is nominally attributed to David (via the From: tag)
> > I'll be changing Co-developed-by tag to your name, OK?
> 
> OK.

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-18  0:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 10:54 [PATCH v2] Input: touchscreen: ads7846.c: Fix race that causes missing releases Oleksij Rempel
2020-11-09 11:00 ` Oleksij Rempel
2020-11-11 19:07 ` Dmitry Torokhov
2020-11-12 11:48   ` Oleksij Rempel
2020-11-18  0:31     ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).