@@ -47,6 +47,8 @@ static DEFINE_MUTEX(input_mutex);
4747
4848static struct input_handler * input_table [8 ];
4949
50+ static const struct input_value input_value_sync = { EV_SYN , SYN_REPORT , 1 };
51+
5052static inline int is_event_supported (unsigned int code ,
5153 unsigned long * bm , unsigned int max )
5254{
@@ -90,46 +92,81 @@ static void input_stop_autorepeat(struct input_dev *dev)
9092 * filtered out, through all open handles. This function is called with
9193 * dev->event_lock held and interrupts disabled.
9294 */
93- static void input_pass_event (struct input_dev * dev ,
94- unsigned int type , unsigned int code , int value )
95+ static unsigned int input_to_handler (struct input_handle * handle ,
96+ struct input_value * vals , unsigned int count )
9597{
96- struct input_handler * handler ;
97- struct input_handle * handle ;
98+ struct input_handler * handler = handle -> handler ;
99+ struct input_value * end = vals ;
100+ struct input_value * v ;
98101
99- rcu_read_lock ();
102+ for (v = vals ; v != vals + count ; v ++ ) {
103+ if (handler -> filter &&
104+ handler -> filter (handle , v -> type , v -> code , v -> value ))
105+ continue ;
106+ if (end != v )
107+ * end = * v ;
108+ end ++ ;
109+ }
100110
101- handle = rcu_dereference (dev -> grab );
102- if (handle )
103- handle -> handler -> event (handle , type , code , value );
104- else {
105- bool filtered = false;
111+ count = end - vals ;
112+ if (!count )
113+ return 0 ;
106114
107- list_for_each_entry_rcu (handle , & dev -> h_list , d_node ) {
108- if (!handle -> open )
109- continue ;
115+ if (handler -> events )
116+ handler -> events (handle , vals , count );
117+ else if (handler -> event )
118+ for (v = vals ; v != end ; v ++ )
119+ handler -> event (handle , v -> type , v -> code , v -> value );
120+
121+ return count ;
122+ }
123+
124+ /*
125+ * Pass values first through all filters and then, if event has not been
126+ * filtered out, through all open handles. This function is called with
127+ * dev->event_lock held and interrupts disabled.
128+ */
129+ static void input_pass_values (struct input_dev * dev ,
130+ struct input_value * vals , unsigned int count )
131+ {
132+ struct input_handle * handle ;
133+ struct input_value * v ;
110134
111- handler = handle -> handler ;
112- if (!handler -> filter ) {
113- if (filtered )
114- break ;
135+ if (!count )
136+ return ;
115137
116- handler -> event ( handle , type , code , value );
138+ rcu_read_lock ( );
117139
118- } else if (handler -> filter (handle , type , code , value ))
119- filtered = true;
120- }
140+ handle = rcu_dereference (dev -> grab );
141+ if (handle ) {
142+ count = input_to_handler (handle , vals , count );
143+ } else {
144+ list_for_each_entry_rcu (handle , & dev -> h_list , d_node )
145+ if (handle -> open )
146+ count = input_to_handler (handle , vals , count );
121147 }
122148
123149 rcu_read_unlock ();
124150
151+ add_input_randomness (vals -> type , vals -> code , vals -> value );
152+
125153 /* trigger auto repeat for key events */
126- if (type == EV_KEY && value != 2 ) {
127- if (value )
128- input_start_autorepeat (dev , code );
129- else
130- input_stop_autorepeat (dev );
154+ for (v = vals ; v != vals + count ; v ++ ) {
155+ if (v -> type == EV_KEY && v -> value != 2 ) {
156+ if (v -> value )
157+ input_start_autorepeat (dev , v -> code );
158+ else
159+ input_stop_autorepeat (dev );
160+ }
131161 }
162+ }
132163
164+ static void input_pass_event (struct input_dev * dev ,
165+ unsigned int type , unsigned int code , int value )
166+ {
167+ struct input_value vals [] = { { type , code , value } };
168+
169+ input_pass_values (dev , vals , ARRAY_SIZE (vals ));
133170}
134171
135172/*
@@ -146,18 +183,12 @@ static void input_repeat_key(unsigned long data)
146183
147184 if (test_bit (dev -> repeat_key , dev -> key ) &&
148185 is_event_supported (dev -> repeat_key , dev -> keybit , KEY_MAX )) {
186+ struct input_value vals [] = {
187+ { EV_KEY , dev -> repeat_key , 2 },
188+ input_value_sync
189+ };
149190
150- input_pass_event (dev , EV_KEY , dev -> repeat_key , 2 );
151-
152- if (dev -> sync ) {
153- /*
154- * Only send SYN_REPORT if we are not in a middle
155- * of driver parsing a new hardware packet.
156- * Otherwise assume that the driver will send
157- * SYN_REPORT once it's done.
158- */
159- input_pass_event (dev , EV_SYN , SYN_REPORT , 1 );
160- }
191+ input_pass_values (dev , vals , ARRAY_SIZE (vals ));
161192
162193 if (dev -> rep [REP_PERIOD ])
163194 mod_timer (& dev -> timer , jiffies +
@@ -170,6 +201,8 @@ static void input_repeat_key(unsigned long data)
170201#define INPUT_IGNORE_EVENT 0
171202#define INPUT_PASS_TO_HANDLERS 1
172203#define INPUT_PASS_TO_DEVICE 2
204+ #define INPUT_SLOT 4
205+ #define INPUT_FLUSH 8
173206#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
174207
175208static int input_handle_abs_event (struct input_dev * dev ,
@@ -216,14 +249,14 @@ static int input_handle_abs_event(struct input_dev *dev,
216249 /* Flush pending "slot" event */
217250 if (is_mt_event && mt && mt -> slot != input_abs_get_val (dev , ABS_MT_SLOT )) {
218251 input_abs_set_val (dev , ABS_MT_SLOT , mt -> slot );
219- input_pass_event ( dev , EV_ABS , ABS_MT_SLOT , mt -> slot ) ;
252+ return INPUT_PASS_TO_HANDLERS | INPUT_SLOT ;
220253 }
221254
222255 return INPUT_PASS_TO_HANDLERS ;
223256}
224257
225- static void input_handle_event (struct input_dev * dev ,
226- unsigned int type , unsigned int code , int value )
258+ static int input_get_disposition (struct input_dev * dev ,
259+ unsigned int type , unsigned int code , int value )
227260{
228261 int disposition = INPUT_IGNORE_EVENT ;
229262
@@ -236,13 +269,9 @@ static void input_handle_event(struct input_dev *dev,
236269 break ;
237270
238271 case SYN_REPORT :
239- if (!dev -> sync ) {
240- dev -> sync = true;
241- disposition = INPUT_PASS_TO_HANDLERS ;
242- }
272+ disposition = INPUT_PASS_TO_HANDLERS | INPUT_FLUSH ;
243273 break ;
244274 case SYN_MT_REPORT :
245- dev -> sync = false;
246275 disposition = INPUT_PASS_TO_HANDLERS ;
247276 break ;
248277 }
@@ -327,14 +356,48 @@ static void input_handle_event(struct input_dev *dev,
327356 break ;
328357 }
329358
330- if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN )
331- dev -> sync = false;
359+ return disposition ;
360+ }
361+
362+ static void input_handle_event (struct input_dev * dev ,
363+ unsigned int type , unsigned int code , int value )
364+ {
365+ int disposition ;
366+
367+ disposition = input_get_disposition (dev , type , code , value );
332368
333369 if ((disposition & INPUT_PASS_TO_DEVICE ) && dev -> event )
334370 dev -> event (dev , type , code , value );
335371
336- if (disposition & INPUT_PASS_TO_HANDLERS )
337- input_pass_event (dev , type , code , value );
372+ if (!dev -> vals )
373+ return ;
374+
375+ if (disposition & INPUT_PASS_TO_HANDLERS ) {
376+ struct input_value * v ;
377+
378+ if (disposition & INPUT_SLOT ) {
379+ v = & dev -> vals [dev -> num_vals ++ ];
380+ v -> type = EV_ABS ;
381+ v -> code = ABS_MT_SLOT ;
382+ v -> value = dev -> mt -> slot ;
383+ }
384+
385+ v = & dev -> vals [dev -> num_vals ++ ];
386+ v -> type = type ;
387+ v -> code = code ;
388+ v -> value = value ;
389+ }
390+
391+ if (disposition & INPUT_FLUSH ) {
392+ if (dev -> num_vals >= 2 )
393+ input_pass_values (dev , dev -> vals , dev -> num_vals );
394+ dev -> num_vals = 0 ;
395+ } else if (dev -> num_vals >= dev -> max_vals - 2 ) {
396+ dev -> vals [dev -> num_vals ++ ] = input_value_sync ;
397+ input_pass_values (dev , dev -> vals , dev -> num_vals );
398+ dev -> num_vals = 0 ;
399+ }
400+
338401}
339402
340403/**
@@ -362,7 +425,6 @@ void input_event(struct input_dev *dev,
362425 if (is_event_supported (type , dev -> evbit , EV_MAX )) {
363426
364427 spin_lock_irqsave (& dev -> event_lock , flags );
365- add_input_randomness (type , code , value );
366428 input_handle_event (dev , type , code , value );
367429 spin_unlock_irqrestore (& dev -> event_lock , flags );
368430 }
@@ -841,10 +903,12 @@ int input_set_keycode(struct input_dev *dev,
841903 if (test_bit (EV_KEY , dev -> evbit ) &&
842904 !is_event_supported (old_keycode , dev -> keybit , KEY_MAX ) &&
843905 __test_and_clear_bit (old_keycode , dev -> key )) {
906+ struct input_value vals [] = {
907+ { EV_KEY , old_keycode , 0 },
908+ input_value_sync
909+ };
844910
845- input_pass_event (dev , EV_KEY , old_keycode , 0 );
846- if (dev -> sync )
847- input_pass_event (dev , EV_SYN , SYN_REPORT , 1 );
911+ input_pass_values (dev , vals , ARRAY_SIZE (vals ));
848912 }
849913
850914 out :
@@ -1426,6 +1490,7 @@ static void input_dev_release(struct device *device)
14261490 input_ff_destroy (dev );
14271491 input_mt_destroy_slots (dev );
14281492 kfree (dev -> absinfo );
1493+ kfree (dev -> vals );
14291494 kfree (dev );
14301495
14311496 module_put (THIS_MODULE );
@@ -1846,6 +1911,11 @@ int input_register_device(struct input_dev *dev)
18461911 if (dev -> hint_events_per_packet < packet_size )
18471912 dev -> hint_events_per_packet = packet_size ;
18481913
1914+ dev -> max_vals = max (dev -> hint_events_per_packet , packet_size ) + 2 ;
1915+ dev -> vals = kcalloc (dev -> max_vals , sizeof (* dev -> vals ), GFP_KERNEL );
1916+ if (!dev -> vals )
1917+ return - ENOMEM ;
1918+
18491919 /*
18501920 * If delay and period are pre-set by the driver, then autorepeating
18511921 * is handled by the driver itself and we don't do it in input.c.
0 commit comments