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.
This commit is contained in:
Peter Hutterer 2013-06-05 11:22:35 +10:00
parent 645d5d3a64
commit dc27c627a7
2 changed files with 9 additions and 9 deletions

View file

@ -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;

View file

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