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

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