Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: properly queue synthetic events

We should not be passing synthetic events (such as autorepeat events)
out of order with the events coming from the hardware device, but rather
add them to pending events and flush them all at once.

This also fixes an issue with timestamps for key release events carrying
stale data from the previous autorepeat event.

Reviewed-by: Angela Czubak <acz@semihalf.com>
Link: https://lore.kernel.org/r/YszNfq4b6MkeoCJC@google.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+63 -62
+63 -62
drivers/input/input.c
··· 174 174 } 175 175 } 176 176 177 - static void input_pass_event(struct input_dev *dev, 178 - unsigned int type, unsigned int code, int value) 179 - { 180 - struct input_value vals[] = { { type, code, value } }; 181 - 182 - input_pass_values(dev, vals, ARRAY_SIZE(vals)); 183 - } 184 - 185 - /* 186 - * Generate software autorepeat event. Note that we take 187 - * dev->event_lock here to avoid racing with input_event 188 - * which may cause keys get "stuck". 189 - */ 190 - static void input_repeat_key(struct timer_list *t) 191 - { 192 - struct input_dev *dev = from_timer(dev, t, timer); 193 - unsigned long flags; 194 - 195 - spin_lock_irqsave(&dev->event_lock, flags); 196 - 197 - if (test_bit(dev->repeat_key, dev->key) && 198 - is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 199 - struct input_value vals[] = { 200 - { EV_KEY, dev->repeat_key, 2 }, 201 - input_value_sync 202 - }; 203 - 204 - input_set_timestamp(dev, ktime_get()); 205 - input_pass_values(dev, vals, ARRAY_SIZE(vals)); 206 - 207 - if (dev->rep[REP_PERIOD]) 208 - mod_timer(&dev->timer, jiffies + 209 - msecs_to_jiffies(dev->rep[REP_PERIOD])); 210 - } 211 - 212 - spin_unlock_irqrestore(&dev->event_lock, flags); 213 - } 214 - 215 177 #define INPUT_IGNORE_EVENT 0 216 178 #define INPUT_PASS_TO_HANDLERS 1 217 179 #define INPUT_PASS_TO_DEVICE 2 ··· 236 274 { 237 275 int disposition = INPUT_IGNORE_EVENT; 238 276 int value = *pval; 277 + 278 + /* filter-out events from inhibited devices */ 279 + if (dev->inhibited) 280 + return INPUT_IGNORE_EVENT; 239 281 240 282 switch (type) { 241 283 ··· 341 375 return disposition; 342 376 } 343 377 344 - static void input_handle_event(struct input_dev *dev, 345 - unsigned int type, unsigned int code, int value) 378 + static void input_event_dispose(struct input_dev *dev, int disposition, 379 + unsigned int type, unsigned int code, int value) 346 380 { 347 - int disposition; 348 - 349 - /* filter-out events from inhibited devices */ 350 - if (dev->inhibited) 351 - return; 352 - 353 - disposition = input_get_disposition(dev, type, code, &value); 354 - if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 355 - add_input_randomness(type, code, value); 356 - 357 381 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 358 382 dev->event(dev, type, code, value); 359 383 ··· 382 426 input_pass_values(dev, dev->vals, dev->num_vals); 383 427 dev->num_vals = 0; 384 428 } 429 + } 385 430 431 + static void input_handle_event(struct input_dev *dev, 432 + unsigned int type, unsigned int code, int value) 433 + { 434 + int disposition; 435 + 436 + lockdep_assert_held(&dev->event_lock); 437 + 438 + disposition = input_get_disposition(dev, type, code, &value); 439 + if (disposition != INPUT_IGNORE_EVENT) { 440 + if (type != EV_SYN) 441 + add_input_randomness(type, code, value); 442 + 443 + input_event_dispose(dev, disposition, type, code, value); 444 + } 386 445 } 387 446 388 447 /** ··· 584 613 lockdep_is_held(&dev->mutex)); 585 614 if (grabber == handle) { 586 615 rcu_assign_pointer(dev->grab, NULL); 587 - /* Make sure input_pass_event() notices that grab is gone */ 616 + /* Make sure input_pass_values() notices that grab is gone */ 588 617 synchronize_rcu(); 589 618 590 619 list_for_each_entry(handle, &dev->h_list, d_node) ··· 707 736 708 737 if (!--handle->open) { 709 738 /* 710 - * synchronize_rcu() makes sure that input_pass_event() 739 + * synchronize_rcu() makes sure that input_pass_values() 711 740 * completed and that no more input events are delivered 712 741 * through this handle 713 742 */ ··· 729 758 730 759 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { 731 760 for_each_set_bit(code, dev->key, KEY_CNT) { 732 - input_pass_event(dev, EV_KEY, code, 0); 761 + input_handle_event(dev, EV_KEY, code, 0); 733 762 need_sync = true; 734 763 } 735 764 736 765 if (need_sync) 737 - input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 738 - 739 - memset(dev->key, 0, sizeof(dev->key)); 766 + input_handle_event(dev, EV_SYN, SYN_REPORT, 1); 740 767 } 741 768 } 742 769 ··· 973 1004 } else if (test_bit(EV_KEY, dev->evbit) && 974 1005 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 975 1006 __test_and_clear_bit(old_keycode, dev->key)) { 976 - struct input_value vals[] = { 977 - { EV_KEY, old_keycode, 0 }, 978 - input_value_sync 979 - }; 980 - 981 - input_pass_values(dev, vals, ARRAY_SIZE(vals)); 1007 + /* 1008 + * We have to use input_event_dispose() here directly instead 1009 + * of input_handle_event() because the key we want to release 1010 + * here is considered no longer supported by the device and 1011 + * input_handle_event() will ignore it. 1012 + */ 1013 + input_event_dispose(dev, INPUT_PASS_TO_HANDLERS, 1014 + EV_KEY, old_keycode, 0); 1015 + input_event_dispose(dev, INPUT_PASS_TO_HANDLERS | INPUT_FLUSH, 1016 + EV_SYN, SYN_REPORT, 1); 982 1017 } 983 1018 984 1019 out: ··· 2230 2257 dev_dbg(dev, "%s: unregistering device %s\n", 2231 2258 __func__, dev_name(&input->dev)); 2232 2259 __input_unregister_device(input); 2260 + } 2261 + 2262 + /* 2263 + * Generate software autorepeat event. Note that we take 2264 + * dev->event_lock here to avoid racing with input_event 2265 + * which may cause keys get "stuck". 2266 + */ 2267 + static void input_repeat_key(struct timer_list *t) 2268 + { 2269 + struct input_dev *dev = from_timer(dev, t, timer); 2270 + unsigned long flags; 2271 + 2272 + spin_lock_irqsave(&dev->event_lock, flags); 2273 + 2274 + if (!dev->inhibited && 2275 + test_bit(dev->repeat_key, dev->key) && 2276 + is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 2277 + 2278 + input_set_timestamp(dev, ktime_get()); 2279 + input_handle_event(dev, EV_KEY, dev->repeat_key, 2); 2280 + input_handle_event(dev, EV_SYN, SYN_REPORT, 1); 2281 + 2282 + if (dev->rep[REP_PERIOD]) 2283 + mod_timer(&dev->timer, jiffies + 2284 + msecs_to_jiffies(dev->rep[REP_PERIOD])); 2285 + } 2286 + 2287 + spin_unlock_irqrestore(&dev->event_lock, flags); 2233 2288 } 2234 2289 2235 2290 /**