89
89
static void input_pass_event(struct input_dev *dev,
90
90
unsigned int type, unsigned int code, int value)
92
struct input_handle *handle;
92
{ struct input_handle *handle;
96
96
handle = rcu_dereference(dev->grab);
98
98
handle->handler->event(handle, type, code, value);
100
list_for_each_entry_rcu(handle, &dev->h_list, d_node)
102
handle->handler->event(handle,
102
handle = rcu_dereference(dev->filter);
103
if (handle && handle->handler->filter(handle, type, code, value))
106
list_for_each_entry_rcu(handle, &dev->h_list, d_node)
108
handle->handler->event(handle,
104
111
rcu_read_unlock();
376
383
EXPORT_SYMBOL(input_grab_device);
378
static void __input_release_device(struct input_handle *handle)
385
static void __input_release_device(struct input_handle *handle, bool filter)
380
387
struct input_dev *dev = handle->dev;
382
if (dev->grab == handle) {
383
rcu_assign_pointer(dev->grab, NULL);
389
if (handle == (filter ? dev->filter : dev->grab)) {
391
rcu_assign_pointer(dev->filter, NULL);
393
rcu_assign_pointer(dev->grab, NULL);
384
394
/* Make sure input_pass_event() notices that grab is gone */
385
395
synchronize_rcu();
404
414
struct input_dev *dev = handle->dev;
406
416
mutex_lock(&dev->mutex);
407
__input_release_device(handle);
417
__input_release_device(handle, false);
408
418
mutex_unlock(&dev->mutex);
410
420
EXPORT_SYMBOL(input_release_device);
423
* input_filter_device - allow input events to be filtered from higher layers
424
* @handle: input handle that wants to filter the device
426
* When a device is filtered by an input handle all events generated by
427
* the device are to this handle. If the filter function returns true then
428
* the event is discarded rather than being passed to any other input handles,
429
* otherwise it is passed to them as normal. Grabs will be handled before
430
* filters, so a grabbed device will not deliver events to a filter function.
432
int input_filter_device(struct input_handle *handle)
434
struct input_dev *dev = handle->dev;
437
retval = mutex_lock_interruptible(&dev->mutex);
446
rcu_assign_pointer(dev->filter, handle);
450
mutex_unlock(&dev->mutex);
453
EXPORT_SYMBOL(input_filter_device);
456
* input_unfilter_device - removes a filter from a device
457
* @handle: input handle that owns the device
459
* Removes the filter from a device so that other input handles can
460
* start receiving unfiltered input events. Upon release all handlers
461
* attached to the device have their start() method called so they
462
* have a change to synchronize device state with the rest of the
465
void input_unfilter_device(struct input_handle *handle)
467
struct input_dev *dev = handle->dev;
469
mutex_lock(&dev->mutex);
470
__input_release_device(handle, true);
471
mutex_unlock(&dev->mutex);
473
EXPORT_SYMBOL(input_unfilter_device);
413
476
* input_open_device - open input device
414
477
* @handle: handle through which device is being accessed
483
546
mutex_lock(&dev->mutex);
485
__input_release_device(handle);
548
/* Release both grabs and filters */
549
__input_release_device(handle, false);
550
__input_release_device(handle, true);
487
552
if (!--dev->users && dev->close)