LIBEVDEV_EXPORT int
libevdev_enable_event_type(struct libevdev *dev, unsigned int type)
{
+ int max;
+
if (type > EV_MAX)
return -1;
if (libevdev_has_event_type(dev, type))
return 0;
+ max = libevdev_event_type_get_max(type);
+ if (max == -1)
+ return -1;
+
set_bit(dev->bits, type);
if (type == EV_REP) {
LIBEVDEV_EXPORT int
libevdev_disable_event_type(struct libevdev *dev, unsigned int type)
{
+ int max;
+
if (type > EV_MAX || type == EV_SYN)
return -1;
+ max = libevdev_event_type_get_max(type);
+ if (max == -1)
+ return -1;
+
clear_bit(dev->bits, type);
return 0;
max = type_to_mask(dev, type, &mask);
- if (code > max)
+ if (code > max || (int)max == -1)
return -1;
set_bit(mask, code);
max = type_to_mask(dev, type, &mask);
- if (code > max)
+ if (code > max || (int)max == -1)
return -1;
clear_bit(mask, code);
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_ABS, ABS_MAX + 1, &abs), -1);
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_MAX + 1, ABS_MAX + 1, &abs), -1);
ck_assert_int_eq(libevdev_enable_event_type(dev, EV_MAX + 1), -1);
+ /* there's a gap between EV_SW and EV_LED */
+ ck_assert_int_eq(libevdev_enable_event_type(dev, EV_LED - 1), -1);
+ ck_assert_int_eq(libevdev_enable_event_code(dev, EV_LED - 1, 0, NULL), -1);
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_ABS, ABS_Y, NULL), -1);
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_REP, REP_DELAY, NULL), -1);
rc = test_create_abs_device(&uidev, &dev, 1, &abs, -1);
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
+ /* there's a gap between EV_SW and EV_LED */
+ ck_assert_int_eq(libevdev_disable_event_type(dev, EV_LED - 1), -1);
+ ck_assert_int_eq(libevdev_disable_event_code(dev, EV_LED - 1, 0), -1);
ck_assert_int_eq(libevdev_disable_event_code(dev, EV_ABS, ABS_MAX + 1), -1);
ck_assert_int_eq(libevdev_disable_event_code(dev, EV_MAX + 1, ABS_MAX + 1), -1);
ck_assert_int_eq(libevdev_disable_event_type(dev, EV_MAX + 1), -1);