Blame SOURCES/0004-Remember-the-event-types-we-receive-and-skip-events-.patch

33a11a
From 13b35027202496be168b3c345cd6fc65055f9604 Mon Sep 17 00:00:00 2001
33a11a
From: Peter Hutterer <peter.hutterer@who-t.net>
33a11a
Date: Wed, 24 Oct 2018 10:35:17 +1000
33a11a
Subject: [PATCH 4/4] Remember the event types we receive and skip events with
33a11a
 no data
33a11a
33a11a
On RHEL7.x kernels we get event frames with merely MSC_SERIAL -1 for some
33a11a
devices on proximity in. This is caused by the accelerometer data that is
33a11a
otherwise suppressed by those kernels.
33a11a
33a11a
E: 123.456 0000 0000 0000       # ------------ SYN_REPORT (0) ----------
33a11a
E: 123.456 0004 0000 -001       # EV_MSC / MSC_SERIAL           -1
33a11a
33a11a
For a MSC_SERIAL -1 we default to the PAD_ID (0x10), despite the events
33a11a
happening on the Pen device node. This triggers an error message during EV_SYN
33a11a
processing:
33a11a
33a11a
   (EE) usbDispatchEvents: Device Type mismatch - 16 -> 0. This is a BUG.
33a11a
33a11a
Once we receive the BTN_TOOL_PEN when the actual pen comes into proximity, the
33a11a
error message goes away because our tool type matches with what we expect.
33a11a
33a11a
Fix this issue by remembering which event types we received in the current
33a11a
frame. If all we got was EV_MSC, skip the event dispatch - we don't have any
33a11a
data to process anyway.
33a11a
33a11a
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
33a11a
Reviewed-by: Ping Cheng <ping.cheng@wacom.com>
33a11a
(cherry picked from commit 84400df38f0f9abe664de26a8d3747b10f3a05e5)
33a11a
---
33a11a
 src/wcmUSB.c | 24 ++++++++++++++++++------
33a11a
 1 file changed, 18 insertions(+), 6 deletions(-)
33a11a
33a11a
diff --git a/src/wcmUSB.c b/src/wcmUSB.c
33a11a
index cf89ff8..2bb6b78 100644
33a11a
--- a/src/wcmUSB.c
33a11a
+++ b/src/wcmUSB.c
33a11a
@@ -38,6 +38,7 @@ typedef struct {
33a11a
 	int wcmMTChannel;
33a11a
 	int wcmEventCnt;
33a11a
 	struct input_event wcmEvents[MAX_USB_EVENTS];
33a11a
+	uint32_t wcmEventFlags;      /* event types received in this frame */
33a11a
 	int nbuttons;                /* total number of buttons */
33a11a
 	int npadkeys;                /* number of pad keys in the above array */
33a11a
 	int padkey_code[WCM_MAX_BUTTONS];/* hardware codes for buttons */
33a11a
@@ -973,6 +974,13 @@ static int usbChooseChannel(WacomCommonPtr common, int device_type, unsigned int
33a11a
 	return channel;
33a11a
 }
33a11a
 
33a11a
+static inline void
33a11a
+usbResetEventCounter(wcmUSBData *private)
33a11a
+{
33a11a
+	private->wcmEventCnt = 0;
33a11a
+	private->wcmEventFlags = 0;
33a11a
+}
33a11a
+
33a11a
 static void usbParseEvent(InputInfoPtr pInfo,
33a11a
 	const struct input_event* event)
33a11a
 {
33a11a
@@ -989,12 +997,13 @@ static void usbParseEvent(InputInfoPtr pInfo,
33a11a
 	{
33a11a
 		LogMessageVerbSigSafe(X_ERROR, 0, "%s: usbParse: Exceeded event queue (%d) \n",
33a11a
 				      pInfo->name, private->wcmEventCnt);
33a11a
-		private->wcmEventCnt = 0;
33a11a
+		usbResetEventCounter(private);
33a11a
 		return;
33a11a
 	}
33a11a
 
33a11a
 	/* save it for later */
33a11a
 	private->wcmEvents[private->wcmEventCnt++] = *event;
33a11a
+	private->wcmEventFlags |= 1 << event->type;
33a11a
 
33a11a
 	switch (event->type)
33a11a
 	{
33a11a
@@ -1032,7 +1041,7 @@ static void usbParseMscEvent(InputInfoPtr pInfo,
33a11a
 		LogMessageVerbSigSafe(X_ERROR, 0,
33a11a
 				      "%s: usbParse: Ignoring event from invalid serial 0\n",
33a11a
 				      pInfo->name);
33a11a
-		private->wcmEventCnt = 0;
33a11a
+		usbResetEventCounter(private);
33a11a
 	}
33a11a
 }
33a11a
 
33a11a
@@ -1048,6 +1057,7 @@ static void usbParseSynEvent(InputInfoPtr pInfo,
33a11a
 	WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
33a11a
 	WacomCommonPtr common = priv->common;
33a11a
 	wcmUSBData* private = common->private;
33a11a
+	const uint32_t significant_event_types = ~(1 << EV_SYN | 1 << EV_MSC);
33a11a
 
33a11a
 	if (event->code != SYN_REPORT)
33a11a
 		return;
33a11a
@@ -1060,9 +1070,11 @@ static void usbParseSynEvent(InputInfoPtr pInfo,
33a11a
 		goto skipEvent;
33a11a
 	}
33a11a
 
33a11a
-	/* ignore sync windows that contain no data */
33a11a
-	if (private->wcmEventCnt == 1 &&
33a11a
-	    private->wcmEvents->type == EV_SYN) {
33a11a
+
33a11a
+	/* If all we get in an event frame is EV_SYN/EV_MSC, we don't have
33a11a
+	 * real data to process. */
33a11a
+	if ((private->wcmEventFlags & significant_event_types) == 0)
33a11a
+	{
33a11a
 		DBG(6, common, "no real events received\n");
33a11a
 		goto skipEvent;
33a11a
 	}
33a11a
@@ -1071,7 +1083,7 @@ static void usbParseSynEvent(InputInfoPtr pInfo,
33a11a
 	usbDispatchEvents(pInfo);
33a11a
 
33a11a
 skipEvent:
33a11a
-	private->wcmEventCnt = 0;
33a11a
+	usbResetEventCounter(private);
33a11a
 }
33a11a
 
33a11a
 static int usbFilterEvent(WacomCommonPtr common, struct input_event *event)
33a11a
-- 
33a11a
2.19.2
33a11a