Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 183111
b: refs/heads/master
c: ef7995f
h: refs/heads/master
i:
  183109: 8521909
  183107: d7a647d
  183103: 23a2060
v: v3
  • Loading branch information
Dmitry Torokhov committed Jan 30, 2010
1 parent 3405f9c commit fc81a33
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 45cdba4d376adfd30cfbda1b7d43110818d967cc
refs/heads/master: ef7995f4e46b1677f3eaaf547316e1a910b38dcb
41 changes: 34 additions & 7 deletions trunk/drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,40 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
}

/*
* Pass event through all open handles. This function is called with
* Pass event first through all filters and then, if event has not been
* filtered out, through all open handles. This function is called with
* dev->event_lock held and interrupts disabled.
*/
static void input_pass_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
{
struct input_handler *handler;
struct input_handle *handle;

rcu_read_lock();

handle = rcu_dereference(dev->grab);
if (handle)
handle->handler->event(handle, type, code, value);
else
list_for_each_entry_rcu(handle, &dev->h_list, d_node)
if (handle->open)
handle->handler->event(handle,
type, code, value);
else {
bool filtered = false;

list_for_each_entry_rcu(handle, &dev->h_list, d_node) {
if (!handle->open)
continue;

handler = handle->handler;
if (!handler->filter) {
if (filtered)
break;

handler->event(handle, type, code, value);

} else if (handler->filter(handle, type, code, value))
filtered = true;
}
}

rcu_read_unlock();
}

Expand Down Expand Up @@ -990,6 +1006,8 @@ static int input_handlers_seq_show(struct seq_file *seq, void *v)
union input_seq_state *state = (union input_seq_state *)&seq->private;

seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
if (handler->filter)
seq_puts(seq, " (filter)");
if (handler->fops)
seq_printf(seq, " Minor=%d", handler->minor);
seq_putc(seq, '\n');
Expand Down Expand Up @@ -1803,7 +1821,16 @@ int input_register_handle(struct input_handle *handle)
error = mutex_lock_interruptible(&dev->mutex);
if (error)
return error;
list_add_tail_rcu(&handle->d_node, &dev->h_list);

/*
* Filters go to the head of the list, normal handlers
* to the tail.
*/
if (handler->filter)
list_add_rcu(&handle->d_node, &dev->h_list);
else
list_add_tail_rcu(&handle->d_node, &dev->h_list);

mutex_unlock(&dev->mutex);

/*
Expand Down
8 changes: 8 additions & 0 deletions trunk/include/linux/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@ struct input_handle;
* @event: event handler. This method is being called by input core with
* interrupts disabled and dev->event_lock spinlock held and so
* it may not sleep
* @filter: similar to @event; separates normal event handlers from
* "filters".
* @connect: called when attaching a handler to an input device
* @disconnect: disconnects a handler from input device
* @start: starts handler for given handle. This function is called by
Expand All @@ -1219,6 +1221,11 @@ struct input_handle;
* same time. All of them will get their copy of input event generated by
* the device.
*
* The very same structure is used to implement input filters. Input core
* allows filters to run first and will not pass event to regular handlers
* if any of the filters indicate that the event should be filtered (by
* returning %true from their filter() method).
*
* Note that input core serializes calls to connect() and disconnect()
* methods.
*/
Expand All @@ -1227,6 +1234,7 @@ struct input_handler {
void *private;

void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
void (*disconnect)(struct input_handle *handle);
void (*start)(struct input_handle *handle);
Expand Down

0 comments on commit fc81a33

Please sign in to comment.