Fix invalid absinfo range values reported by certain mtk soc
authorAndreas Pokorny <andreas.pokorny@canonical.com>
Sun, 23 Aug 2015 16:27:28 +0000 (18:27 +0200)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 24 Aug 2015 06:26:00 +0000 (16:26 +1000)
This change will only affect certain touch screens, for which the driver
integration code does not provide meaningful values for the allowed range
of ABS_MT_TRACKING_IDs. The reported range [0, 0] will be overwritten with
[-1, 0xFFFF]

Signed-off-by: Andreas Pokorny <andreas.pokorny@canonical.com>
[Changed from INT_MAX to 0xFFFF to match the kernel, add device name to log
message]

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
libevdev/libevdev.c

index 3a82fc72853b733ad78200d50857608eb38489f1..48b49b16afa96ffb73b2a33c7b7fc1f7a09afd91 100644 (file)
@@ -25,6 +25,7 @@
 #include <poll.h>
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -126,6 +127,26 @@ libevdev_dflt_log_func(enum libevdev_log_priority priority,
        vfprintf(stderr, format, args);
 }
 
+static void
+fix_invalid_absinfo(const struct libevdev *dev,
+                   int axis,
+                   struct input_absinfo* abs_info)
+{
+       /*
+        * The reported absinfo for ABS_MT_TRACKING_ID is sometimes
+        * uninitialized for certain mtk-soc, due to init code mangling
+        * in the vendor kernel.
+        */
+       if (axis == ABS_MT_TRACKING_ID &&
+           abs_info->maximum == abs_info->minimum) {
+               abs_info->minimum = -1;
+               abs_info->maximum = 0xFFFF;
+               log_bug(dev,
+                       "Device \"%s\" has invalid ABS_MT_TRACKING_ID range",
+                       dev->name);
+       }
+}
+
 /*
  * Global logging settings.
  */
@@ -431,6 +452,8 @@ libevdev_set_fd(struct libevdev* dev, int fd)
                        if (rc < 0)
                                goto out;
 
+                       fix_invalid_absinfo(dev, i, &abs_info);
+
                        dev->abs_info[i] = abs_info;
                }
        }