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

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