All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq'
@ 2017-01-26 17:06 Jason Gerecke
  2017-01-26 20:44 ` Ping Cheng
  2017-01-26 20:52 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Gerecke @ 2017-01-26 17:06 UTC (permalink / raw)
  To: linux-input, Jiri Kosina
  Cc: Benjamin Tissoires, Ping Cheng, Aaron Skomra, Jason Gerecke,
	Jason Gerecke

Commit 025bcc1 performed cleanup work on the 'wacom_pl_irq' function, making
it follow the standards used in the rest of the codebase. The change
unintiontionally allowed the function to send input events from reports
that are not marked as being in prox. This can cause problems as the
report values for X, Y, etc. are not guaranteed to be correct. In
particular, occasionally the tablet will send a report with these values
set to zero. If such a report is received it can caus an unexpected jump
in the XY position.

This patch surrounds more of the processing code with a proximity check,
preventing these zeroed reports from overwriting the current state. To
be safe, only the tool type and ABS_MISC events should be reported when
the pen is marked as being out of prox.

Fixes: 025bcc1540 ("HID: wacom: Simplify 'wacom_pl_irq'")
Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 0884dc9554fd..672145b0d8f5 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -166,19 +166,21 @@ static int wacom_pl_irq(struct wacom_wac *wacom)
 		wacom->id[0] = STYLUS_DEVICE_ID;
 	}
 
-	pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
-	if (features->pressure_max > 255)
-		pressure = (pressure << 1) | ((data[4] >> 6) & 1);
-	pressure += (features->pressure_max + 1) / 2;
-
-	input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
-	input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
-	input_report_abs(input, ABS_PRESSURE, pressure);
-
-	input_report_key(input, BTN_TOUCH, data[4] & 0x08);
-	input_report_key(input, BTN_STYLUS, data[4] & 0x10);
-	/* Only allow the stylus2 button to be reported for the pen tool. */
-	input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
+	if (prox) {
+		pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
+		if (features->pressure_max > 255)
+			pressure = (pressure << 1) | ((data[4] >> 6) & 1);
+		pressure += (features->pressure_max + 1) / 2;
+
+		input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
+		input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
+		input_report_abs(input, ABS_PRESSURE, pressure);
+
+		input_report_key(input, BTN_TOUCH, data[4] & 0x08);
+		input_report_key(input, BTN_STYLUS, data[4] & 0x10);
+		/* Only allow the stylus2 button to be reported for the pen tool. */
+		input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
+	}
 
 	if (!prox)
 		wacom->id[0] = 0;
-- 
2.11.0


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

* Re: [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq'
  2017-01-26 17:06 [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq' Jason Gerecke
@ 2017-01-26 20:44 ` Ping Cheng
  2017-01-26 20:52 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Ping Cheng @ 2017-01-26 20:44 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: linux-input, Jiri Kosina, Benjamin Tissoires, Aaron Skomra,
	Jason Gerecke

On Thu, Jan 26, 2017 at 9:06 AM, Jason Gerecke <killertofu@gmail.com> wrote:
> Commit 025bcc1 performed cleanup work on the 'wacom_pl_irq' function, making
> it follow the standards used in the rest of the codebase. The change
> unintiontionally allowed the function to send input events from reports
> that are not marked as being in prox. This can cause problems as the
> report values for X, Y, etc. are not guaranteed to be correct. In
> particular, occasionally the tablet will send a report with these values
> set to zero. If such a report is received it can caus an unexpected jump
> in the XY position.
>
> This patch surrounds more of the processing code with a proximity check,
> preventing these zeroed reports from overwriting the current state. To
> be safe, only the tool type and ABS_MISC events should be reported when
> the pen is marked as being out of prox.
>
> Fixes: 025bcc1540 ("HID: wacom: Simplify 'wacom_pl_irq'")
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>

Reviewed-by: Ping Cheng <pingc@wacom.com>

Cheers,
Ping

P.S., this patch has been tested by users at linuxwacom.sf.net

> ---
>  drivers/hid/wacom_wac.c | 28 +++++++++++++++-------------
>  1 file changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 0884dc9554fd..672145b0d8f5 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -166,19 +166,21 @@ static int wacom_pl_irq(struct wacom_wac *wacom)
>                 wacom->id[0] = STYLUS_DEVICE_ID;
>         }
>
> -       pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
> -       if (features->pressure_max > 255)
> -               pressure = (pressure << 1) | ((data[4] >> 6) & 1);
> -       pressure += (features->pressure_max + 1) / 2;
> -
> -       input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
> -       input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
> -       input_report_abs(input, ABS_PRESSURE, pressure);
> -
> -       input_report_key(input, BTN_TOUCH, data[4] & 0x08);
> -       input_report_key(input, BTN_STYLUS, data[4] & 0x10);
> -       /* Only allow the stylus2 button to be reported for the pen tool. */
> -       input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
> +       if (prox) {
> +               pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
> +               if (features->pressure_max > 255)
> +                       pressure = (pressure << 1) | ((data[4] >> 6) & 1);
> +               pressure += (features->pressure_max + 1) / 2;
> +
> +               input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
> +               input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
> +               input_report_abs(input, ABS_PRESSURE, pressure);
> +
> +               input_report_key(input, BTN_TOUCH, data[4] & 0x08);
> +               input_report_key(input, BTN_STYLUS, data[4] & 0x10);
> +               /* Only allow the stylus2 button to be reported for the pen tool. */
> +               input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
> +       }
>
>         if (!prox)
>                 wacom->id[0] = 0;
> --
> 2.11.0
>

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

* Re: [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq'
  2017-01-26 17:06 [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq' Jason Gerecke
  2017-01-26 20:44 ` Ping Cheng
@ 2017-01-26 20:52 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2017-01-26 20:52 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: linux-input, Benjamin Tissoires, Ping Cheng, Aaron Skomra, Jason Gerecke

On Thu, 26 Jan 2017, Jason Gerecke wrote:

> Commit 025bcc1 performed cleanup work on the 'wacom_pl_irq' function, making
> it follow the standards used in the rest of the codebase. The change
> unintiontionally allowed the function to send input events from reports
> that are not marked as being in prox. This can cause problems as the
> report values for X, Y, etc. are not guaranteed to be correct. In
> particular, occasionally the tablet will send a report with these values
> set to zero. If such a report is received it can caus an unexpected jump
> in the XY position.
> 
> This patch surrounds more of the processing code with a proximity check,
> preventing these zeroed reports from overwriting the current state. To
> be safe, only the tool type and ABS_MISC events should be reported when
> the pen is marked as being out of prox.
> 
> Fixes: 025bcc1540 ("HID: wacom: Simplify 'wacom_pl_irq'")
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2017-01-26 21:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 17:06 [PATCH] HID: wacom: Fix poor prox handling in 'wacom_pl_irq' Jason Gerecke
2017-01-26 20:44 ` Ping Cheng
2017-01-26 20:52 ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.