Input: do not pass injected events back to the originating handler

Sometimes input handlers (as opposed to input devices) have a need to
inject (or re-inject) events back into input core. For example sysrq
filter may want to inject previously suppressed Alt-SysRq so that user
can take a screen print. In this case we do not want to pass such events
back to the same same handler that injected them to avoid loops.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+26 -11
+26 -11
drivers/input/input.c
··· 74 74 * dev->event_lock held and interrupts disabled. 75 75 */ 76 76 static void input_pass_event(struct input_dev *dev, 77 + struct input_handler *src_handler, 77 78 unsigned int type, unsigned int code, int value) 78 79 { 79 80 struct input_handler *handler; ··· 93 92 continue; 94 93 95 94 handler = handle->handler; 95 + 96 + /* 97 + * If this is the handler that injected this 98 + * particular event we want to skip it to avoid 99 + * filters firing again and again. 100 + */ 101 + if (handler == src_handler) 102 + continue; 103 + 96 104 if (!handler->filter) { 97 105 if (filtered) 98 106 break; ··· 131 121 if (test_bit(dev->repeat_key, dev->key) && 132 122 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 133 123 134 - input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 124 + input_pass_event(dev, NULL, EV_KEY, dev->repeat_key, 2); 135 125 136 126 if (dev->sync) { 137 127 /* ··· 140 130 * Otherwise assume that the driver will send 141 131 * SYN_REPORT once it's done. 142 132 */ 143 - input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 133 + input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1); 144 134 } 145 135 146 136 if (dev->rep[REP_PERIOD]) ··· 173 163 #define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 174 164 175 165 static int input_handle_abs_event(struct input_dev *dev, 166 + struct input_handler *src_handler, 176 167 unsigned int code, int *pval) 177 168 { 178 169 bool is_mt_event; ··· 217 206 /* Flush pending "slot" event */ 218 207 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { 219 208 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot); 220 - input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); 209 + input_pass_event(dev, src_handler, 210 + EV_ABS, ABS_MT_SLOT, dev->slot); 221 211 } 222 212 223 213 return INPUT_PASS_TO_HANDLERS; 224 214 } 225 215 226 216 static void input_handle_event(struct input_dev *dev, 217 + struct input_handler *src_handler, 227 218 unsigned int type, unsigned int code, int value) 228 219 { 229 220 int disposition = INPUT_IGNORE_EVENT; ··· 278 265 279 266 case EV_ABS: 280 267 if (is_event_supported(code, dev->absbit, ABS_MAX)) 281 - disposition = input_handle_abs_event(dev, code, &value); 268 + disposition = input_handle_abs_event(dev, src_handler, 269 + code, &value); 282 270 283 271 break; 284 272 ··· 337 323 dev->event(dev, type, code, value); 338 324 339 325 if (disposition & INPUT_PASS_TO_HANDLERS) 340 - input_pass_event(dev, type, code, value); 326 + input_pass_event(dev, src_handler, type, code, value); 341 327 } 342 328 343 329 /** ··· 366 352 367 353 spin_lock_irqsave(&dev->event_lock, flags); 368 354 add_input_randomness(type, code, value); 369 - input_handle_event(dev, type, code, value); 355 + input_handle_event(dev, NULL, type, code, value); 370 356 spin_unlock_irqrestore(&dev->event_lock, flags); 371 357 } 372 358 } ··· 396 382 rcu_read_lock(); 397 383 grab = rcu_dereference(dev->grab); 398 384 if (!grab || grab == handle) 399 - input_handle_event(dev, type, code, value); 385 + input_handle_event(dev, handle->handler, 386 + type, code, value); 400 387 rcu_read_unlock(); 401 388 402 389 spin_unlock_irqrestore(&dev->event_lock, flags); ··· 610 595 for (code = 0; code <= KEY_MAX; code++) { 611 596 if (is_event_supported(code, dev->keybit, KEY_MAX) && 612 597 __test_and_clear_bit(code, dev->key)) { 613 - input_pass_event(dev, EV_KEY, code, 0); 598 + input_pass_event(dev, NULL, EV_KEY, code, 0); 614 599 } 615 600 } 616 - input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 601 + input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1); 617 602 } 618 603 } 619 604 ··· 888 873 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 889 874 __test_and_clear_bit(old_keycode, dev->key)) { 890 875 891 - input_pass_event(dev, EV_KEY, old_keycode, 0); 876 + input_pass_event(dev, NULL, EV_KEY, old_keycode, 0); 892 877 if (dev->sync) 893 - input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 878 + input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1); 894 879 } 895 880 896 881 out: