diff mbox series

HID: wacom: Use "Confidence" flag to prevent reporting invalid contacts

Message ID 20211109003101.425207-1-jason.gerecke@wacom.com (mailing list archive)
State Mainlined
Commit 7fb0413baa7f8a04caef0c504df9af7e0623d296
Delegated to: Jiri Kosina
Headers show
Series HID: wacom: Use "Confidence" flag to prevent reporting invalid contacts | expand

Commit Message

Gerecke, Jason Nov. 9, 2021, 12:31 a.m. UTC
The HID descriptor of many of Wacom's touch input devices include a
"Confidence" usage that signals if a particular touch collection contains
useful data. The driver does not look at this flag, however, which causes
even invalid contacts to be reported to userspace. A lucky combination of
kernel event filtering and device behavior (specifically: contact ID 0 ==
invalid, contact ID >0 == valid; and order all data so that all valid
contacts are reported before any invalid contacts) spare most devices from
any visibly-bad behavior.

The DTH-2452 is one example of an unlucky device that misbehaves. It uses
ID 0 for both the first valid contact and all invalid contacts. Because
we report both the valid and invalid contacts, the kernel reports that
contact 0 first goes down (valid) and then goes up (invalid) in every
report. This causes ~100 clicks per second simply by touching the screen.

This patch inroduces new `confidence` flag in our `hid_data` structure.
The value is initially set to `true` at the start of a report and can be
set to `false` if an invalid touch usage is seen.

Link: https://github.com/linuxwacom/input-wacom/issues/270
Fixes: f8b6a74719b5 ("HID: wacom: generic: Support multiple tools per report")
Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Tested-by: Joshua Dickens <joshua.dickens@wacom.com>
Cc: <stable@vger.kernel.org>
---
 drivers/hid/wacom_wac.c | 8 +++++++-
 drivers/hid/wacom_wac.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

Comments

Jiri Kosina Nov. 10, 2021, 9:02 a.m. UTC | #1
On Mon, 8 Nov 2021, Jason Gerecke wrote:

> The HID descriptor of many of Wacom's touch input devices include a
> "Confidence" usage that signals if a particular touch collection contains
> useful data. The driver does not look at this flag, however, which causes
> even invalid contacts to be reported to userspace. A lucky combination of
> kernel event filtering and device behavior (specifically: contact ID 0 ==
> invalid, contact ID >0 == valid; and order all data so that all valid
> contacts are reported before any invalid contacts) spare most devices from
> any visibly-bad behavior.
> 
> The DTH-2452 is one example of an unlucky device that misbehaves. It uses
> ID 0 for both the first valid contact and all invalid contacts. Because
> we report both the valid and invalid contacts, the kernel reports that
> contact 0 first goes down (valid) and then goes up (invalid) in every
> report. This causes ~100 clicks per second simply by touching the screen.
> 
> This patch inroduces new `confidence` flag in our `hid_data` structure.
> The value is initially set to `true` at the start of a report and can be
> set to `false` if an invalid touch usage is seen.
> 
> Link: https://github.com/linuxwacom/input-wacom/issues/270
> Fixes: f8b6a74719b5 ("HID: wacom: generic: Support multiple tools per report")
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> Tested-by: Joshua Dickens <joshua.dickens@wacom.com>
> Cc: <stable@vger.kernel.org>

Applied, thanks Jason.
diff mbox series

Patch

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 33a6908995b1..2a4cc39962e7 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -2603,6 +2603,9 @@  static void wacom_wac_finger_event(struct hid_device *hdev,
 		return;
 
 	switch (equivalent_usage) {
+	case HID_DG_CONFIDENCE:
+		wacom_wac->hid_data.confidence = value;
+		break;
 	case HID_GD_X:
 		wacom_wac->hid_data.x = value;
 		break;
@@ -2635,7 +2638,8 @@  static void wacom_wac_finger_event(struct hid_device *hdev,
 	}
 
 	if (usage->usage_index + 1 == field->report_count) {
-		if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
+		if (equivalent_usage == wacom_wac->hid_data.last_slot_field &&
+		    wacom_wac->hid_data.confidence)
 			wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
 	}
 }
@@ -2653,6 +2657,8 @@  static void wacom_wac_finger_pre_report(struct hid_device *hdev,
 
 	wacom_wac->is_invalid_bt_frame = false;
 
+	hid_data->confidence = true;
+
 	for (i = 0; i < report->maxfield; i++) {
 		struct hid_field *field = report->field[i];
 		int j;
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index 8b2d4e5b2303..466b62cc16dc 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -301,6 +301,7 @@  struct hid_data {
 	bool barrelswitch;
 	bool barrelswitch2;
 	bool serialhi;
+	bool confidence;
 	int x;
 	int y;
 	int pressure;