touchpad: check touchpad for basic features we expect
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 28 May 2015 03:41:58 +0000 (13:41 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 29 May 2015 02:23:05 +0000 (12:23 +1000)
If a relative device is tagged by udev as ID_INPUT_TOUCHPAD we need to
catch this before we try to dereference device->abs.absinfo_x.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev-mt-touchpad.c

index b18f74e91fda618ad2ad0b1fe0e66a16a111ec52..eacec6e3abcf8d1da5b55a8662b3e086562c36ef 100644 (file)
@@ -1439,6 +1439,30 @@ tp_init_sendevents(struct tp_dispatch *tp,
        return 0;
 }
 
+static int
+tp_sanity_check(struct tp_dispatch *tp,
+               struct evdev_device *device)
+{
+       struct libevdev *evdev = device->evdev;
+       struct libinput *libinput = tp_libinput_context(tp);
+
+       if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X))
+               goto error;
+
+       if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH))
+               goto error;
+
+       if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER))
+               goto error;
+
+       return 0;
+
+error:
+       log_bug_kernel(libinput,
+                      "device %s failed touchpad sanity checks\n");
+       return -1;
+}
+
 static int
 tp_init(struct tp_dispatch *tp,
        struct evdev_device *device)
@@ -1449,6 +1473,9 @@ tp_init(struct tp_dispatch *tp,
        tp->base.interface = &tp_interface;
        tp->device = device;
 
+       if (tp_sanity_check(tp, device) != 0)
+               return -1;
+
        if (tp_init_slots(tp, device) != 0)
                return -1;