From dc27c627a7ca7759b3cc917e2fa76dc83dcbc5bf Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Jun 2013 11:22:35 +1000 Subject: [PATCH] Fix type_to_mask to return -1 EV_SYN doesn't have a max, so 0 is not enough. returning 0 on failure is a bad idea, as mask is unset. --- libevdev/libevdev-util.h | 12 ++++++------ libevdev/libevdev.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libevdev/libevdev-util.h b/libevdev/libevdev-util.h index 74f8edb..b052597 100644 --- a/libevdev/libevdev-util.h +++ b/libevdev/libevdev-util.h @@ -53,10 +53,10 @@ set_bit_state(unsigned long *array, int bit, int state) clear_bit(array, bit); } -static inline unsigned int +static inline int type_to_mask_const(const struct libevdev *dev, unsigned int type, const unsigned long **mask) { - unsigned int max; + int max; switch(type) { case EV_ABS: @@ -76,16 +76,16 @@ type_to_mask_const(const struct libevdev *dev, unsigned int type, const unsigned max = LED_MAX; break; default: - return 0; + return -1; } return max; } -static inline unsigned int +static inline int type_to_mask(struct libevdev *dev, unsigned int type, unsigned long **mask) { - unsigned int max; + int max; switch(type) { case EV_ABS: @@ -105,7 +105,7 @@ type_to_mask(struct libevdev *dev, unsigned int type, unsigned long **mask) max = LED_MAX; break; default: - return 0; + return -1; } return max; diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c index 3d5bbf6..362e0ff 100644 --- a/libevdev/libevdev.c +++ b/libevdev/libevdev.c @@ -611,7 +611,7 @@ int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code) { const unsigned long *mask; - unsigned int max; + int max; if (!libevdev_has_event_type(dev, type)) return 0; @@ -621,7 +621,7 @@ libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned max = type_to_mask_const(dev, type, &mask); - if (code > max) + if (max == -1 || code > max) return 0; return bit_is_set(mask, code); @@ -840,7 +840,7 @@ libevdev_kernel_enable_event_code(struct libevdev *dev, unsigned int type, unsig return rc; max = type_to_mask_const(dev, type, &mask); - if (code > max) + if (max == -1 || code > max) return -EINVAL; switch(type) {