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) {