aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r--drivers/input/input.c270
1 files changed, 214 insertions, 56 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 2266ecbfbc01..9c79bd56b51a 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -14,6 +14,7 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/input.h> 15#include <linux/input.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/slab.h>
17#include <linux/random.h> 18#include <linux/random.h>
18#include <linux/major.h> 19#include <linux/major.h>
19#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
@@ -24,6 +25,7 @@
24#include <linux/mutex.h> 25#include <linux/mutex.h>
25#include <linux/rcupdate.h> 26#include <linux/rcupdate.h>
26#include <linux/smp_lock.h> 27#include <linux/smp_lock.h>
28#include "input-compat.h"
27 29
28MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 30MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
29MODULE_DESCRIPTION("Input core"); 31MODULE_DESCRIPTION("Input core");
@@ -45,6 +47,7 @@ static unsigned int input_abs_bypass_init_data[] __initdata = {
45 ABS_MT_TOOL_TYPE, 47 ABS_MT_TOOL_TYPE,
46 ABS_MT_BLOB_ID, 48 ABS_MT_BLOB_ID,
47 ABS_MT_TRACKING_ID, 49 ABS_MT_TRACKING_ID,
50 ABS_MT_PRESSURE,
48 0 51 0
49}; 52};
50static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)]; 53static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)];
@@ -85,12 +88,14 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
85} 88}
86 89
87/* 90/*
88 * Pass event through all open handles. This function is called with 91 * Pass event first through all filters and then, if event has not been
92 * filtered out, through all open handles. This function is called with
89 * dev->event_lock held and interrupts disabled. 93 * dev->event_lock held and interrupts disabled.
90 */ 94 */
91static void input_pass_event(struct input_dev *dev, 95static void input_pass_event(struct input_dev *dev,
92 unsigned int type, unsigned int code, int value) 96 unsigned int type, unsigned int code, int value)
93{ 97{
98 struct input_handler *handler;
94 struct input_handle *handle; 99 struct input_handle *handle;
95 100
96 rcu_read_lock(); 101 rcu_read_lock();
@@ -98,11 +103,25 @@ static void input_pass_event(struct input_dev *dev,
98 handle = rcu_dereference(dev->grab); 103 handle = rcu_dereference(dev->grab);
99 if (handle) 104 if (handle)
100 handle->handler->event(handle, type, code, value); 105 handle->handler->event(handle, type, code, value);
101 else 106 else {
102 list_for_each_entry_rcu(handle, &dev->h_list, d_node) 107 bool filtered = false;
103 if (handle->open) 108
104 handle->handler->event(handle, 109 list_for_each_entry_rcu(handle, &dev->h_list, d_node) {
105 type, code, value); 110 if (!handle->open)
111 continue;
112
113 handler = handle->handler;
114 if (!handler->filter) {
115 if (filtered)
116 break;
117
118 handler->event(handle, type, code, value);
119
120 } else if (handler->filter(handle, type, code, value))
121 filtered = true;
122 }
123 }
124
106 rcu_read_unlock(); 125 rcu_read_unlock();
107} 126}
108 127
@@ -296,9 +315,15 @@ static void input_handle_event(struct input_dev *dev,
296 * @value: value of the event 315 * @value: value of the event
297 * 316 *
298 * This function should be used by drivers implementing various input 317 * This function should be used by drivers implementing various input
299 * devices. See also input_inject_event(). 318 * devices to report input events. See also input_inject_event().
319 *
320 * NOTE: input_event() may be safely used right after input device was
321 * allocated with input_allocate_device(), even before it is registered
322 * with input_register_device(), but the event will not reach any of the
323 * input handlers. Such early invocation of input_event() may be used
324 * to 'seed' initial state of a switch or initial position of absolute
325 * axis, etc.
300 */ 326 */
301
302void input_event(struct input_dev *dev, 327void input_event(struct input_dev *dev,
303 unsigned int type, unsigned int code, int value) 328 unsigned int type, unsigned int code, int value)
304{ 329{
@@ -558,7 +583,8 @@ static int input_fetch_keycode(struct input_dev *dev, int scancode)
558} 583}
559 584
560static int input_default_getkeycode(struct input_dev *dev, 585static int input_default_getkeycode(struct input_dev *dev,
561 int scancode, int *keycode) 586 unsigned int scancode,
587 unsigned int *keycode)
562{ 588{
563 if (!dev->keycodesize) 589 if (!dev->keycodesize)
564 return -EINVAL; 590 return -EINVAL;
@@ -572,7 +598,8 @@ static int input_default_getkeycode(struct input_dev *dev,
572} 598}
573 599
574static int input_default_setkeycode(struct input_dev *dev, 600static int input_default_setkeycode(struct input_dev *dev,
575 int scancode, int keycode) 601 unsigned int scancode,
602 unsigned int keycode)
576{ 603{
577 int old_keycode; 604 int old_keycode;
578 int i; 605 int i;
@@ -607,12 +634,12 @@ static int input_default_setkeycode(struct input_dev *dev,
607 } 634 }
608 } 635 }
609 636
610 clear_bit(old_keycode, dev->keybit); 637 __clear_bit(old_keycode, dev->keybit);
611 set_bit(keycode, dev->keybit); 638 __set_bit(keycode, dev->keybit);
612 639
613 for (i = 0; i < dev->keycodemax; i++) { 640 for (i = 0; i < dev->keycodemax; i++) {
614 if (input_fetch_keycode(dev, i) == old_keycode) { 641 if (input_fetch_keycode(dev, i) == old_keycode) {
615 set_bit(old_keycode, dev->keybit); 642 __set_bit(old_keycode, dev->keybit);
616 break; /* Setting the bit twice is useless, so break */ 643 break; /* Setting the bit twice is useless, so break */
617 } 644 }
618 } 645 }
@@ -630,12 +657,17 @@ static int input_default_setkeycode(struct input_dev *dev,
630 * This function should be called by anyone interested in retrieving current 657 * This function should be called by anyone interested in retrieving current
631 * keymap. Presently keyboard and evdev handlers use it. 658 * keymap. Presently keyboard and evdev handlers use it.
632 */ 659 */
633int input_get_keycode(struct input_dev *dev, int scancode, int *keycode) 660int input_get_keycode(struct input_dev *dev,
661 unsigned int scancode, unsigned int *keycode)
634{ 662{
635 if (scancode < 0) 663 unsigned long flags;
636 return -EINVAL; 664 int retval;
665
666 spin_lock_irqsave(&dev->event_lock, flags);
667 retval = dev->getkeycode(dev, scancode, keycode);
668 spin_unlock_irqrestore(&dev->event_lock, flags);
637 669
638 return dev->getkeycode(dev, scancode, keycode); 670 return retval;
639} 671}
640EXPORT_SYMBOL(input_get_keycode); 672EXPORT_SYMBOL(input_get_keycode);
641 673
@@ -648,16 +680,14 @@ EXPORT_SYMBOL(input_get_keycode);
648 * This function should be called by anyone needing to update current 680 * This function should be called by anyone needing to update current
649 * keymap. Presently keyboard and evdev handlers use it. 681 * keymap. Presently keyboard and evdev handlers use it.
650 */ 682 */
651int input_set_keycode(struct input_dev *dev, int scancode, int keycode) 683int input_set_keycode(struct input_dev *dev,
684 unsigned int scancode, unsigned int keycode)
652{ 685{
653 unsigned long flags; 686 unsigned long flags;
654 int old_keycode; 687 int old_keycode;
655 int retval; 688 int retval;
656 689
657 if (scancode < 0) 690 if (keycode > KEY_MAX)
658 return -EINVAL;
659
660 if (keycode < 0 || keycode > KEY_MAX)
661 return -EINVAL; 691 return -EINVAL;
662 692
663 spin_lock_irqsave(&dev->event_lock, flags); 693 spin_lock_irqsave(&dev->event_lock, flags);
@@ -670,6 +700,9 @@ int input_set_keycode(struct input_dev *dev, int scancode, int keycode)
670 if (retval) 700 if (retval)
671 goto out; 701 goto out;
672 702
703 /* Make sure KEY_RESERVED did not get enabled. */
704 __clear_bit(KEY_RESERVED, dev->keybit);
705
673 /* 706 /*
674 * Simulate keyup event if keycode is not present 707 * Simulate keyup event if keycode is not present
675 * in the keymap anymore 708 * in the keymap anymore
@@ -697,12 +730,13 @@ EXPORT_SYMBOL(input_set_keycode);
697 if (i != BITS_TO_LONGS(max)) \ 730 if (i != BITS_TO_LONGS(max)) \
698 continue; 731 continue;
699 732
700static const struct input_device_id *input_match_device(const struct input_device_id *id, 733static const struct input_device_id *input_match_device(struct input_handler *handler,
701 struct input_dev *dev) 734 struct input_dev *dev)
702{ 735{
736 const struct input_device_id *id;
703 int i; 737 int i;
704 738
705 for (; id->flags || id->driver_info; id++) { 739 for (id = handler->id_table; id->flags || id->driver_info; id++) {
706 740
707 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) 741 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
708 if (id->bustype != dev->id.bustype) 742 if (id->bustype != dev->id.bustype)
@@ -730,7 +764,8 @@ static const struct input_device_id *input_match_device(const struct input_devic
730 MATCH_BIT(ffbit, FF_MAX); 764 MATCH_BIT(ffbit, FF_MAX);
731 MATCH_BIT(swbit, SW_MAX); 765 MATCH_BIT(swbit, SW_MAX);
732 766
733 return id; 767 if (!handler->match || handler->match(handler, dev))
768 return id;
734 } 769 }
735 770
736 return NULL; 771 return NULL;
@@ -741,10 +776,7 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han
741 const struct input_device_id *id; 776 const struct input_device_id *id;
742 int error; 777 int error;
743 778
744 if (handler->blacklist && input_match_device(handler->blacklist, dev)) 779 id = input_match_device(handler, dev);
745 return -ENODEV;
746
747 id = input_match_device(handler->id_table, dev);
748 if (!id) 780 if (!id)
749 return -ENODEV; 781 return -ENODEV;
750 782
@@ -758,6 +790,40 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han
758 return error; 790 return error;
759} 791}
760 792
793#ifdef CONFIG_COMPAT
794
795static int input_bits_to_string(char *buf, int buf_size,
796 unsigned long bits, bool skip_empty)
797{
798 int len = 0;
799
800 if (INPUT_COMPAT_TEST) {
801 u32 dword = bits >> 32;
802 if (dword || !skip_empty)
803 len += snprintf(buf, buf_size, "%x ", dword);
804
805 dword = bits & 0xffffffffUL;
806 if (dword || !skip_empty || len)
807 len += snprintf(buf + len, max(buf_size - len, 0),
808 "%x", dword);
809 } else {
810 if (bits || !skip_empty)
811 len += snprintf(buf, buf_size, "%lx", bits);
812 }
813
814 return len;
815}
816
817#else /* !CONFIG_COMPAT */
818
819static int input_bits_to_string(char *buf, int buf_size,
820 unsigned long bits, bool skip_empty)
821{
822 return bits || !skip_empty ?
823 snprintf(buf, buf_size, "%lx", bits) : 0;
824}
825
826#endif
761 827
762#ifdef CONFIG_PROC_FS 828#ifdef CONFIG_PROC_FS
763 829
@@ -826,14 +892,25 @@ static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
826 unsigned long *bitmap, int max) 892 unsigned long *bitmap, int max)
827{ 893{
828 int i; 894 int i;
829 895 bool skip_empty = true;
830 for (i = BITS_TO_LONGS(max) - 1; i > 0; i--) 896 char buf[18];
831 if (bitmap[i])
832 break;
833 897
834 seq_printf(seq, "B: %s=", name); 898 seq_printf(seq, "B: %s=", name);
835 for (; i >= 0; i--) 899
836 seq_printf(seq, "%lx%s", bitmap[i], i > 0 ? " " : ""); 900 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
901 if (input_bits_to_string(buf, sizeof(buf),
902 bitmap[i], skip_empty)) {
903 skip_empty = false;
904 seq_printf(seq, "%s%s", buf, i > 0 ? " " : "");
905 }
906 }
907
908 /*
909 * If no output was produced print a single 0.
910 */
911 if (skip_empty)
912 seq_puts(seq, "0");
913
837 seq_putc(seq, '\n'); 914 seq_putc(seq, '\n');
838} 915}
839 916
@@ -935,6 +1012,8 @@ static int input_handlers_seq_show(struct seq_file *seq, void *v)
935 union input_seq_state *state = (union input_seq_state *)&seq->private; 1012 union input_seq_state *state = (union input_seq_state *)&seq->private;
936 1013
937 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); 1014 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
1015 if (handler->filter)
1016 seq_puts(seq, " (filter)");
938 if (handler->fops) 1017 if (handler->fops)
939 seq_printf(seq, " Minor=%d", handler->minor); 1018 seq_printf(seq, " Minor=%d", handler->minor);
940 seq_putc(seq, '\n'); 1019 seq_putc(seq, '\n');
@@ -1122,14 +1201,23 @@ static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
1122{ 1201{
1123 int i; 1202 int i;
1124 int len = 0; 1203 int len = 0;
1204 bool skip_empty = true;
1205
1206 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
1207 len += input_bits_to_string(buf + len, max(buf_size - len, 0),
1208 bitmap[i], skip_empty);
1209 if (len) {
1210 skip_empty = false;
1211 if (i > 0)
1212 len += snprintf(buf + len, max(buf_size - len, 0), " ");
1213 }
1214 }
1125 1215
1126 for (i = BITS_TO_LONGS(max) - 1; i > 0; i--) 1216 /*
1127 if (bitmap[i]) 1217 * If no output was produced print a single 0.
1128 break; 1218 */
1129 1219 if (len == 0)
1130 for (; i >= 0; i--) 1220 len = snprintf(buf, buf_size, "%d", 0);
1131 len += snprintf(buf + len, max(buf_size - len, 0),
1132 "%lx%s", bitmap[i], i > 0 ? " " : "");
1133 1221
1134 if (add_cr) 1222 if (add_cr)
1135 len += snprintf(buf + len, max(buf_size - len, 0), "\n"); 1223 len += snprintf(buf + len, max(buf_size - len, 0), "\n");
@@ -1144,7 +1232,8 @@ static ssize_t input_dev_show_cap_##bm(struct device *dev, \
1144{ \ 1232{ \
1145 struct input_dev *input_dev = to_input_dev(dev); \ 1233 struct input_dev *input_dev = to_input_dev(dev); \
1146 int len = input_print_bitmap(buf, PAGE_SIZE, \ 1234 int len = input_print_bitmap(buf, PAGE_SIZE, \
1147 input_dev->bm##bit, ev##_MAX, 1); \ 1235 input_dev->bm##bit, ev##_MAX, \
1236 true); \
1148 return min_t(int, len, PAGE_SIZE); \ 1237 return min_t(int, len, PAGE_SIZE); \
1149} \ 1238} \
1150static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL) 1239static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL)
@@ -1208,7 +1297,7 @@ static int input_add_uevent_bm_var(struct kobj_uevent_env *env,
1208 1297
1209 len = input_print_bitmap(&env->buf[env->buflen - 1], 1298 len = input_print_bitmap(&env->buf[env->buflen - 1],
1210 sizeof(env->buf) - env->buflen, 1299 sizeof(env->buf) - env->buflen,
1211 bitmap, max, 0); 1300 bitmap, max, false);
1212 if (len >= (sizeof(env->buf) - env->buflen)) 1301 if (len >= (sizeof(env->buf) - env->buflen))
1213 return -ENOMEM; 1302 return -ENOMEM;
1214 1303
@@ -1488,6 +1577,25 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
1488} 1577}
1489EXPORT_SYMBOL(input_set_capability); 1578EXPORT_SYMBOL(input_set_capability);
1490 1579
1580#define INPUT_CLEANSE_BITMASK(dev, type, bits) \
1581 do { \
1582 if (!test_bit(EV_##type, dev->evbit)) \
1583 memset(dev->bits##bit, 0, \
1584 sizeof(dev->bits##bit)); \
1585 } while (0)
1586
1587static void input_cleanse_bitmasks(struct input_dev *dev)
1588{
1589 INPUT_CLEANSE_BITMASK(dev, KEY, key);
1590 INPUT_CLEANSE_BITMASK(dev, REL, rel);
1591 INPUT_CLEANSE_BITMASK(dev, ABS, abs);
1592 INPUT_CLEANSE_BITMASK(dev, MSC, msc);
1593 INPUT_CLEANSE_BITMASK(dev, LED, led);
1594 INPUT_CLEANSE_BITMASK(dev, SND, snd);
1595 INPUT_CLEANSE_BITMASK(dev, FF, ff);
1596 INPUT_CLEANSE_BITMASK(dev, SW, sw);
1597}
1598
1491/** 1599/**
1492 * input_register_device - register device with input core 1600 * input_register_device - register device with input core
1493 * @dev: device to be registered 1601 * @dev: device to be registered
@@ -1507,13 +1615,19 @@ int input_register_device(struct input_dev *dev)
1507 const char *path; 1615 const char *path;
1508 int error; 1616 int error;
1509 1617
1618 /* Every input device generates EV_SYN/SYN_REPORT events. */
1510 __set_bit(EV_SYN, dev->evbit); 1619 __set_bit(EV_SYN, dev->evbit);
1511 1620
1621 /* KEY_RESERVED is not supposed to be transmitted to userspace. */
1622 __clear_bit(KEY_RESERVED, dev->keybit);
1623
1624 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
1625 input_cleanse_bitmasks(dev);
1626
1512 /* 1627 /*
1513 * If delay and period are pre-set by the driver, then autorepeating 1628 * If delay and period are pre-set by the driver, then autorepeating
1514 * is handled by the driver itself and we don't do it in input.c. 1629 * is handled by the driver itself and we don't do it in input.c.
1515 */ 1630 */
1516
1517 init_timer(&dev->timer); 1631 init_timer(&dev->timer);
1518 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { 1632 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
1519 dev->timer.data = (long) dev; 1633 dev->timer.data = (long) dev;
@@ -1658,6 +1772,38 @@ void input_unregister_handler(struct input_handler *handler)
1658EXPORT_SYMBOL(input_unregister_handler); 1772EXPORT_SYMBOL(input_unregister_handler);
1659 1773
1660/** 1774/**
1775 * input_handler_for_each_handle - handle iterator
1776 * @handler: input handler to iterate
1777 * @data: data for the callback
1778 * @fn: function to be called for each handle
1779 *
1780 * Iterate over @bus's list of devices, and call @fn for each, passing
1781 * it @data and stop when @fn returns a non-zero value. The function is
1782 * using RCU to traverse the list and therefore may be usind in atonic
1783 * contexts. The @fn callback is invoked from RCU critical section and
1784 * thus must not sleep.
1785 */
1786int input_handler_for_each_handle(struct input_handler *handler, void *data,
1787 int (*fn)(struct input_handle *, void *))
1788{
1789 struct input_handle *handle;
1790 int retval = 0;
1791
1792 rcu_read_lock();
1793
1794 list_for_each_entry_rcu(handle, &handler->h_list, h_node) {
1795 retval = fn(handle, data);
1796 if (retval)
1797 break;
1798 }
1799
1800 rcu_read_unlock();
1801
1802 return retval;
1803}
1804EXPORT_SYMBOL(input_handler_for_each_handle);
1805
1806/**
1661 * input_register_handle - register a new input handle 1807 * input_register_handle - register a new input handle
1662 * @handle: handle to register 1808 * @handle: handle to register
1663 * 1809 *
@@ -1681,7 +1827,16 @@ int input_register_handle(struct input_handle *handle)
1681 error = mutex_lock_interruptible(&dev->mutex); 1827 error = mutex_lock_interruptible(&dev->mutex);
1682 if (error) 1828 if (error)
1683 return error; 1829 return error;
1684 list_add_tail_rcu(&handle->d_node, &dev->h_list); 1830
1831 /*
1832 * Filters go to the head of the list, normal handlers
1833 * to the tail.
1834 */
1835 if (handler->filter)
1836 list_add_rcu(&handle->d_node, &dev->h_list);
1837 else
1838 list_add_tail_rcu(&handle->d_node, &dev->h_list);
1839
1685 mutex_unlock(&dev->mutex); 1840 mutex_unlock(&dev->mutex);
1686 1841
1687 /* 1842 /*
@@ -1690,7 +1845,7 @@ int input_register_handle(struct input_handle *handle)
1690 * we can't be racing with input_unregister_handle() 1845 * we can't be racing with input_unregister_handle()
1691 * and so separate lock is not needed here. 1846 * and so separate lock is not needed here.
1692 */ 1847 */
1693 list_add_tail(&handle->h_node, &handler->h_list); 1848 list_add_tail_rcu(&handle->h_node, &handler->h_list);
1694 1849
1695 if (handler->start) 1850 if (handler->start)
1696 handler->start(handle); 1851 handler->start(handle);
@@ -1713,7 +1868,7 @@ void input_unregister_handle(struct input_handle *handle)
1713{ 1868{
1714 struct input_dev *dev = handle->dev; 1869 struct input_dev *dev = handle->dev;
1715 1870
1716 list_del_init(&handle->h_node); 1871 list_del_rcu(&handle->h_node);
1717 1872
1718 /* 1873 /*
1719 * Take dev->mutex to prevent race with input_release_device(). 1874 * Take dev->mutex to prevent race with input_release_device().
@@ -1721,6 +1876,7 @@ void input_unregister_handle(struct input_handle *handle)
1721 mutex_lock(&dev->mutex); 1876 mutex_lock(&dev->mutex);
1722 list_del_rcu(&handle->d_node); 1877 list_del_rcu(&handle->d_node);
1723 mutex_unlock(&dev->mutex); 1878 mutex_unlock(&dev->mutex);
1879
1724 synchronize_rcu(); 1880 synchronize_rcu();
1725} 1881}
1726EXPORT_SYMBOL(input_unregister_handle); 1882EXPORT_SYMBOL(input_unregister_handle);
@@ -1731,35 +1887,37 @@ static int input_open_file(struct inode *inode, struct file *file)
1731 const struct file_operations *old_fops, *new_fops = NULL; 1887 const struct file_operations *old_fops, *new_fops = NULL;
1732 int err; 1888 int err;
1733 1889
1734 lock_kernel(); 1890 err = mutex_lock_interruptible(&input_mutex);
1891 if (err)
1892 return err;
1893
1735 /* No load-on-demand here? */ 1894 /* No load-on-demand here? */
1736 handler = input_table[iminor(inode) >> 5]; 1895 handler = input_table[iminor(inode) >> 5];
1737 if (!handler || !(new_fops = fops_get(handler->fops))) { 1896 if (handler)
1738 err = -ENODEV; 1897 new_fops = fops_get(handler->fops);
1739 goto out; 1898
1740 } 1899 mutex_unlock(&input_mutex);
1741 1900
1742 /* 1901 /*
1743 * That's _really_ odd. Usually NULL ->open means "nothing special", 1902 * That's _really_ odd. Usually NULL ->open means "nothing special",
1744 * not "no device". Oh, well... 1903 * not "no device". Oh, well...
1745 */ 1904 */
1746 if (!new_fops->open) { 1905 if (!new_fops || !new_fops->open) {
1747 fops_put(new_fops); 1906 fops_put(new_fops);
1748 err = -ENODEV; 1907 err = -ENODEV;
1749 goto out; 1908 goto out;
1750 } 1909 }
1910
1751 old_fops = file->f_op; 1911 old_fops = file->f_op;
1752 file->f_op = new_fops; 1912 file->f_op = new_fops;
1753 1913
1754 err = new_fops->open(inode, file); 1914 err = new_fops->open(inode, file);
1755
1756 if (err) { 1915 if (err) {
1757 fops_put(file->f_op); 1916 fops_put(file->f_op);
1758 file->f_op = fops_get(old_fops); 1917 file->f_op = fops_get(old_fops);
1759 } 1918 }
1760 fops_put(old_fops); 1919 fops_put(old_fops);
1761out: 1920out:
1762 unlock_kernel();
1763 return err; 1921 return err;
1764} 1922}
1765 1923