Skip to content

Commit a184cf9

Browse files
committed
Input: make sure input handlers define only one processing method
Input core expects input handlers to be either filters, or regular handlers, but not both. Additionally, for regular handlers it does not make sense to define both single event method and batch method. Refuse registering handler if it defines more than one method. Reviewed-by: Jeff LaBundy <jeff@labundy.com> Reviewed-by: Benjamin Tissoires <bentiss@kernel.org> Link: https://lore.kernel.org/r/20240703213756.3375978-3-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent b3d6510 commit a184cf9

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

drivers/input/input.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,26 @@ void input_unregister_device(struct input_dev *dev)
25172517
}
25182518
EXPORT_SYMBOL(input_unregister_device);
25192519

2520+
static int input_handler_check_methods(const struct input_handler *handler)
2521+
{
2522+
int count = 0;
2523+
2524+
if (handler->filter)
2525+
count++;
2526+
if (handler->events)
2527+
count++;
2528+
if (handler->event)
2529+
count++;
2530+
2531+
if (count > 1) {
2532+
pr_err("%s: only one event processing method can be defined (%s)\n",
2533+
__func__, handler->name);
2534+
return -EINVAL;
2535+
}
2536+
2537+
return 0;
2538+
}
2539+
25202540
/**
25212541
* input_register_handler - register a new input handler
25222542
* @handler: handler to be registered
@@ -2530,6 +2550,10 @@ int input_register_handler(struct input_handler *handler)
25302550
struct input_dev *dev;
25312551
int error;
25322552

2553+
error = input_handler_check_methods(handler);
2554+
if (error)
2555+
return error;
2556+
25332557
error = mutex_lock_interruptible(&input_mutex);
25342558
if (error)
25352559
return error;

0 commit comments

Comments
 (0)