diff options
Diffstat (limited to 'drivers/input/input.c')
| -rw-r--r-- | drivers/input/input.c | 366 |
1 files changed, 221 insertions, 145 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index 768e46b05ef0..53a0ddee7872 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
| 16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
| 17 | #include <linux/idr.h> | ||
| 17 | #include <linux/input/mt.h> | 18 | #include <linux/input/mt.h> |
| 18 | #include <linux/module.h> | 19 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
| @@ -32,7 +33,9 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); | |||
| 32 | MODULE_DESCRIPTION("Input core"); | 33 | MODULE_DESCRIPTION("Input core"); |
| 33 | MODULE_LICENSE("GPL"); | 34 | MODULE_LICENSE("GPL"); |
| 34 | 35 | ||
| 35 | #define INPUT_DEVICES 256 | 36 | #define INPUT_MAX_CHAR_DEVICES 1024 |
| 37 | #define INPUT_FIRST_DYNAMIC_DEV 256 | ||
| 38 | static DEFINE_IDA(input_ida); | ||
| 36 | 39 | ||
| 37 | static LIST_HEAD(input_dev_list); | 40 | static LIST_HEAD(input_dev_list); |
| 38 | static LIST_HEAD(input_handler_list); | 41 | static LIST_HEAD(input_handler_list); |
| @@ -45,7 +48,7 @@ static LIST_HEAD(input_handler_list); | |||
| 45 | */ | 48 | */ |
| 46 | static DEFINE_MUTEX(input_mutex); | 49 | static DEFINE_MUTEX(input_mutex); |
| 47 | 50 | ||
| 48 | static struct input_handler *input_table[8]; | 51 | static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 }; |
| 49 | 52 | ||
| 50 | static inline int is_event_supported(unsigned int code, | 53 | static inline int is_event_supported(unsigned int code, |
| 51 | unsigned long *bm, unsigned int max) | 54 | unsigned long *bm, unsigned int max) |
| @@ -69,42 +72,102 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz) | |||
| 69 | return value; | 72 | return value; |
| 70 | } | 73 | } |
| 71 | 74 | ||
| 75 | static void input_start_autorepeat(struct input_dev *dev, int code) | ||
| 76 | { | ||
| 77 | if (test_bit(EV_REP, dev->evbit) && | ||
| 78 | dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && | ||
| 79 | dev->timer.data) { | ||
| 80 | dev->repeat_key = code; | ||
| 81 | mod_timer(&dev->timer, | ||
| 82 | jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | static void input_stop_autorepeat(struct input_dev *dev) | ||
| 87 | { | ||
| 88 | del_timer(&dev->timer); | ||
| 89 | } | ||
| 90 | |||
| 72 | /* | 91 | /* |
| 73 | * Pass event first through all filters and then, if event has not been | 92 | * Pass event first through all filters and then, if event has not been |
| 74 | * filtered out, through all open handles. This function is called with | 93 | * filtered out, through all open handles. This function is called with |
| 75 | * dev->event_lock held and interrupts disabled. | 94 | * dev->event_lock held and interrupts disabled. |
| 76 | */ | 95 | */ |
| 77 | static void input_pass_event(struct input_dev *dev, | 96 | static unsigned int input_to_handler(struct input_handle *handle, |
| 78 | unsigned int type, unsigned int code, int value) | 97 | struct input_value *vals, unsigned int count) |
| 98 | { | ||
| 99 | struct input_handler *handler = handle->handler; | ||
| 100 | struct input_value *end = vals; | ||
| 101 | struct input_value *v; | ||
| 102 | |||
| 103 | for (v = vals; v != vals + count; v++) { | ||
| 104 | if (handler->filter && | ||
| 105 | handler->filter(handle, v->type, v->code, v->value)) | ||
| 106 | continue; | ||
| 107 | if (end != v) | ||
| 108 | *end = *v; | ||
| 109 | end++; | ||
| 110 | } | ||
| 111 | |||
| 112 | count = end - vals; | ||
| 113 | if (!count) | ||
| 114 | return 0; | ||
| 115 | |||
| 116 | if (handler->events) | ||
| 117 | handler->events(handle, vals, count); | ||
| 118 | else if (handler->event) | ||
| 119 | for (v = vals; v != end; v++) | ||
| 120 | handler->event(handle, v->type, v->code, v->value); | ||
| 121 | |||
| 122 | return count; | ||
| 123 | } | ||
| 124 | |||
| 125 | /* | ||
| 126 | * Pass values first through all filters and then, if event has not been | ||
| 127 | * filtered out, through all open handles. This function is called with | ||
| 128 | * dev->event_lock held and interrupts disabled. | ||
| 129 | */ | ||
| 130 | static void input_pass_values(struct input_dev *dev, | ||
| 131 | struct input_value *vals, unsigned int count) | ||
| 79 | { | 132 | { |
| 80 | struct input_handler *handler; | ||
| 81 | struct input_handle *handle; | 133 | struct input_handle *handle; |
| 134 | struct input_value *v; | ||
| 135 | |||
| 136 | if (!count) | ||
| 137 | return; | ||
| 82 | 138 | ||
| 83 | rcu_read_lock(); | 139 | rcu_read_lock(); |
| 84 | 140 | ||
| 85 | handle = rcu_dereference(dev->grab); | 141 | handle = rcu_dereference(dev->grab); |
| 86 | if (handle) | 142 | if (handle) { |
| 87 | handle->handler->event(handle, type, code, value); | 143 | count = input_to_handler(handle, vals, count); |
| 88 | else { | 144 | } else { |
| 89 | bool filtered = false; | 145 | list_for_each_entry_rcu(handle, &dev->h_list, d_node) |
| 90 | 146 | if (handle->open) | |
| 91 | list_for_each_entry_rcu(handle, &dev->h_list, d_node) { | 147 | count = input_to_handler(handle, vals, count); |
| 92 | if (!handle->open) | 148 | } |
| 93 | continue; | ||
| 94 | 149 | ||
| 95 | handler = handle->handler; | 150 | rcu_read_unlock(); |
| 96 | if (!handler->filter) { | ||
| 97 | if (filtered) | ||
| 98 | break; | ||
| 99 | 151 | ||
| 100 | handler->event(handle, type, code, value); | 152 | add_input_randomness(vals->type, vals->code, vals->value); |
| 101 | 153 | ||
| 102 | } else if (handler->filter(handle, type, code, value)) | 154 | /* trigger auto repeat for key events */ |
| 103 | filtered = true; | 155 | for (v = vals; v != vals + count; v++) { |
| 156 | if (v->type == EV_KEY && v->value != 2) { | ||
| 157 | if (v->value) | ||
| 158 | input_start_autorepeat(dev, v->code); | ||
| 159 | else | ||
| 160 | input_stop_autorepeat(dev); | ||
| 104 | } | 161 | } |
| 105 | } | 162 | } |
| 163 | } | ||
| 106 | 164 | ||
| 107 | rcu_read_unlock(); | 165 | static void input_pass_event(struct input_dev *dev, |
| 166 | unsigned int type, unsigned int code, int value) | ||
| 167 | { | ||
| 168 | struct input_value vals[] = { { type, code, value } }; | ||
| 169 | |||
| 170 | input_pass_values(dev, vals, ARRAY_SIZE(vals)); | ||
| 108 | } | 171 | } |
| 109 | 172 | ||
| 110 | /* | 173 | /* |
| @@ -121,18 +184,12 @@ static void input_repeat_key(unsigned long data) | |||
| 121 | 184 | ||
| 122 | if (test_bit(dev->repeat_key, dev->key) && | 185 | if (test_bit(dev->repeat_key, dev->key) && |
| 123 | is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { | 186 | is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { |
| 187 | struct input_value vals[] = { | ||
| 188 | { EV_KEY, dev->repeat_key, 2 }, | ||
| 189 | input_value_sync | ||
| 190 | }; | ||
| 124 | 191 | ||
| 125 | input_pass_event(dev, EV_KEY, dev->repeat_key, 2); | 192 | input_pass_values(dev, vals, ARRAY_SIZE(vals)); |
| 126 | |||
| 127 | if (dev->sync) { | ||
| 128 | /* | ||
| 129 | * Only send SYN_REPORT if we are not in a middle | ||
| 130 | * of driver parsing a new hardware packet. | ||
| 131 | * Otherwise assume that the driver will send | ||
| 132 | * SYN_REPORT once it's done. | ||
| 133 | */ | ||
| 134 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); | ||
| 135 | } | ||
| 136 | 193 | ||
| 137 | if (dev->rep[REP_PERIOD]) | 194 | if (dev->rep[REP_PERIOD]) |
| 138 | mod_timer(&dev->timer, jiffies + | 195 | mod_timer(&dev->timer, jiffies + |
| @@ -142,30 +199,17 @@ static void input_repeat_key(unsigned long data) | |||
| 142 | spin_unlock_irqrestore(&dev->event_lock, flags); | 199 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 143 | } | 200 | } |
| 144 | 201 | ||
| 145 | static void input_start_autorepeat(struct input_dev *dev, int code) | ||
| 146 | { | ||
| 147 | if (test_bit(EV_REP, dev->evbit) && | ||
| 148 | dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && | ||
| 149 | dev->timer.data) { | ||
| 150 | dev->repeat_key = code; | ||
| 151 | mod_timer(&dev->timer, | ||
| 152 | jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | static void input_stop_autorepeat(struct input_dev *dev) | ||
| 157 | { | ||
| 158 | del_timer(&dev->timer); | ||
| 159 | } | ||
| 160 | |||
| 161 | #define INPUT_IGNORE_EVENT 0 | 202 | #define INPUT_IGNORE_EVENT 0 |
| 162 | #define INPUT_PASS_TO_HANDLERS 1 | 203 | #define INPUT_PASS_TO_HANDLERS 1 |
| 163 | #define INPUT_PASS_TO_DEVICE 2 | 204 | #define INPUT_PASS_TO_DEVICE 2 |
| 205 | #define INPUT_SLOT 4 | ||
| 206 | #define INPUT_FLUSH 8 | ||
| 164 | #define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) | 207 | #define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) |
| 165 | 208 | ||
| 166 | static int input_handle_abs_event(struct input_dev *dev, | 209 | static int input_handle_abs_event(struct input_dev *dev, |
| 167 | unsigned int code, int *pval) | 210 | unsigned int code, int *pval) |
| 168 | { | 211 | { |
| 212 | struct input_mt *mt = dev->mt; | ||
| 169 | bool is_mt_event; | 213 | bool is_mt_event; |
| 170 | int *pold; | 214 | int *pold; |
| 171 | 215 | ||
| @@ -174,8 +218,8 @@ static int input_handle_abs_event(struct input_dev *dev, | |||
| 174 | * "Stage" the event; we'll flush it later, when we | 218 | * "Stage" the event; we'll flush it later, when we |
| 175 | * get actual touch data. | 219 | * get actual touch data. |
| 176 | */ | 220 | */ |
| 177 | if (*pval >= 0 && *pval < dev->mtsize) | 221 | if (mt && *pval >= 0 && *pval < mt->num_slots) |
| 178 | dev->slot = *pval; | 222 | mt->slot = *pval; |
| 179 | 223 | ||
| 180 | return INPUT_IGNORE_EVENT; | 224 | return INPUT_IGNORE_EVENT; |
| 181 | } | 225 | } |
| @@ -184,9 +228,8 @@ static int input_handle_abs_event(struct input_dev *dev, | |||
| 184 | 228 | ||
| 185 | if (!is_mt_event) { | 229 | if (!is_mt_event) { |
| 186 | pold = &dev->absinfo[code].value; | 230 | pold = &dev->absinfo[code].value; |
| 187 | } else if (dev->mt) { | 231 | } else if (mt) { |
| 188 | struct input_mt_slot *mtslot = &dev->mt[dev->slot]; | 232 | pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST]; |
| 189 | pold = &mtslot->abs[code - ABS_MT_FIRST]; | ||
| 190 | } else { | 233 | } else { |
| 191 | /* | 234 | /* |
| 192 | * Bypass filtering for multi-touch events when | 235 | * Bypass filtering for multi-touch events when |
| @@ -205,16 +248,16 @@ static int input_handle_abs_event(struct input_dev *dev, | |||
| 205 | } | 248 | } |
| 206 | 249 | ||
| 207 | /* Flush pending "slot" event */ | 250 | /* Flush pending "slot" event */ |
| 208 | if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { | 251 | if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { |
| 209 | input_abs_set_val(dev, ABS_MT_SLOT, dev->slot); | 252 | input_abs_set_val(dev, ABS_MT_SLOT, mt->slot); |
| 210 | input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); | 253 | return INPUT_PASS_TO_HANDLERS | INPUT_SLOT; |
| 211 | } | 254 | } |
| 212 | 255 | ||
| 213 | return INPUT_PASS_TO_HANDLERS; | 256 | return INPUT_PASS_TO_HANDLERS; |
| 214 | } | 257 | } |
| 215 | 258 | ||
| 216 | static void input_handle_event(struct input_dev *dev, | 259 | static int input_get_disposition(struct input_dev *dev, |
| 217 | unsigned int type, unsigned int code, int value) | 260 | unsigned int type, unsigned int code, int value) |
| 218 | { | 261 | { |
| 219 | int disposition = INPUT_IGNORE_EVENT; | 262 | int disposition = INPUT_IGNORE_EVENT; |
| 220 | 263 | ||
| @@ -227,37 +270,34 @@ static void input_handle_event(struct input_dev *dev, | |||
| 227 | break; | 270 | break; |
| 228 | 271 | ||
| 229 | case SYN_REPORT: | 272 | case SYN_REPORT: |
| 230 | if (!dev->sync) { | 273 | disposition = INPUT_PASS_TO_HANDLERS | INPUT_FLUSH; |
| 231 | dev->sync = true; | ||
| 232 | disposition = INPUT_PASS_TO_HANDLERS; | ||
| 233 | } | ||
| 234 | break; | 274 | break; |
| 235 | case SYN_MT_REPORT: | 275 | case SYN_MT_REPORT: |
| 236 | dev->sync = false; | ||
| 237 | disposition = INPUT_PASS_TO_HANDLERS; | 276 | disposition = INPUT_PASS_TO_HANDLERS; |
| 238 | break; | 277 | break; |
| 239 | } | 278 | } |
| 240 | break; | 279 | break; |
| 241 | 280 | ||
| 242 | case EV_KEY: | 281 | case EV_KEY: |
| 243 | if (is_event_supported(code, dev->keybit, KEY_MAX) && | 282 | if (is_event_supported(code, dev->keybit, KEY_MAX)) { |
| 244 | !!test_bit(code, dev->key) != value) { | ||
| 245 | 283 | ||
| 246 | if (value != 2) { | 284 | /* auto-repeat bypasses state updates */ |
| 247 | __change_bit(code, dev->key); | 285 | if (value == 2) { |
| 248 | if (value) | 286 | disposition = INPUT_PASS_TO_HANDLERS; |
| 249 | input_start_autorepeat(dev, code); | 287 | break; |
| 250 | else | ||
| 251 | input_stop_autorepeat(dev); | ||
| 252 | } | 288 | } |
| 253 | 289 | ||
| 254 | disposition = INPUT_PASS_TO_HANDLERS; | 290 | if (!!test_bit(code, dev->key) != !!value) { |
| 291 | |||
| 292 | __change_bit(code, dev->key); | ||
| 293 | disposition = INPUT_PASS_TO_HANDLERS; | ||
| 294 | } | ||
| 255 | } | 295 | } |
| 256 | break; | 296 | break; |
| 257 | 297 | ||
| 258 | case EV_SW: | 298 | case EV_SW: |
| 259 | if (is_event_supported(code, dev->swbit, SW_MAX) && | 299 | if (is_event_supported(code, dev->swbit, SW_MAX) && |
| 260 | !!test_bit(code, dev->sw) != value) { | 300 | !!test_bit(code, dev->sw) != !!value) { |
| 261 | 301 | ||
| 262 | __change_bit(code, dev->sw); | 302 | __change_bit(code, dev->sw); |
| 263 | disposition = INPUT_PASS_TO_HANDLERS; | 303 | disposition = INPUT_PASS_TO_HANDLERS; |
| @@ -284,7 +324,7 @@ static void input_handle_event(struct input_dev *dev, | |||
| 284 | 324 | ||
| 285 | case EV_LED: | 325 | case EV_LED: |
| 286 | if (is_event_supported(code, dev->ledbit, LED_MAX) && | 326 | if (is_event_supported(code, dev->ledbit, LED_MAX) && |
| 287 | !!test_bit(code, dev->led) != value) { | 327 | !!test_bit(code, dev->led) != !!value) { |
| 288 | 328 | ||
| 289 | __change_bit(code, dev->led); | 329 | __change_bit(code, dev->led); |
| 290 | disposition = INPUT_PASS_TO_ALL; | 330 | disposition = INPUT_PASS_TO_ALL; |
| @@ -317,14 +357,48 @@ static void input_handle_event(struct input_dev *dev, | |||
| 317 | break; | 357 | break; |
| 318 | } | 358 | } |
| 319 | 359 | ||
| 320 | if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) | 360 | return disposition; |
| 321 | dev->sync = false; | 361 | } |
| 362 | |||
| 363 | static void input_handle_event(struct input_dev *dev, | ||
| 364 | unsigned int type, unsigned int code, int value) | ||
| 365 | { | ||
| 366 | int disposition; | ||
| 367 | |||
| 368 | disposition = input_get_disposition(dev, type, code, value); | ||
| 322 | 369 | ||
| 323 | if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) | 370 | if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) |
| 324 | dev->event(dev, type, code, value); | 371 | dev->event(dev, type, code, value); |
| 325 | 372 | ||
| 326 | if (disposition & INPUT_PASS_TO_HANDLERS) | 373 | if (!dev->vals) |
| 327 | input_pass_event(dev, type, code, value); | 374 | return; |
| 375 | |||
| 376 | if (disposition & INPUT_PASS_TO_HANDLERS) { | ||
| 377 | struct input_value *v; | ||
| 378 | |||
| 379 | if (disposition & INPUT_SLOT) { | ||
| 380 | v = &dev->vals[dev->num_vals++]; | ||
| 381 | v->type = EV_ABS; | ||
| 382 | v->code = ABS_MT_SLOT; | ||
| 383 | v->value = dev->mt->slot; | ||
| 384 | } | ||
| 385 | |||
| 386 | v = &dev->vals[dev->num_vals++]; | ||
| 387 | v->type = type; | ||
| 388 | v->code = code; | ||
| 389 | v->value = value; | ||
| 390 | } | ||
| 391 | |||
| 392 | if (disposition & INPUT_FLUSH) { | ||
| 393 | if (dev->num_vals >= 2) | ||
| 394 | input_pass_values(dev, dev->vals, dev->num_vals); | ||
| 395 | dev->num_vals = 0; | ||
| 396 | } else if (dev->num_vals >= dev->max_vals - 2) { | ||
| 397 | dev->vals[dev->num_vals++] = input_value_sync; | ||
| 398 | input_pass_values(dev, dev->vals, dev->num_vals); | ||
| 399 | dev->num_vals = 0; | ||
| 400 | } | ||
| 401 | |||
| 328 | } | 402 | } |
| 329 | 403 | ||
| 330 | /** | 404 | /** |
| @@ -352,7 +426,6 @@ void input_event(struct input_dev *dev, | |||
| 352 | if (is_event_supported(type, dev->evbit, EV_MAX)) { | 426 | if (is_event_supported(type, dev->evbit, EV_MAX)) { |
| 353 | 427 | ||
| 354 | spin_lock_irqsave(&dev->event_lock, flags); | 428 | spin_lock_irqsave(&dev->event_lock, flags); |
| 355 | add_input_randomness(type, code, value); | ||
| 356 | input_handle_event(dev, type, code, value); | 429 | input_handle_event(dev, type, code, value); |
| 357 | spin_unlock_irqrestore(&dev->event_lock, flags); | 430 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 358 | } | 431 | } |
| @@ -831,10 +904,12 @@ int input_set_keycode(struct input_dev *dev, | |||
| 831 | if (test_bit(EV_KEY, dev->evbit) && | 904 | if (test_bit(EV_KEY, dev->evbit) && |
| 832 | !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && | 905 | !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && |
| 833 | __test_and_clear_bit(old_keycode, dev->key)) { | 906 | __test_and_clear_bit(old_keycode, dev->key)) { |
| 907 | struct input_value vals[] = { | ||
| 908 | { EV_KEY, old_keycode, 0 }, | ||
| 909 | input_value_sync | ||
| 910 | }; | ||
| 834 | 911 | ||
| 835 | input_pass_event(dev, EV_KEY, old_keycode, 0); | 912 | input_pass_values(dev, vals, ARRAY_SIZE(vals)); |
| 836 | if (dev->sync) | ||
| 837 | input_pass_event(dev, EV_SYN, SYN_REPORT, 1); | ||
| 838 | } | 913 | } |
| 839 | 914 | ||
| 840 | out: | 915 | out: |
| @@ -1144,7 +1219,7 @@ static int input_handlers_seq_show(struct seq_file *seq, void *v) | |||
| 1144 | seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); | 1219 | seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); |
| 1145 | if (handler->filter) | 1220 | if (handler->filter) |
| 1146 | seq_puts(seq, " (filter)"); | 1221 | seq_puts(seq, " (filter)"); |
| 1147 | if (handler->fops) | 1222 | if (handler->legacy_minors) |
| 1148 | seq_printf(seq, " Minor=%d", handler->minor); | 1223 | seq_printf(seq, " Minor=%d", handler->minor); |
| 1149 | seq_putc(seq, '\n'); | 1224 | seq_putc(seq, '\n'); |
| 1150 | 1225 | ||
| @@ -1425,6 +1500,7 @@ static void input_dev_release(struct device *device) | |||
| 1425 | input_ff_destroy(dev); | 1500 | input_ff_destroy(dev); |
| 1426 | input_mt_destroy_slots(dev); | 1501 | input_mt_destroy_slots(dev); |
| 1427 | kfree(dev->absinfo); | 1502 | kfree(dev->absinfo); |
| 1503 | kfree(dev->vals); | ||
| 1428 | kfree(dev); | 1504 | kfree(dev); |
| 1429 | 1505 | ||
| 1430 | module_put(THIS_MODULE); | 1506 | module_put(THIS_MODULE); |
| @@ -1760,8 +1836,8 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev) | |||
| 1760 | int i; | 1836 | int i; |
| 1761 | unsigned int events; | 1837 | unsigned int events; |
| 1762 | 1838 | ||
| 1763 | if (dev->mtsize) { | 1839 | if (dev->mt) { |
| 1764 | mt_slots = dev->mtsize; | 1840 | mt_slots = dev->mt->num_slots; |
| 1765 | } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { | 1841 | } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { |
| 1766 | mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - | 1842 | mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - |
| 1767 | dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1, | 1843 | dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1, |
| @@ -1787,6 +1863,9 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev) | |||
| 1787 | if (test_bit(i, dev->relbit)) | 1863 | if (test_bit(i, dev->relbit)) |
| 1788 | events++; | 1864 | events++; |
| 1789 | 1865 | ||
| 1866 | /* Make room for KEY and MSC events */ | ||
| 1867 | events += 7; | ||
| 1868 | |||
| 1790 | return events; | 1869 | return events; |
| 1791 | } | 1870 | } |
| 1792 | 1871 | ||
| @@ -1825,6 +1904,7 @@ int input_register_device(struct input_dev *dev) | |||
| 1825 | { | 1904 | { |
| 1826 | static atomic_t input_no = ATOMIC_INIT(0); | 1905 | static atomic_t input_no = ATOMIC_INIT(0); |
| 1827 | struct input_handler *handler; | 1906 | struct input_handler *handler; |
| 1907 | unsigned int packet_size; | ||
| 1828 | const char *path; | 1908 | const char *path; |
| 1829 | int error; | 1909 | int error; |
| 1830 | 1910 | ||
| @@ -1837,9 +1917,14 @@ int input_register_device(struct input_dev *dev) | |||
| 1837 | /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ | 1917 | /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ |
| 1838 | input_cleanse_bitmasks(dev); | 1918 | input_cleanse_bitmasks(dev); |
| 1839 | 1919 | ||
| 1840 | if (!dev->hint_events_per_packet) | 1920 | packet_size = input_estimate_events_per_packet(dev); |
| 1841 | dev->hint_events_per_packet = | 1921 | if (dev->hint_events_per_packet < packet_size) |
| 1842 | input_estimate_events_per_packet(dev); | 1922 | dev->hint_events_per_packet = packet_size; |
| 1923 | |||
| 1924 | dev->max_vals = max(dev->hint_events_per_packet, packet_size) + 2; | ||
| 1925 | dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL); | ||
| 1926 | if (!dev->vals) | ||
| 1927 | return -ENOMEM; | ||
| 1843 | 1928 | ||
| 1844 | /* | 1929 | /* |
| 1845 | * If delay and period are pre-set by the driver, then autorepeating | 1930 | * If delay and period are pre-set by the driver, then autorepeating |
| @@ -1932,22 +2017,14 @@ EXPORT_SYMBOL(input_unregister_device); | |||
| 1932 | int input_register_handler(struct input_handler *handler) | 2017 | int input_register_handler(struct input_handler *handler) |
| 1933 | { | 2018 | { |
| 1934 | struct input_dev *dev; | 2019 | struct input_dev *dev; |
| 1935 | int retval; | 2020 | int error; |
| 1936 | 2021 | ||
| 1937 | retval = mutex_lock_interruptible(&input_mutex); | 2022 | error = mutex_lock_interruptible(&input_mutex); |
| 1938 | if (retval) | 2023 | if (error) |
| 1939 | return retval; | 2024 | return error; |
| 1940 | 2025 | ||
| 1941 | INIT_LIST_HEAD(&handler->h_list); | 2026 | INIT_LIST_HEAD(&handler->h_list); |
| 1942 | 2027 | ||
| 1943 | if (handler->fops != NULL) { | ||
| 1944 | if (input_table[handler->minor >> 5]) { | ||
| 1945 | retval = -EBUSY; | ||
| 1946 | goto out; | ||
| 1947 | } | ||
| 1948 | input_table[handler->minor >> 5] = handler; | ||
| 1949 | } | ||
| 1950 | |||
| 1951 | list_add_tail(&handler->node, &input_handler_list); | 2028 | list_add_tail(&handler->node, &input_handler_list); |
| 1952 | 2029 | ||
| 1953 | list_for_each_entry(dev, &input_dev_list, node) | 2030 | list_for_each_entry(dev, &input_dev_list, node) |
| @@ -1955,9 +2032,8 @@ int input_register_handler(struct input_handler *handler) | |||
| 1955 | 2032 | ||
| 1956 | input_wakeup_procfs_readers(); | 2033 | input_wakeup_procfs_readers(); |
| 1957 | 2034 | ||
| 1958 | out: | ||
| 1959 | mutex_unlock(&input_mutex); | 2035 | mutex_unlock(&input_mutex); |
| 1960 | return retval; | 2036 | return 0; |
| 1961 | } | 2037 | } |
| 1962 | EXPORT_SYMBOL(input_register_handler); | 2038 | EXPORT_SYMBOL(input_register_handler); |
| 1963 | 2039 | ||
| @@ -1980,9 +2056,6 @@ void input_unregister_handler(struct input_handler *handler) | |||
| 1980 | 2056 | ||
| 1981 | list_del_init(&handler->node); | 2057 | list_del_init(&handler->node); |
| 1982 | 2058 | ||
| 1983 | if (handler->fops != NULL) | ||
| 1984 | input_table[handler->minor >> 5] = NULL; | ||
| 1985 | |||
| 1986 | input_wakeup_procfs_readers(); | 2059 | input_wakeup_procfs_readers(); |
| 1987 | 2060 | ||
| 1988 | mutex_unlock(&input_mutex); | 2061 | mutex_unlock(&input_mutex); |
| @@ -2099,51 +2172,52 @@ void input_unregister_handle(struct input_handle *handle) | |||
| 2099 | } | 2172 | } |
| 2100 | EXPORT_SYMBOL(input_unregister_handle); | 2173 | EXPORT_SYMBOL(input_unregister_handle); |
| 2101 | 2174 | ||
| 2102 | static int input_open_file(struct inode *inode, struct file *file) | 2175 | /** |
| 2176 | * input_get_new_minor - allocates a new input minor number | ||
| 2177 | * @legacy_base: beginning or the legacy range to be searched | ||
| 2178 | * @legacy_num: size of legacy range | ||
| 2179 | * @allow_dynamic: whether we can also take ID from the dynamic range | ||
| 2180 | * | ||
| 2181 | * This function allocates a new device minor for from input major namespace. | ||
| 2182 | * Caller can request legacy minor by specifying @legacy_base and @legacy_num | ||
| 2183 | * parameters and whether ID can be allocated from dynamic range if there are | ||
| 2184 | * no free IDs in legacy range. | ||
| 2185 | */ | ||
| 2186 | int input_get_new_minor(int legacy_base, unsigned int legacy_num, | ||
| 2187 | bool allow_dynamic) | ||
| 2103 | { | 2188 | { |
| 2104 | struct input_handler *handler; | ||
| 2105 | const struct file_operations *old_fops, *new_fops = NULL; | ||
| 2106 | int err; | ||
| 2107 | |||
| 2108 | err = mutex_lock_interruptible(&input_mutex); | ||
| 2109 | if (err) | ||
| 2110 | return err; | ||
| 2111 | |||
| 2112 | /* No load-on-demand here? */ | ||
| 2113 | handler = input_table[iminor(inode) >> 5]; | ||
| 2114 | if (handler) | ||
| 2115 | new_fops = fops_get(handler->fops); | ||
| 2116 | |||
| 2117 | mutex_unlock(&input_mutex); | ||
| 2118 | |||
| 2119 | /* | 2189 | /* |
| 2120 | * That's _really_ odd. Usually NULL ->open means "nothing special", | 2190 | * This function should be called from input handler's ->connect() |
| 2121 | * not "no device". Oh, well... | 2191 | * methods, which are serialized with input_mutex, so no additional |
| 2192 | * locking is needed here. | ||
| 2122 | */ | 2193 | */ |
| 2123 | if (!new_fops || !new_fops->open) { | 2194 | if (legacy_base >= 0) { |
| 2124 | fops_put(new_fops); | 2195 | int minor = ida_simple_get(&input_ida, |
| 2125 | err = -ENODEV; | 2196 | legacy_base, |
| 2126 | goto out; | 2197 | legacy_base + legacy_num, |
| 2198 | GFP_KERNEL); | ||
| 2199 | if (minor >= 0 || !allow_dynamic) | ||
| 2200 | return minor; | ||
| 2127 | } | 2201 | } |
| 2128 | 2202 | ||
| 2129 | old_fops = file->f_op; | 2203 | return ida_simple_get(&input_ida, |
| 2130 | file->f_op = new_fops; | 2204 | INPUT_FIRST_DYNAMIC_DEV, INPUT_MAX_CHAR_DEVICES, |
| 2131 | 2205 | GFP_KERNEL); | |
| 2132 | err = new_fops->open(inode, file); | ||
| 2133 | if (err) { | ||
| 2134 | fops_put(file->f_op); | ||
| 2135 | file->f_op = fops_get(old_fops); | ||
| 2136 | } | ||
| 2137 | fops_put(old_fops); | ||
| 2138 | out: | ||
| 2139 | return err; | ||
| 2140 | } | 2206 | } |
| 2207 | EXPORT_SYMBOL(input_get_new_minor); | ||
| 2141 | 2208 | ||
| 2142 | static const struct file_operations input_fops = { | 2209 | /** |
| 2143 | .owner = THIS_MODULE, | 2210 | * input_free_minor - release previously allocated minor |
| 2144 | .open = input_open_file, | 2211 | * @minor: minor to be released |
| 2145 | .llseek = noop_llseek, | 2212 | * |
| 2146 | }; | 2213 | * This function releases previously allocated input minor so that it can be |
| 2214 | * reused later. | ||
| 2215 | */ | ||
| 2216 | void input_free_minor(unsigned int minor) | ||
| 2217 | { | ||
| 2218 | ida_simple_remove(&input_ida, minor); | ||
| 2219 | } | ||
| 2220 | EXPORT_SYMBOL(input_free_minor); | ||
| 2147 | 2221 | ||
| 2148 | static int __init input_init(void) | 2222 | static int __init input_init(void) |
| 2149 | { | 2223 | { |
| @@ -2159,7 +2233,8 @@ static int __init input_init(void) | |||
| 2159 | if (err) | 2233 | if (err) |
| 2160 | goto fail1; | 2234 | goto fail1; |
| 2161 | 2235 | ||
| 2162 | err = register_chrdev(INPUT_MAJOR, "input", &input_fops); | 2236 | err = register_chrdev_region(MKDEV(INPUT_MAJOR, 0), |
| 2237 | INPUT_MAX_CHAR_DEVICES, "input"); | ||
| 2163 | if (err) { | 2238 | if (err) { |
| 2164 | pr_err("unable to register char major %d", INPUT_MAJOR); | 2239 | pr_err("unable to register char major %d", INPUT_MAJOR); |
| 2165 | goto fail2; | 2240 | goto fail2; |
| @@ -2175,7 +2250,8 @@ static int __init input_init(void) | |||
| 2175 | static void __exit input_exit(void) | 2250 | static void __exit input_exit(void) |
| 2176 | { | 2251 | { |
| 2177 | input_proc_exit(); | 2252 | input_proc_exit(); |
| 2178 | unregister_chrdev(INPUT_MAJOR, "input"); | 2253 | unregister_chrdev_region(MKDEV(INPUT_MAJOR, 0), |
| 2254 | INPUT_MAX_CHAR_DEVICES); | ||
| 2179 | class_unregister(&input_class); | 2255 | class_unregister(&input_class); |
| 2180 | } | 2256 | } |
| 2181 | 2257 | ||
