[PATCH libevdev 5/6] Move slot-related initialization down

Peter Hutterer peter.hutterer at who-t.net
Tue Apr 1 19:17:28 PDT 2014


No real effects, but improves readability

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev.c | 73 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 35 deletions(-)

diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index ab67002..2262284 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -379,47 +379,50 @@ libevdev_set_fd(struct libevdev* dev, int fd)
 				goto out;
 
 			dev->abs_info[i] = abs_info;
-
-			/* devices with ABS_MT_SLOT - 1 aren't MT devices,
-			   see the documentation for multitouch-related
-			   functions for more details */
-			if (i == ABS_MT_SLOT &&
-			    !libevdev_has_event_code(dev, EV_ABS, ABS_MT_SLOT - 1)) {
-				dev->num_slots = abs_info.maximum + 1;
-				dev->mt_slot_vals = calloc(dev->num_slots * ABS_MT_CNT, sizeof(int));
-				if (!dev->mt_slot_vals) {
-					rc = -ENOMEM;
-					goto out;
-				}
-				dev->current_slot = abs_info.value;
-
-				dev->mt_sync.mt_state_sz = sizeof(*dev->mt_sync.mt_state) +
-							   (dev->num_slots) * sizeof(int);
-				dev->mt_sync.mt_state = calloc(1, dev->mt_sync.mt_state_sz);
-				if (!dev->mt_sync.mt_state) {
-					rc = -ENOMEM;
-					goto out;
-				}
-
-				dev->mt_sync.tracking_id_changes_sz = NLONGS(dev->num_slots) * sizeof(long);
-				dev->mt_sync.tracking_id_changes = malloc(dev->mt_sync.tracking_id_changes_sz);
-
-				dev->mt_sync.slot_update_sz = NLONGS(dev->num_slots * ABS_MT_CNT) * sizeof(long);
-				dev->mt_sync.slot_update = malloc(dev->mt_sync.slot_update_sz);
-
-				if (!dev->mt_sync.tracking_id_changes ||
-				    !dev->mt_sync.slot_update) {
-					rc = -ENOMEM;
-					goto out;
-				}
-			}
 		}
 	}
 
 	dev->fd = fd;
+
+	/* devices with ABS_MT_SLOT - 1 aren't MT devices,
+	   see the documentation for multitouch-related
+	   functions for more details */
 	if (!libevdev_has_event_code(dev, EV_ABS, ABS_MT_SLOT - 1) &&
-	    libevdev_has_event_code(dev, EV_ABS, ABS_MT_SLOT))
+	    libevdev_has_event_code(dev, EV_ABS, ABS_MT_SLOT)) {
+		const struct input_absinfo *abs_info;
+
+		abs_info = libevdev_get_abs_info(dev, ABS_MT_SLOT);
+
+		dev->num_slots = abs_info->maximum + 1;
+		dev->mt_slot_vals = calloc(dev->num_slots * ABS_MT_CNT, sizeof(int));
+		if (!dev->mt_slot_vals) {
+			rc = -ENOMEM;
+			goto out;
+		}
+		dev->current_slot = abs_info->value;
+
+		dev->mt_sync.mt_state_sz = sizeof(*dev->mt_sync.mt_state) +
+					   (dev->num_slots) * sizeof(int);
+		dev->mt_sync.mt_state = calloc(1, dev->mt_sync.mt_state_sz);
+		if (!dev->mt_sync.mt_state) {
+			rc = -ENOMEM;
+			goto out;
+		}
+
+		dev->mt_sync.tracking_id_changes_sz = NLONGS(dev->num_slots) * sizeof(long);
+		dev->mt_sync.tracking_id_changes = malloc(dev->mt_sync.tracking_id_changes_sz);
+
+		dev->mt_sync.slot_update_sz = NLONGS(dev->num_slots * ABS_MT_CNT) * sizeof(long);
+		dev->mt_sync.slot_update = malloc(dev->mt_sync.slot_update_sz);
+
+		if (!dev->mt_sync.tracking_id_changes ||
+		    !dev->mt_sync.slot_update) {
+			rc = -ENOMEM;
+			goto out;
+		}
+
 	    sync_mt_state(dev, 0);
+	}
 
 	rc = init_event_queue(dev);
 	if (rc < 0) {
-- 
1.9.0



More information about the Input-tools mailing list