diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-03-01 02:55:20 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-03-01 02:55:20 -0500 |
commit | 35858adbfca13678af99fb31618ef4428d6dedb0 (patch) | |
tree | 3336feaa61324486945816cb52c347733e7c0821 /drivers/input/input.c | |
parent | 197d4db752e67160d79fed09968c2140376a80a3 (diff) | |
parent | 4b70858ba8d4537daf782defebe5f2ff80ccef2b (diff) |
Merge branch 'next' into for-linus
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r-- | drivers/input/input.c | 90 |
1 files changed, 72 insertions, 18 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index 86cb2d2196ff..41168d5f8c17 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -87,12 +87,14 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz) | |||
87 | } | 87 | } |
88 | 88 | ||
89 | /* | 89 | /* |
90 | * Pass event through all open handles. This function is called with | 90 | * Pass event first through all filters and then, if event has not been |
91 | * filtered out, through all open handles. This function is called with | ||
91 | * dev->event_lock held and interrupts disabled. | 92 | * dev->event_lock held and interrupts disabled. |
92 | */ | 93 | */ |
93 | static void input_pass_event(struct input_dev *dev, | 94 | static void input_pass_event(struct input_dev *dev, |
94 | unsigned int type, unsigned int code, int value) | 95 | unsigned int type, unsigned int code, int value) |
95 | { | 96 | { |
97 | struct input_handler *handler; | ||
96 | struct input_handle *handle; | 98 | struct input_handle *handle; |
97 | 99 | ||
98 | rcu_read_lock(); | 100 | rcu_read_lock(); |
@@ -100,11 +102,25 @@ static void input_pass_event(struct input_dev *dev, | |||
100 | handle = rcu_dereference(dev->grab); | 102 | handle = rcu_dereference(dev->grab); |
101 | if (handle) | 103 | if (handle) |
102 | handle->handler->event(handle, type, code, value); | 104 | handle->handler->event(handle, type, code, value); |
103 | else | 105 | else { |
104 | list_for_each_entry_rcu(handle, &dev->h_list, d_node) | 106 | bool filtered = false; |
105 | if (handle->open) | 107 | |
106 | handle->handler->event(handle, | 108 | list_for_each_entry_rcu(handle, &dev->h_list, d_node) { |
107 | type, code, value); | 109 | if (!handle->open) |
110 | continue; | ||
111 | |||
112 | handler = handle->handler; | ||
113 | if (!handler->filter) { | ||
114 | if (filtered) | ||
115 | break; | ||
116 | |||
117 | handler->event(handle, type, code, value); | ||
118 | |||
119 | } else if (handler->filter(handle, type, code, value)) | ||
120 | filtered = true; | ||
121 | } | ||
122 | } | ||
123 | |||
108 | rcu_read_unlock(); | 124 | rcu_read_unlock(); |
109 | } | 125 | } |
110 | 126 | ||
@@ -615,12 +631,12 @@ static int input_default_setkeycode(struct input_dev *dev, | |||
615 | } | 631 | } |
616 | } | 632 | } |
617 | 633 | ||
618 | clear_bit(old_keycode, dev->keybit); | 634 | __clear_bit(old_keycode, dev->keybit); |
619 | set_bit(keycode, dev->keybit); | 635 | __set_bit(keycode, dev->keybit); |
620 | 636 | ||
621 | for (i = 0; i < dev->keycodemax; i++) { | 637 | for (i = 0; i < dev->keycodemax; i++) { |
622 | if (input_fetch_keycode(dev, i) == old_keycode) { | 638 | if (input_fetch_keycode(dev, i) == old_keycode) { |
623 | set_bit(old_keycode, dev->keybit); | 639 | __set_bit(old_keycode, dev->keybit); |
624 | break; /* Setting the bit twice is useless, so break */ | 640 | break; /* Setting the bit twice is useless, so break */ |
625 | } | 641 | } |
626 | } | 642 | } |
@@ -678,6 +694,9 @@ int input_set_keycode(struct input_dev *dev, int scancode, int keycode) | |||
678 | if (retval) | 694 | if (retval) |
679 | goto out; | 695 | goto out; |
680 | 696 | ||
697 | /* Make sure KEY_RESERVED did not get enabled. */ | ||
698 | __clear_bit(KEY_RESERVED, dev->keybit); | ||
699 | |||
681 | /* | 700 | /* |
682 | * Simulate keyup event if keycode is not present | 701 | * Simulate keyup event if keycode is not present |
683 | * in the keymap anymore | 702 | * in the keymap anymore |
@@ -705,12 +724,13 @@ EXPORT_SYMBOL(input_set_keycode); | |||
705 | if (i != BITS_TO_LONGS(max)) \ | 724 | if (i != BITS_TO_LONGS(max)) \ |
706 | continue; | 725 | continue; |
707 | 726 | ||
708 | static const struct input_device_id *input_match_device(const struct input_device_id *id, | 727 | static const struct input_device_id *input_match_device(struct input_handler *handler, |
709 | struct input_dev *dev) | 728 | struct input_dev *dev) |
710 | { | 729 | { |
730 | const struct input_device_id *id; | ||
711 | int i; | 731 | int i; |
712 | 732 | ||
713 | for (; id->flags || id->driver_info; id++) { | 733 | for (id = handler->id_table; id->flags || id->driver_info; id++) { |
714 | 734 | ||
715 | if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) | 735 | if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) |
716 | if (id->bustype != dev->id.bustype) | 736 | if (id->bustype != dev->id.bustype) |
@@ -738,7 +758,8 @@ static const struct input_device_id *input_match_device(const struct input_devic | |||
738 | MATCH_BIT(ffbit, FF_MAX); | 758 | MATCH_BIT(ffbit, FF_MAX); |
739 | MATCH_BIT(swbit, SW_MAX); | 759 | MATCH_BIT(swbit, SW_MAX); |
740 | 760 | ||
741 | return id; | 761 | if (!handler->match || handler->match(handler, dev)) |
762 | return id; | ||
742 | } | 763 | } |
743 | 764 | ||
744 | return NULL; | 765 | return NULL; |
@@ -749,10 +770,7 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han | |||
749 | const struct input_device_id *id; | 770 | const struct input_device_id *id; |
750 | int error; | 771 | int error; |
751 | 772 | ||
752 | if (handler->blacklist && input_match_device(handler->blacklist, dev)) | 773 | id = input_match_device(handler, dev); |
753 | return -ENODEV; | ||
754 | |||
755 | id = input_match_device(handler->id_table, dev); | ||
756 | if (!id) | 774 | if (!id) |
757 | return -ENODEV; | 775 | return -ENODEV; |
758 | 776 | ||
@@ -988,6 +1006,8 @@ static int input_handlers_seq_show(struct seq_file *seq, void *v) | |||
988 | union input_seq_state *state = (union input_seq_state *)&seq->private; | 1006 | union input_seq_state *state = (union input_seq_state *)&seq->private; |
989 | 1007 | ||
990 | seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); | 1008 | seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); |
1009 | if (handler->filter) | ||
1010 | seq_puts(seq, " (filter)"); | ||
991 | if (handler->fops) | 1011 | if (handler->fops) |
992 | seq_printf(seq, " Minor=%d", handler->minor); | 1012 | seq_printf(seq, " Minor=%d", handler->minor); |
993 | seq_putc(seq, '\n'); | 1013 | seq_putc(seq, '\n'); |
@@ -1551,6 +1571,25 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int | |||
1551 | } | 1571 | } |
1552 | EXPORT_SYMBOL(input_set_capability); | 1572 | EXPORT_SYMBOL(input_set_capability); |
1553 | 1573 | ||
1574 | #define INPUT_CLEANSE_BITMASK(dev, type, bits) \ | ||
1575 | do { \ | ||
1576 | if (!test_bit(EV_##type, dev->evbit)) \ | ||
1577 | memset(dev->bits##bit, 0, \ | ||
1578 | sizeof(dev->bits##bit)); \ | ||
1579 | } while (0) | ||
1580 | |||
1581 | static void input_cleanse_bitmasks(struct input_dev *dev) | ||
1582 | { | ||
1583 | INPUT_CLEANSE_BITMASK(dev, KEY, key); | ||
1584 | INPUT_CLEANSE_BITMASK(dev, REL, rel); | ||
1585 | INPUT_CLEANSE_BITMASK(dev, ABS, abs); | ||
1586 | INPUT_CLEANSE_BITMASK(dev, MSC, msc); | ||
1587 | INPUT_CLEANSE_BITMASK(dev, LED, led); | ||
1588 | INPUT_CLEANSE_BITMASK(dev, SND, snd); | ||
1589 | INPUT_CLEANSE_BITMASK(dev, FF, ff); | ||
1590 | INPUT_CLEANSE_BITMASK(dev, SW, sw); | ||
1591 | } | ||
1592 | |||
1554 | /** | 1593 | /** |
1555 | * input_register_device - register device with input core | 1594 | * input_register_device - register device with input core |
1556 | * @dev: device to be registered | 1595 | * @dev: device to be registered |
@@ -1570,13 +1609,19 @@ int input_register_device(struct input_dev *dev) | |||
1570 | const char *path; | 1609 | const char *path; |
1571 | int error; | 1610 | int error; |
1572 | 1611 | ||
1612 | /* Every input device generates EV_SYN/SYN_REPORT events. */ | ||
1573 | __set_bit(EV_SYN, dev->evbit); | 1613 | __set_bit(EV_SYN, dev->evbit); |
1574 | 1614 | ||
1615 | /* KEY_RESERVED is not supposed to be transmitted to userspace. */ | ||
1616 | __clear_bit(KEY_RESERVED, dev->keybit); | ||
1617 | |||
1618 | /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ | ||
1619 | input_cleanse_bitmasks(dev); | ||
1620 | |||
1575 | /* | 1621 | /* |
1576 | * If delay and period are pre-set by the driver, then autorepeating | 1622 | * If delay and period are pre-set by the driver, then autorepeating |
1577 | * is handled by the driver itself and we don't do it in input.c. | 1623 | * is handled by the driver itself and we don't do it in input.c. |
1578 | */ | 1624 | */ |
1579 | |||
1580 | init_timer(&dev->timer); | 1625 | init_timer(&dev->timer); |
1581 | if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { | 1626 | if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { |
1582 | dev->timer.data = (long) dev; | 1627 | dev->timer.data = (long) dev; |
@@ -1776,7 +1821,16 @@ int input_register_handle(struct input_handle *handle) | |||
1776 | error = mutex_lock_interruptible(&dev->mutex); | 1821 | error = mutex_lock_interruptible(&dev->mutex); |
1777 | if (error) | 1822 | if (error) |
1778 | return error; | 1823 | return error; |
1779 | list_add_tail_rcu(&handle->d_node, &dev->h_list); | 1824 | |
1825 | /* | ||
1826 | * Filters go to the head of the list, normal handlers | ||
1827 | * to the tail. | ||
1828 | */ | ||
1829 | if (handler->filter) | ||
1830 | list_add_rcu(&handle->d_node, &dev->h_list); | ||
1831 | else | ||
1832 | list_add_tail_rcu(&handle->d_node, &dev->h_list); | ||
1833 | |||
1780 | mutex_unlock(&dev->mutex); | 1834 | mutex_unlock(&dev->mutex); |
1781 | 1835 | ||
1782 | /* | 1836 | /* |