Simplify some error handling by assuming a >=3.4 kernel
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 11 Feb 2020 03:23:44 +0000 (13:23 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 11 Feb 2020 11:07:06 +0000 (21:07 +1000)
v3.4 was released in 2012, every kernel since has that ioctl. So instead of
assuming you're running new libevdev on an 8 year old kernel, let's assume
that any error from the ioctl() is an actual error and handle it accordingly.

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

index dbf8ea3..c1375f8 100644 (file)
@@ -708,7 +708,6 @@ sync_mt_state(struct libevdev *dev, int create_events)
        struct input_absinfo abs_info;
        int rc;
        int axis, slot;
-       int ioctl_success = 0;
        int last_reported_slot = 0;
        struct mt_sync_state *mt_state = dev->mt_sync.mt_state;
        unsigned long *slot_update = dev->mt_sync.slot_update;
@@ -730,36 +729,26 @@ sync_mt_state(struct libevdev *dev, int create_events)
 
                mt_state->code = axis;
                rc = ioctl(dev->fd, EVIOCGMTSLOTS(dev->mt_sync.mt_state_sz), mt_state);
-               if (rc < 0) {
-                       /* if the first ioctl fails with -EINVAL, chances are the kernel
-                          doesn't support the ioctl. Simply continue */
-                       if (errno == -EINVAL && !ioctl_success) {
-                               rc = 0;
-                       } else /* if the second, ... ioctl fails, really fail */
-                               goto out;
-               } else {
-                       if (ioctl_success == 0)
-                               ioctl_success = 1;
-
-                       for (slot = 0; slot < dev->num_slots; slot++) {
-
-                               if (*slot_value(dev, slot, axis) == mt_state->val[slot])
-                                       continue;
+               if (rc < 0)
+                       goto out;
 
-                               if (axis == ABS_MT_TRACKING_ID &&
-                                   *slot_value(dev, slot, axis) != -1 &&
-                                   mt_state->val[slot] != -1) {
-                                       set_bit(tracking_id_changes, slot);
-                                       need_tracking_id_changes = 1;
-                               }
+               for (slot = 0; slot < dev->num_slots; slot++) {
 
-                               *slot_value(dev, slot, axis) = mt_state->val[slot];
+                       if (*slot_value(dev, slot, axis) == mt_state->val[slot])
+                               continue;
 
-                               set_bit(slot_update, AXISBIT(slot, axis));
-                               /* note that this slot has updates */
-                               set_bit(slot_update, AXISBIT(slot, ABS_MT_SLOT));
+                       if (axis == ABS_MT_TRACKING_ID &&
+                           *slot_value(dev, slot, axis) != -1 &&
+                           mt_state->val[slot] != -1) {
+                               set_bit(tracking_id_changes, slot);
+                               need_tracking_id_changes = 1;
                        }
 
+                       *slot_value(dev, slot, axis) = mt_state->val[slot];
+
+                       set_bit(slot_update, AXISBIT(slot, axis));
+                       /* note that this slot has updates */
+                       set_bit(slot_update, AXISBIT(slot, ABS_MT_SLOT));
                }
        }