[PATCH libevdev 3/4] Return the size of the mask array when getting the mask

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 21 21:59:42 UTC 2016


Currently unused by the callers, this is prep work for an upcoming patch.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev-int.h | 47 +++++++++++++++++++++++++++--------------------
 libevdev/libevdev.c     |  4 ++--
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/libevdev/libevdev-int.h b/libevdev/libevdev-int.h
index e1c7ec5..6c5b8b6 100644
--- a/libevdev/libevdev-int.h
+++ b/libevdev/libevdev-int.h
@@ -286,9 +286,10 @@ queue_set_num_elements(struct libevdev *dev, size_t nelem)
 	return 0;
 }
 
-#define max_mask(uc, lc) \
+#define max_mask(uc, lc, sz) \
 	case EV_##uc: \
 			*mask = dev->lc##_bits; \
+			sz = sizeof(dev->lc##_bits); \
 			max = libevdev_event_type_get_max(type); \
 		break;
 
@@ -296,17 +297,18 @@ static inline int
 type_to_mask_const(const struct libevdev *dev, unsigned int type, const unsigned long **mask)
 {
 	int max;
+	size_t sz __attribute__((unused));
 
 	switch(type) {
-		max_mask(ABS, abs);
-		max_mask(REL, rel);
-		max_mask(KEY, key);
-		max_mask(LED, led);
-		max_mask(MSC, msc);
-		max_mask(SW, sw);
-		max_mask(FF, ff);
-		max_mask(REP, rep);
-		max_mask(SND, snd);
+		max_mask(ABS, abs, sz);
+		max_mask(REL, rel, sz);
+		max_mask(KEY, key, sz);
+		max_mask(LED, led, sz);
+		max_mask(MSC, msc, sz);
+		max_mask(SW, sw, sz);
+		max_mask(FF, ff, sz);
+		max_mask(REP, rep, sz);
+		max_mask(SND, snd, sz);
 		default:
 		     max = -1;
 		     break;
@@ -316,25 +318,30 @@ type_to_mask_const(const struct libevdev *dev, unsigned int type, const unsigned
 }
 
 static inline int
-type_to_mask(struct libevdev *dev, unsigned int type, unsigned long **mask)
+type_to_mask(struct libevdev *dev, unsigned int type,
+	     unsigned long **mask, size_t *size)
 {
 	int max;
+	size_t sz;
 
 	switch(type) {
-		max_mask(ABS, abs);
-		max_mask(REL, rel);
-		max_mask(KEY, key);
-		max_mask(LED, led);
-		max_mask(MSC, msc);
-		max_mask(SW, sw);
-		max_mask(FF, ff);
-		max_mask(REP, rep);
-		max_mask(SND, snd);
+		max_mask(ABS, abs, sz);
+		max_mask(REL, rel, sz);
+		max_mask(KEY, key, sz);
+		max_mask(LED, led, sz);
+		max_mask(MSC, msc, sz);
+		max_mask(SW, sw, sz);
+		max_mask(FF, ff, sz);
+		max_mask(REP, rep, sz);
+		max_mask(SND, snd, sz);
 		default:
 		     max = -1;
 		     break;
 	}
 
+	if (size)
+		*size = sz;
+
 	return max;
 }
 
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 48b49b1..149a0d7 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -1479,7 +1479,7 @@ libevdev_enable_event_code(struct libevdev *dev, unsigned int type,
 			break;
 	}
 
-	max = type_to_mask(dev, type, &mask);
+	max = type_to_mask(dev, type, &mask, NULL);
 
 	if (code > max || (int)max == -1)
 		return -1;
@@ -1506,7 +1506,7 @@ libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned in
 	if (type > EV_MAX || type == EV_SYN)
 		return -1;
 
-	max = type_to_mask(dev, type, &mask);
+	max = type_to_mask(dev, type, &mask, NULL);
 
 	if (code > max || (int)max == -1)
 		return -1;
-- 
2.7.3



More information about the Input-tools mailing list