2 * Event char devices, giving access to raw input device events.
4 * Copyright (c) 1999-2002 Vojtech Pavlik
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #define EVDEV_MINOR_BASE 64
14 #define EVDEV_MINORS 32
15 #define EVDEV_MIN_BUFFER_SIZE 64U
16 #define EVDEV_BUF_PACKETS 8
18 #include <linux/poll.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/vmalloc.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/input/mt.h>
26 #include <linux/major.h>
27 #include <linux/device.h>
28 #include <linux/cdev.h>
29 #include <linux/wakelock.h>
30 #include "input-compat.h"
34 struct input_handle handle;
35 wait_queue_head_t wait;
36 struct evdev_client __rcu *grab;
37 struct list_head client_list;
38 spinlock_t client_lock; /* protects client_list */
48 unsigned int packet_head; /* [future] position of the first element of next packet */
49 spinlock_t buffer_lock; /* protects access to buffer, head and tail */
50 struct wake_lock wake_lock;
53 struct fasync_struct *fasync;
55 struct list_head node;
58 struct input_event buffer[];
61 static void __pass_event(struct evdev_client *client,
62 const struct input_event *event)
64 client->buffer[client->head++] = *event;
65 client->head &= client->bufsize - 1;
67 if (unlikely(client->head == client->tail)) {
69 * This effectively "drops" all unconsumed events, leaving
70 * EV_SYN/SYN_DROPPED plus the newest event in the queue.
72 client->tail = (client->head - 2) & (client->bufsize - 1);
74 client->buffer[client->tail].time = event->time;
75 client->buffer[client->tail].type = EV_SYN;
76 client->buffer[client->tail].code = SYN_DROPPED;
77 client->buffer[client->tail].value = 0;
79 client->packet_head = client->tail;
80 if (client->use_wake_lock)
81 wake_unlock(&client->wake_lock);
84 if (event->type == EV_SYN && event->code == SYN_REPORT) {
85 client->packet_head = client->head;
86 if (client->use_wake_lock)
87 wake_lock(&client->wake_lock);
88 kill_fasync(&client->fasync, SIGIO, POLL_IN);
92 static void evdev_pass_values(struct evdev_client *client,
93 const struct input_value *vals, unsigned int count,
94 ktime_t mono, ktime_t real)
96 struct evdev *evdev = client->evdev;
97 const struct input_value *v;
98 struct input_event event;
101 event.time = ktime_to_timeval(client->clkid == CLOCK_MONOTONIC ?
104 /* Interrupts are disabled, just acquire the lock. */
105 spin_lock(&client->buffer_lock);
107 for (v = vals; v != vals + count; v++) {
108 event.type = v->type;
109 event.code = v->code;
110 event.value = v->value;
111 __pass_event(client, &event);
112 if (v->type == EV_SYN && v->code == SYN_REPORT)
116 spin_unlock(&client->buffer_lock);
119 wake_up_interruptible(&evdev->wait);
123 * Pass incoming events to all connected clients.
125 static void evdev_events(struct input_handle *handle,
126 const struct input_value *vals, unsigned int count)
128 struct evdev *evdev = handle->private;
129 struct evdev_client *client;
130 ktime_t time_mono, time_real;
132 time_mono = ktime_get();
133 time_real = ktime_sub(time_mono, ktime_get_monotonic_offset());
137 client = rcu_dereference(evdev->grab);
140 evdev_pass_values(client, vals, count, time_mono, time_real);
142 list_for_each_entry_rcu(client, &evdev->client_list, node)
143 evdev_pass_values(client, vals, count,
144 time_mono, time_real);
150 * Pass incoming event to all connected clients.
152 static void evdev_event(struct input_handle *handle,
153 unsigned int type, unsigned int code, int value)
155 struct input_value vals[] = { { type, code, value } };
157 evdev_events(handle, vals, 1);
160 static int evdev_fasync(int fd, struct file *file, int on)
162 struct evdev_client *client = file->private_data;
164 return fasync_helper(fd, file, on, &client->fasync);
167 static int evdev_flush(struct file *file, fl_owner_t id)
169 struct evdev_client *client = file->private_data;
170 struct evdev *evdev = client->evdev;
173 retval = mutex_lock_interruptible(&evdev->mutex);
180 retval = input_flush_device(&evdev->handle, file);
182 mutex_unlock(&evdev->mutex);
186 static void evdev_free(struct device *dev)
188 struct evdev *evdev = container_of(dev, struct evdev, dev);
190 input_put_device(evdev->handle.dev);
195 * Grabs an event device (along with underlying input device).
196 * This function is called with evdev->mutex taken.
198 static int evdev_grab(struct evdev *evdev, struct evdev_client *client)
205 error = input_grab_device(&evdev->handle);
209 rcu_assign_pointer(evdev->grab, client);
214 static int evdev_ungrab(struct evdev *evdev, struct evdev_client *client)
216 struct evdev_client *grab = rcu_dereference_protected(evdev->grab,
217 lockdep_is_held(&evdev->mutex));
222 rcu_assign_pointer(evdev->grab, NULL);
224 input_release_device(&evdev->handle);
229 static void evdev_attach_client(struct evdev *evdev,
230 struct evdev_client *client)
232 spin_lock(&evdev->client_lock);
233 list_add_tail_rcu(&client->node, &evdev->client_list);
234 spin_unlock(&evdev->client_lock);
237 static void evdev_detach_client(struct evdev *evdev,
238 struct evdev_client *client)
240 spin_lock(&evdev->client_lock);
241 list_del_rcu(&client->node);
242 spin_unlock(&evdev->client_lock);
246 static int evdev_open_device(struct evdev *evdev)
250 retval = mutex_lock_interruptible(&evdev->mutex);
256 else if (!evdev->open++) {
257 retval = input_open_device(&evdev->handle);
262 mutex_unlock(&evdev->mutex);
266 static void evdev_close_device(struct evdev *evdev)
268 mutex_lock(&evdev->mutex);
270 if (evdev->exist && !--evdev->open)
271 input_close_device(&evdev->handle);
273 mutex_unlock(&evdev->mutex);
277 * Wake up users waiting for IO so they can disconnect from
280 static void evdev_hangup(struct evdev *evdev)
282 struct evdev_client *client;
284 spin_lock(&evdev->client_lock);
285 list_for_each_entry(client, &evdev->client_list, node)
286 kill_fasync(&client->fasync, SIGIO, POLL_HUP);
287 spin_unlock(&evdev->client_lock);
289 wake_up_interruptible(&evdev->wait);
292 static int evdev_release(struct inode *inode, struct file *file)
294 struct evdev_client *client = file->private_data;
295 struct evdev *evdev = client->evdev;
297 mutex_lock(&evdev->mutex);
298 evdev_ungrab(evdev, client);
299 mutex_unlock(&evdev->mutex);
301 evdev_detach_client(evdev, client);
302 if (client->use_wake_lock)
303 wake_lock_destroy(&client->wake_lock);
305 if (is_vmalloc_addr(client))
310 evdev_close_device(evdev);
315 static unsigned int evdev_compute_buffer_size(struct input_dev *dev)
317 unsigned int n_events =
318 max(dev->hint_events_per_packet * EVDEV_BUF_PACKETS,
319 EVDEV_MIN_BUFFER_SIZE);
321 return roundup_pow_of_two(n_events);
324 static int evdev_open(struct inode *inode, struct file *file)
326 struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev);
327 unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
328 unsigned int size = sizeof(struct evdev_client) +
329 bufsize * sizeof(struct input_event);
330 struct evdev_client *client;
333 client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
335 client = vzalloc(size);
339 client->bufsize = bufsize;
340 spin_lock_init(&client->buffer_lock);
341 snprintf(client->name, sizeof(client->name), "%s-%d",
342 dev_name(&evdev->dev), task_tgid_vnr(current));
343 client->evdev = evdev;
344 evdev_attach_client(evdev, client);
346 error = evdev_open_device(evdev);
348 goto err_free_client;
350 file->private_data = client;
351 nonseekable_open(inode, file);
356 evdev_detach_client(evdev, client);
361 static ssize_t evdev_write(struct file *file, const char __user *buffer,
362 size_t count, loff_t *ppos)
364 struct evdev_client *client = file->private_data;
365 struct evdev *evdev = client->evdev;
366 struct input_event event;
369 if (count != 0 && count < input_event_size())
372 retval = mutex_lock_interruptible(&evdev->mutex);
381 while (retval + input_event_size() <= count) {
383 if (input_event_from_user(buffer + retval, &event)) {
387 retval += input_event_size();
389 input_inject_event(&evdev->handle,
390 event.type, event.code, event.value);
394 mutex_unlock(&evdev->mutex);
398 static int evdev_fetch_next_event(struct evdev_client *client,
399 struct input_event *event)
403 spin_lock_irq(&client->buffer_lock);
405 have_event = client->packet_head != client->tail;
407 *event = client->buffer[client->tail++];
408 client->tail &= client->bufsize - 1;
409 if (client->use_wake_lock &&
410 client->packet_head == client->tail)
411 wake_unlock(&client->wake_lock);
414 spin_unlock_irq(&client->buffer_lock);
419 static ssize_t evdev_read(struct file *file, char __user *buffer,
420 size_t count, loff_t *ppos)
422 struct evdev_client *client = file->private_data;
423 struct evdev *evdev = client->evdev;
424 struct input_event event;
428 if (count != 0 && count < input_event_size())
435 if (client->packet_head == client->tail &&
436 (file->f_flags & O_NONBLOCK))
440 * count == 0 is special - no IO is done but we check
441 * for error conditions (see above).
446 while (read + input_event_size() <= count &&
447 evdev_fetch_next_event(client, &event)) {
449 if (input_event_to_user(buffer + read, &event))
452 read += input_event_size();
458 if (!(file->f_flags & O_NONBLOCK)) {
459 error = wait_event_interruptible(evdev->wait,
460 client->packet_head != client->tail ||
470 /* No kernel lock - fine */
471 static unsigned int evdev_poll(struct file *file, poll_table *wait)
473 struct evdev_client *client = file->private_data;
474 struct evdev *evdev = client->evdev;
477 poll_wait(file, &evdev->wait, wait);
479 mask = evdev->exist ? POLLOUT | POLLWRNORM : POLLHUP | POLLERR;
480 if (client->packet_head != client->tail)
481 mask |= POLLIN | POLLRDNORM;
488 #define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8)
489 #define BITS_TO_LONGS_COMPAT(x) ((((x) - 1) / BITS_PER_LONG_COMPAT) + 1)
492 static int bits_to_user(unsigned long *bits, unsigned int maxbit,
493 unsigned int maxlen, void __user *p, int compat)
498 len = BITS_TO_LONGS_COMPAT(maxbit) * sizeof(compat_long_t);
502 for (i = 0; i < len / sizeof(compat_long_t); i++)
503 if (copy_to_user((compat_long_t __user *) p + i,
504 (compat_long_t *) bits +
505 i + 1 - ((i % 2) << 1),
506 sizeof(compat_long_t)))
509 len = BITS_TO_LONGS(maxbit) * sizeof(long);
513 if (copy_to_user(p, bits, len))
520 static int bits_to_user(unsigned long *bits, unsigned int maxbit,
521 unsigned int maxlen, void __user *p, int compat)
524 BITS_TO_LONGS_COMPAT(maxbit) * sizeof(compat_long_t) :
525 BITS_TO_LONGS(maxbit) * sizeof(long);
530 return copy_to_user(p, bits, len) ? -EFAULT : len;
532 #endif /* __BIG_ENDIAN */
536 static int bits_to_user(unsigned long *bits, unsigned int maxbit,
537 unsigned int maxlen, void __user *p, int compat)
539 int len = BITS_TO_LONGS(maxbit) * sizeof(long);
544 return copy_to_user(p, bits, len) ? -EFAULT : len;
547 #endif /* CONFIG_COMPAT */
549 static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
556 len = strlen(str) + 1;
560 return copy_to_user(p, str, len) ? -EFAULT : len;
563 #define OLD_KEY_MAX 0x1ff
564 static int handle_eviocgbit(struct input_dev *dev,
565 unsigned int type, unsigned int size,
566 void __user *p, int compat_mode)
568 static unsigned long keymax_warn_time;
574 case 0: bits = dev->evbit; len = EV_MAX; break;
575 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
576 case EV_REL: bits = dev->relbit; len = REL_MAX; break;
577 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
578 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
579 case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
580 case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
581 case EV_FF: bits = dev->ffbit; len = FF_MAX; break;
582 case EV_SW: bits = dev->swbit; len = SW_MAX; break;
583 default: return -EINVAL;
587 * Work around bugs in userspace programs that like to do
588 * EVIOCGBIT(EV_KEY, KEY_MAX) and not realize that 'len'
589 * should be in bytes, not in bits.
591 if (type == EV_KEY && size == OLD_KEY_MAX) {
593 if (printk_timed_ratelimit(&keymax_warn_time, 10 * 1000))
594 pr_warning("(EVIOCGBIT): Suspicious buffer size %u, "
595 "limiting output to %zu bytes. See "
596 "http://userweb.kernel.org/~dtor/eviocgbit-bug.html\n",
598 BITS_TO_LONGS(OLD_KEY_MAX) * sizeof(long));
601 return bits_to_user(bits, len, size, p, compat_mode);
605 static int evdev_handle_get_keycode(struct input_dev *dev, void __user *p)
607 struct input_keymap_entry ke = {
608 .len = sizeof(unsigned int),
611 int __user *ip = (int __user *)p;
615 if (copy_from_user(ke.scancode, p, sizeof(unsigned int)))
618 error = input_get_keycode(dev, &ke);
622 if (put_user(ke.keycode, ip + 1))
628 static int evdev_handle_get_keycode_v2(struct input_dev *dev, void __user *p)
630 struct input_keymap_entry ke;
633 if (copy_from_user(&ke, p, sizeof(ke)))
636 error = input_get_keycode(dev, &ke);
640 if (copy_to_user(p, &ke, sizeof(ke)))
646 static int evdev_handle_set_keycode(struct input_dev *dev, void __user *p)
648 struct input_keymap_entry ke = {
649 .len = sizeof(unsigned int),
652 int __user *ip = (int __user *)p;
654 if (copy_from_user(ke.scancode, p, sizeof(unsigned int)))
657 if (get_user(ke.keycode, ip + 1))
660 return input_set_keycode(dev, &ke);
663 static int evdev_handle_set_keycode_v2(struct input_dev *dev, void __user *p)
665 struct input_keymap_entry ke;
667 if (copy_from_user(&ke, p, sizeof(ke)))
670 if (ke.len > sizeof(ke.scancode))
673 return input_set_keycode(dev, &ke);
676 static int evdev_handle_mt_request(struct input_dev *dev,
680 const struct input_mt *mt = dev->mt;
685 if (get_user(code, &ip[0]))
687 if (!mt || !input_is_mt_value(code))
690 max_slots = (size - sizeof(__u32)) / sizeof(__s32);
691 for (i = 0; i < mt->num_slots && i < max_slots; i++) {
692 int value = input_mt_get_value(&mt->slots[i], code);
693 if (put_user(value, &ip[1 + i]))
700 static int evdev_enable_suspend_block(struct evdev *evdev,
701 struct evdev_client *client)
703 if (client->use_wake_lock)
706 spin_lock_irq(&client->buffer_lock);
707 wake_lock_init(&client->wake_lock, WAKE_LOCK_SUSPEND, client->name);
708 client->use_wake_lock = true;
709 if (client->packet_head != client->tail)
710 wake_lock(&client->wake_lock);
711 spin_unlock_irq(&client->buffer_lock);
715 static int evdev_disable_suspend_block(struct evdev *evdev,
716 struct evdev_client *client)
718 if (!client->use_wake_lock)
721 spin_lock_irq(&client->buffer_lock);
722 client->use_wake_lock = false;
723 wake_lock_destroy(&client->wake_lock);
724 spin_unlock_irq(&client->buffer_lock);
729 static long evdev_do_ioctl(struct file *file, unsigned int cmd,
730 void __user *p, int compat_mode)
732 struct evdev_client *client = file->private_data;
733 struct evdev *evdev = client->evdev;
734 struct input_dev *dev = evdev->handle.dev;
735 struct input_absinfo abs;
736 struct ff_effect effect;
737 int __user *ip = (int __user *)p;
738 unsigned int i, t, u, v;
742 /* First we check for fixed-length commands */
746 return put_user(EV_VERSION, ip);
749 if (copy_to_user(p, &dev->id, sizeof(struct input_id)))
754 if (!test_bit(EV_REP, dev->evbit))
756 if (put_user(dev->rep[REP_DELAY], ip))
758 if (put_user(dev->rep[REP_PERIOD], ip + 1))
763 if (!test_bit(EV_REP, dev->evbit))
767 if (get_user(v, ip + 1))
770 input_inject_event(&evdev->handle, EV_REP, REP_DELAY, u);
771 input_inject_event(&evdev->handle, EV_REP, REP_PERIOD, v);
776 return input_ff_erase(dev, (int)(unsigned long) p, file);
779 i = test_bit(EV_FF, dev->evbit) ?
780 dev->ff->max_effects : 0;
787 return evdev_grab(evdev, client);
789 return evdev_ungrab(evdev, client);
792 if (copy_from_user(&i, p, sizeof(unsigned int)))
794 if (i != CLOCK_MONOTONIC && i != CLOCK_REALTIME)
800 return evdev_handle_get_keycode(dev, p);
803 return evdev_handle_set_keycode(dev, p);
805 case EVIOCGKEYCODE_V2:
806 return evdev_handle_get_keycode_v2(dev, p);
808 case EVIOCSKEYCODE_V2:
809 return evdev_handle_set_keycode_v2(dev, p);
811 case EVIOCGSUSPENDBLOCK:
812 return put_user(client->use_wake_lock, ip);
814 case EVIOCSSUSPENDBLOCK:
816 return evdev_enable_suspend_block(evdev, client);
818 return evdev_disable_suspend_block(evdev, client);
821 size = _IOC_SIZE(cmd);
823 /* Now check variable-length commands */
824 #define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
825 switch (EVIOC_MASK_SIZE(cmd)) {
828 return bits_to_user(dev->propbit, INPUT_PROP_MAX,
829 size, p, compat_mode);
831 case EVIOCGMTSLOTS(0):
832 return evdev_handle_mt_request(dev, size, ip);
835 return bits_to_user(dev->key, KEY_MAX, size, p, compat_mode);
838 return bits_to_user(dev->led, LED_MAX, size, p, compat_mode);
841 return bits_to_user(dev->snd, SND_MAX, size, p, compat_mode);
844 return bits_to_user(dev->sw, SW_MAX, size, p, compat_mode);
847 return str_to_user(dev->name, size, p);
850 return str_to_user(dev->phys, size, p);
853 return str_to_user(dev->uniq, size, p);
855 case EVIOC_MASK_SIZE(EVIOCSFF):
856 if (input_ff_effect_from_user(p, size, &effect))
859 error = input_ff_upload(dev, &effect, file);
861 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
867 /* Multi-number variable-length handlers */
868 if (_IOC_TYPE(cmd) != 'E')
871 if (_IOC_DIR(cmd) == _IOC_READ) {
873 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
874 return handle_eviocgbit(dev,
875 _IOC_NR(cmd) & EV_MAX, size,
878 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
883 t = _IOC_NR(cmd) & ABS_MAX;
884 abs = dev->absinfo[t];
886 if (copy_to_user(p, &abs, min_t(size_t,
887 size, sizeof(struct input_absinfo))))
894 if (_IOC_DIR(cmd) == _IOC_WRITE) {
896 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
901 t = _IOC_NR(cmd) & ABS_MAX;
903 if (copy_from_user(&abs, p, min_t(size_t,
904 size, sizeof(struct input_absinfo))))
907 if (size < sizeof(struct input_absinfo))
910 /* We can't change number of reserved MT slots */
911 if (t == ABS_MT_SLOT)
915 * Take event lock to ensure that we are not
916 * changing device parameters in the middle
919 spin_lock_irq(&dev->event_lock);
920 dev->absinfo[t] = abs;
921 spin_unlock_irq(&dev->event_lock);
930 static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
931 void __user *p, int compat_mode)
933 struct evdev_client *client = file->private_data;
934 struct evdev *evdev = client->evdev;
937 retval = mutex_lock_interruptible(&evdev->mutex);
946 retval = evdev_do_ioctl(file, cmd, p, compat_mode);
949 mutex_unlock(&evdev->mutex);
953 static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
955 return evdev_ioctl_handler(file, cmd, (void __user *)arg, 0);
959 static long evdev_ioctl_compat(struct file *file,
960 unsigned int cmd, unsigned long arg)
962 return evdev_ioctl_handler(file, cmd, compat_ptr(arg), 1);
966 static const struct file_operations evdev_fops = {
967 .owner = THIS_MODULE,
969 .write = evdev_write,
972 .release = evdev_release,
973 .unlocked_ioctl = evdev_ioctl,
975 .compat_ioctl = evdev_ioctl_compat,
977 .fasync = evdev_fasync,
978 .flush = evdev_flush,
983 * Mark device non-existent. This disables writes, ioctls and
984 * prevents new users from opening the device. Already posted
985 * blocking reads will stay, however new ones will fail.
987 static void evdev_mark_dead(struct evdev *evdev)
989 mutex_lock(&evdev->mutex);
990 evdev->exist = false;
991 mutex_unlock(&evdev->mutex);
994 static void evdev_cleanup(struct evdev *evdev)
996 struct input_handle *handle = &evdev->handle;
998 evdev_mark_dead(evdev);
1001 cdev_del(&evdev->cdev);
1003 /* evdev is marked dead so no one else accesses evdev->open */
1005 input_flush_device(handle, NULL);
1006 input_close_device(handle);
1011 * Create new evdev device. Note that input core serializes calls
1012 * to connect and disconnect.
1014 static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
1015 const struct input_device_id *id)
1017 struct evdev *evdev;
1022 minor = input_get_new_minor(EVDEV_MINOR_BASE, EVDEV_MINORS, true);
1025 pr_err("failed to reserve new minor: %d\n", error);
1029 evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL);
1032 goto err_free_minor;
1035 INIT_LIST_HEAD(&evdev->client_list);
1036 spin_lock_init(&evdev->client_lock);
1037 mutex_init(&evdev->mutex);
1038 init_waitqueue_head(&evdev->wait);
1039 evdev->exist = true;
1042 /* Normalize device number if it falls into legacy range */
1043 if (dev_no < EVDEV_MINOR_BASE + EVDEV_MINORS)
1044 dev_no -= EVDEV_MINOR_BASE;
1045 dev_set_name(&evdev->dev, "event%d", dev_no);
1047 evdev->handle.dev = input_get_device(dev);
1048 evdev->handle.name = dev_name(&evdev->dev);
1049 evdev->handle.handler = handler;
1050 evdev->handle.private = evdev;
1052 evdev->dev.devt = MKDEV(INPUT_MAJOR, minor);
1053 evdev->dev.class = &input_class;
1054 evdev->dev.parent = &dev->dev;
1055 evdev->dev.release = evdev_free;
1056 device_initialize(&evdev->dev);
1058 error = input_register_handle(&evdev->handle);
1060 goto err_free_evdev;
1062 cdev_init(&evdev->cdev, &evdev_fops);
1063 evdev->cdev.kobj.parent = &evdev->dev.kobj;
1064 error = cdev_add(&evdev->cdev, evdev->dev.devt, 1);
1066 goto err_unregister_handle;
1068 error = device_add(&evdev->dev);
1070 goto err_cleanup_evdev;
1075 evdev_cleanup(evdev);
1076 err_unregister_handle:
1077 input_unregister_handle(&evdev->handle);
1079 put_device(&evdev->dev);
1081 input_free_minor(minor);
1085 static void evdev_disconnect(struct input_handle *handle)
1087 struct evdev *evdev = handle->private;
1089 device_del(&evdev->dev);
1090 evdev_cleanup(evdev);
1091 input_free_minor(MINOR(evdev->dev.devt));
1092 input_unregister_handle(handle);
1093 put_device(&evdev->dev);
1096 static const struct input_device_id evdev_ids[] = {
1097 { .driver_info = 1 }, /* Matches all devices */
1098 { }, /* Terminating zero entry */
1101 MODULE_DEVICE_TABLE(input, evdev_ids);
1103 static struct input_handler evdev_handler = {
1104 .event = evdev_event,
1105 .events = evdev_events,
1106 .connect = evdev_connect,
1107 .disconnect = evdev_disconnect,
1108 .legacy_minors = true,
1109 .minor = EVDEV_MINOR_BASE,
1111 .id_table = evdev_ids,
1114 static int __init evdev_init(void)
1116 return input_register_handler(&evdev_handler);
1119 static void __exit evdev_exit(void)
1121 input_unregister_handler(&evdev_handler);
1124 module_init(evdev_init);
1125 module_exit(evdev_exit);
1127 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
1128 MODULE_DESCRIPTION("Input driver event char devices");
1129 MODULE_LICENSE("GPL");