pad: don't assert when unable to find the mode group, just discard

Instead of a hard assert if we fail to find the mode group for the given
ring/dial/strip let's just log an error and discard the event.

I'm not sure this assert can be triggered in the current code base but
if it can an error message is going to be more useful to the user than
an assert.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1291>
This commit is contained in:
Peter Hutterer 2025-08-04 12:53:10 +10:00
parent 47d4c563f4
commit 2562c24f95
2 changed files with 46 additions and 29 deletions

View file

@ -307,7 +307,10 @@ pad_dial_get_mode_group(struct pad_dispatch *pad, unsigned int dial)
return group; return group;
} }
assert(!"Unable to find dial mode group"); evdev_log_bug_libinput_ratelimit(pad->device,
&pad->modes.group_not_found,
"Unable to find mode group for dial %d",
dial);
return NULL; return NULL;
} }
@ -322,7 +325,10 @@ pad_ring_get_mode_group(struct pad_dispatch *pad, unsigned int ring)
return group; return group;
} }
assert(!"Unable to find ring mode group"); evdev_log_bug_libinput_ratelimit(pad->device,
&pad->modes.group_not_found,
"Unable to find mode group for ring %d",
ring);
return NULL; return NULL;
} }
@ -337,7 +343,10 @@ pad_strip_get_mode_group(struct pad_dispatch *pad, unsigned int strip)
return group; return group;
} }
assert(!"Unable to find strip mode group"); evdev_log_bug_libinput_ratelimit(pad->device,
&pad->modes.group_not_found,
"Unable to find mode group for strip %d",
strip);
return NULL; return NULL;
} }
@ -362,11 +371,13 @@ pad_check_notify_axes(struct pad_dispatch *pad,
* so we can't set a source */ * so we can't set a source */
if (pad->changed_axes & PAD_AXIS_DIAL1) { if (pad->changed_axes & PAD_AXIS_DIAL1) {
group = pad_dial_get_mode_group(pad, 0); group = pad_dial_get_mode_group(pad, 0);
if (group)
tablet_pad_notify_dial(base, time, 0, pad->dials.dial1, group); tablet_pad_notify_dial(base, time, 0, pad->dials.dial1, group);
} }
if (pad->changed_axes & PAD_AXIS_DIAL2) { if (pad->changed_axes & PAD_AXIS_DIAL2) {
group = pad_dial_get_mode_group(pad, 1); group = pad_dial_get_mode_group(pad, 1);
if (group)
tablet_pad_notify_dial(base, time, 1, pad->dials.dial2, group); tablet_pad_notify_dial(base, time, 1, pad->dials.dial2, group);
} }
@ -376,6 +387,7 @@ pad_check_notify_axes(struct pad_dispatch *pad,
value = -1.0; value = -1.0;
group = pad_ring_get_mode_group(pad, 0); group = pad_ring_get_mode_group(pad, 0);
if (group)
tablet_pad_notify_ring(base, tablet_pad_notify_ring(base,
time, time,
0, 0,
@ -390,6 +402,7 @@ pad_check_notify_axes(struct pad_dispatch *pad,
value = -1.0; value = -1.0;
group = pad_ring_get_mode_group(pad, 1); group = pad_ring_get_mode_group(pad, 1);
if (group)
tablet_pad_notify_ring(base, tablet_pad_notify_ring(base,
time, time,
1, 1,
@ -404,6 +417,7 @@ pad_check_notify_axes(struct pad_dispatch *pad,
value = -1.0; value = -1.0;
group = pad_strip_get_mode_group(pad, 0); group = pad_strip_get_mode_group(pad, 0);
if (group)
tablet_pad_notify_strip(base, tablet_pad_notify_strip(base,
time, time,
0, 0,
@ -418,6 +432,7 @@ pad_check_notify_axes(struct pad_dispatch *pad,
value = -1.0; value = -1.0;
group = pad_strip_get_mode_group(pad, 1); group = pad_strip_get_mode_group(pad, 1);
if (group)
tablet_pad_notify_strip(base, tablet_pad_notify_strip(base,
time, time,
1, 1,
@ -804,6 +819,7 @@ pad_init(struct pad_dispatch *pad, struct evdev_device *device)
pad->device = device; pad->device = device;
pad->status = PAD_NONE; pad->status = PAD_NONE;
pad->changed_axes = PAD_AXIS_NONE; pad->changed_axes = PAD_AXIS_NONE;
ratelimit_init(&pad->modes.group_not_found, h2us(1), 3);
/* We expect the kernel to either give us both axes as hires or neither. /* We expect the kernel to either give us both axes as hires or neither.
* Getting one is a kernel bug we don't need to care about */ * Getting one is a kernel bug we don't need to care about */

View file

@ -87,6 +87,7 @@ struct pad_dispatch {
struct { struct {
struct list mode_group_list; struct list mode_group_list;
struct ratelimit group_not_found;
} modes; } modes;
struct ratelimit duplicate_abs_limit; struct ratelimit duplicate_abs_limit;