@@ -47,6 +47,8 @@ static DEFINE_MUTEX(input_mutex);
47
47
48
48
static struct input_handler * input_table [8 ];
49
49
50
+ static const struct input_value input_value_sync = { EV_SYN , SYN_REPORT , 1 };
51
+
50
52
static inline int is_event_supported (unsigned int code ,
51
53
unsigned long * bm , unsigned int max )
52
54
{
@@ -90,46 +92,81 @@ static void input_stop_autorepeat(struct input_dev *dev)
90
92
* filtered out, through all open handles. This function is called with
91
93
* dev->event_lock held and interrupts disabled.
92
94
*/
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 )
95
97
{
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 ;
98
101
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
+ }
100
110
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 ;
106
114
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 ;
110
134
111
- handler = handle -> handler ;
112
- if (!handler -> filter ) {
113
- if (filtered )
114
- break ;
135
+ if (!count )
136
+ return ;
115
137
116
- handler -> event ( handle , type , code , value );
138
+ rcu_read_lock ( );
117
139
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 );
121
147
}
122
148
123
149
rcu_read_unlock ();
124
150
151
+ add_input_randomness (vals -> type , vals -> code , vals -> value );
152
+
125
153
/* 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
+ }
131
161
}
162
+ }
132
163
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 ));
133
170
}
134
171
135
172
/*
@@ -146,18 +183,12 @@ static void input_repeat_key(unsigned long data)
146
183
147
184
if (test_bit (dev -> repeat_key , dev -> key ) &&
148
185
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
+ };
149
190
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 ));
161
192
162
193
if (dev -> rep [REP_PERIOD ])
163
194
mod_timer (& dev -> timer , jiffies +
@@ -170,6 +201,8 @@ static void input_repeat_key(unsigned long data)
170
201
#define INPUT_IGNORE_EVENT 0
171
202
#define INPUT_PASS_TO_HANDLERS 1
172
203
#define INPUT_PASS_TO_DEVICE 2
204
+ #define INPUT_SLOT 4
205
+ #define INPUT_FLUSH 8
173
206
#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
174
207
175
208
static int input_handle_abs_event (struct input_dev * dev ,
@@ -216,14 +249,14 @@ static int input_handle_abs_event(struct input_dev *dev,
216
249
/* Flush pending "slot" event */
217
250
if (is_mt_event && mt && mt -> slot != input_abs_get_val (dev , ABS_MT_SLOT )) {
218
251
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 ;
220
253
}
221
254
222
255
return INPUT_PASS_TO_HANDLERS ;
223
256
}
224
257
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 )
227
260
{
228
261
int disposition = INPUT_IGNORE_EVENT ;
229
262
@@ -236,13 +269,9 @@ static void input_handle_event(struct input_dev *dev,
236
269
break ;
237
270
238
271
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 ;
243
273
break ;
244
274
case SYN_MT_REPORT :
245
- dev -> sync = false;
246
275
disposition = INPUT_PASS_TO_HANDLERS ;
247
276
break ;
248
277
}
@@ -327,14 +356,48 @@ static void input_handle_event(struct input_dev *dev,
327
356
break ;
328
357
}
329
358
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 );
332
368
333
369
if ((disposition & INPUT_PASS_TO_DEVICE ) && dev -> event )
334
370
dev -> event (dev , type , code , value );
335
371
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
+
338
401
}
339
402
340
403
/**
@@ -362,7 +425,6 @@ void input_event(struct input_dev *dev,
362
425
if (is_event_supported (type , dev -> evbit , EV_MAX )) {
363
426
364
427
spin_lock_irqsave (& dev -> event_lock , flags );
365
- add_input_randomness (type , code , value );
366
428
input_handle_event (dev , type , code , value );
367
429
spin_unlock_irqrestore (& dev -> event_lock , flags );
368
430
}
@@ -841,10 +903,12 @@ int input_set_keycode(struct input_dev *dev,
841
903
if (test_bit (EV_KEY , dev -> evbit ) &&
842
904
!is_event_supported (old_keycode , dev -> keybit , KEY_MAX ) &&
843
905
__test_and_clear_bit (old_keycode , dev -> key )) {
906
+ struct input_value vals [] = {
907
+ { EV_KEY , old_keycode , 0 },
908
+ input_value_sync
909
+ };
844
910
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 ));
848
912
}
849
913
850
914
out :
@@ -1426,6 +1490,7 @@ static void input_dev_release(struct device *device)
1426
1490
input_ff_destroy (dev );
1427
1491
input_mt_destroy_slots (dev );
1428
1492
kfree (dev -> absinfo );
1493
+ kfree (dev -> vals );
1429
1494
kfree (dev );
1430
1495
1431
1496
module_put (THIS_MODULE );
@@ -1846,6 +1911,11 @@ int input_register_device(struct input_dev *dev)
1846
1911
if (dev -> hint_events_per_packet < packet_size )
1847
1912
dev -> hint_events_per_packet = packet_size ;
1848
1913
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
+
1849
1919
/*
1850
1920
* If delay and period are pre-set by the driver, then autorepeating
1851
1921
* is handled by the driver itself and we don't do it in input.c.
0 commit comments