summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2024-07-03 14:37:49 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2024-07-08 16:22:48 -0700
commita184cf98b1d4397fe7eca881da596059fea36a18 (patch)
tree4b4ac72dfdcba3dd697ee23bc36b4cfb105e886d /drivers/input
parentb3d65108ac8abd79e0367d77598d539b117044a3 (diff)
downloadlwn-a184cf98b1d4397fe7eca881da596059fea36a18.tar.gz
lwn-a184cf98b1d4397fe7eca881da596059fea36a18.zip
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>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/input.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index fd4997ba263c..7e4f8824f4fd 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -2517,6 +2517,26 @@ void input_unregister_device(struct input_dev *dev)
}
EXPORT_SYMBOL(input_unregister_device);
+static int input_handler_check_methods(const struct input_handler *handler)
+{
+ int count = 0;
+
+ if (handler->filter)
+ count++;
+ if (handler->events)
+ count++;
+ if (handler->event)
+ count++;
+
+ if (count > 1) {
+ pr_err("%s: only one event processing method can be defined (%s)\n",
+ __func__, handler->name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/**
* input_register_handler - register a new input handler
* @handler: handler to be registered
@@ -2530,6 +2550,10 @@ int input_register_handler(struct input_handler *handler)
struct input_dev *dev;
int error;
+ error = input_handler_check_methods(handler);
+ if (error)
+ return error;
+
error = mutex_lock_interruptible(&input_mutex);
if (error)
return error;