hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/input/input.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * The input core
34 *
45 * Copyright (c) 1999-2002 Vojtech Pavlik
56 */
67
7
-/*
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms of the GNU General Public License version 2 as published by
10
- * the Free Software Foundation.
11
- */
128
139 #define pr_fmt(fmt) KBUILD_BASENAME ": " fmt
1410
....@@ -28,6 +24,7 @@
2824 #include <linux/mutex.h>
2925 #include <linux/rcupdate.h>
3026 #include "input-compat.h"
27
+#include "input-poller.h"
3128
3229 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
3330 MODULE_DESCRIPTION("Input core");
....@@ -49,6 +46,17 @@
4946 static DEFINE_MUTEX(input_mutex);
5047
5148 static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
49
+
50
+static const unsigned int input_max_code[EV_CNT] = {
51
+ [EV_KEY] = KEY_MAX,
52
+ [EV_REL] = REL_MAX,
53
+ [EV_ABS] = ABS_MAX,
54
+ [EV_MSC] = MSC_MAX,
55
+ [EV_SW] = SW_MAX,
56
+ [EV_LED] = LED_MAX,
57
+ [EV_SND] = SND_MAX,
58
+ [EV_FF] = FF_MAX,
59
+};
5260
5361 static inline int is_event_supported(unsigned int code,
5462 unsigned long *bm, unsigned int max)
....@@ -615,19 +623,30 @@
615623
616624 handle->open++;
617625
618
- if (!dev->users++ && dev->open)
619
- retval = dev->open(dev);
626
+ if (dev->users++) {
627
+ /*
628
+ * Device is already opened, so we can exit immediately and
629
+ * report success.
630
+ */
631
+ goto out;
632
+ }
620633
621
- if (retval) {
622
- dev->users--;
623
- if (!--handle->open) {
634
+ if (dev->open) {
635
+ retval = dev->open(dev);
636
+ if (retval) {
637
+ dev->users--;
638
+ handle->open--;
624639 /*
625640 * Make sure we are not delivering any more events
626641 * through this handle
627642 */
628643 synchronize_rcu();
644
+ goto out;
629645 }
630646 }
647
+
648
+ if (dev->poller)
649
+ input_dev_poller_start(dev->poller);
631650
632651 out:
633652 mutex_unlock(&dev->mutex);
....@@ -667,8 +686,13 @@
667686
668687 __input_release_device(handle);
669688
670
- if (!--dev->users && dev->close)
671
- dev->close(dev);
689
+ if (!--dev->users) {
690
+ if (dev->poller)
691
+ input_dev_poller_stop(dev->poller);
692
+
693
+ if (dev->close)
694
+ dev->close(dev);
695
+ }
672696
673697 if (!--handle->open) {
674698 /*
....@@ -1204,13 +1228,12 @@
12041228 return seq_open(file, &input_devices_seq_ops);
12051229 }
12061230
1207
-static const struct file_operations input_devices_fileops = {
1208
- .owner = THIS_MODULE,
1209
- .open = input_proc_devices_open,
1210
- .poll = input_proc_devices_poll,
1211
- .read = seq_read,
1212
- .llseek = seq_lseek,
1213
- .release = seq_release,
1231
+static const struct proc_ops input_devices_proc_ops = {
1232
+ .proc_open = input_proc_devices_open,
1233
+ .proc_poll = input_proc_devices_poll,
1234
+ .proc_read = seq_read,
1235
+ .proc_lseek = seq_lseek,
1236
+ .proc_release = seq_release,
12141237 };
12151238
12161239 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
....@@ -1268,12 +1291,11 @@
12681291 return seq_open(file, &input_handlers_seq_ops);
12691292 }
12701293
1271
-static const struct file_operations input_handlers_fileops = {
1272
- .owner = THIS_MODULE,
1273
- .open = input_proc_handlers_open,
1274
- .read = seq_read,
1275
- .llseek = seq_lseek,
1276
- .release = seq_release,
1294
+static const struct proc_ops input_handlers_proc_ops = {
1295
+ .proc_open = input_proc_handlers_open,
1296
+ .proc_read = seq_read,
1297
+ .proc_lseek = seq_lseek,
1298
+ .proc_release = seq_release,
12771299 };
12781300
12791301 static int __init input_proc_init(void)
....@@ -1285,12 +1307,12 @@
12851307 return -ENOMEM;
12861308
12871309 entry = proc_create("devices", 0, proc_bus_input_dir,
1288
- &input_devices_fileops);
1310
+ &input_devices_proc_ops);
12891311 if (!entry)
12901312 goto fail1;
12911313
12921314 entry = proc_create("handlers", 0, proc_bus_input_dir,
1293
- &input_handlers_fileops);
1315
+ &input_handlers_proc_ops);
12941316 if (!entry)
12951317 goto fail2;
12961318
....@@ -1520,6 +1542,7 @@
15201542 &input_dev_attr_group,
15211543 &input_dev_id_attr_group,
15221544 &input_dev_caps_attr_group,
1545
+ &input_poller_attribute_group,
15231546 NULL
15241547 };
15251548
....@@ -1529,6 +1552,7 @@
15291552
15301553 input_ff_destroy(dev);
15311554 input_mt_destroy_slots(dev);
1555
+ kfree(dev->poller);
15321556 kfree(dev->absinfo);
15331557 kfree(dev->vals);
15341558 kfree(dev);
....@@ -1963,6 +1987,14 @@
19631987 */
19641988 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code)
19651989 {
1990
+ if (type < EV_CNT && input_max_code[type] &&
1991
+ code > input_max_code[type]) {
1992
+ pr_err("%s: invalid code %u for type %u\n", __func__, code,
1993
+ type);
1994
+ dump_stack();
1995
+ return;
1996
+ }
1997
+
19661998 switch (type) {
19671999 case EV_KEY:
19682000 __set_bit(code, dev->keybit);
....@@ -2193,6 +2225,9 @@
21932225 if (!dev->setkeycode)
21942226 dev->setkeycode = input_default_setkeycode;
21952227
2228
+ if (dev->poller)
2229
+ input_dev_poller_finalize(dev->poller);
2230
+
21962231 error = device_add(&dev->dev);
21972232 if (error)
21982233 goto err_free_vals;