1 From 6294c84872b0d26111bdd1b9e5fec41c8a087443 Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Fri, 25 Jul 2008 22:21:23 +0100
4 Subject: [PATCH] fix-EVIOCGRAB-semantics.patch
7 drivers/input/evdev.c | 32 +++++++++++++++-----------------
8 1 files changed, 15 insertions(+), 17 deletions(-)
10 diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
11 index b32984b..499ffe1 100644
12 --- a/drivers/input/evdev.c
13 +++ b/drivers/input/evdev.c
14 @@ -28,7 +28,7 @@ struct evdev {
16 struct input_handle handle;
17 wait_queue_head_t wait;
18 - struct evdev_client *grab;
20 struct list_head client_list;
21 spinlock_t client_lock; /* protects client_list */
23 @@ -39,6 +39,7 @@ struct evdev_client {
24 struct input_event buffer[EVDEV_BUFFER_SIZE];
28 spinlock_t buffer_lock; /* protects access to buffer, head and tail */
29 struct fasync_struct *fasync;
31 @@ -79,12 +80,8 @@ static void evdev_event(struct input_handle *handle,
35 - client = rcu_dereference(evdev->grab);
37 + list_for_each_entry_rcu(client, &evdev->client_list, node)
38 evdev_pass_event(client, &event);
40 - list_for_each_entry_rcu(client, &evdev->client_list, node)
41 - evdev_pass_event(client, &event);
45 @@ -136,14 +133,15 @@ static int evdev_grab(struct evdev *evdev, struct evdev_client *client)
53 - error = input_grab_device(&evdev->handle);
57 - rcu_assign_pointer(evdev->grab, client);
58 + if (!evdev->grab++) {
59 + error = input_grab_device(&evdev->handle);
67 @@ -151,12 +149,12 @@ static int evdev_grab(struct evdev *evdev, struct evdev_client *client)
69 static int evdev_ungrab(struct evdev *evdev, struct evdev_client *client)
71 - if (evdev->grab != client)
75 - rcu_assign_pointer(evdev->grab, NULL);
77 - input_release_device(&evdev->handle);
78 + if (!--evdev->grab && evdev->exist)
79 + input_release_device(&evdev->handle);
84 @@ -231,7 +229,7 @@ static int evdev_release(struct inode *inode, struct file *file)
85 struct evdev *evdev = client->evdev;
87 mutex_lock(&evdev->mutex);
88 - if (evdev->grab == client)
90 evdev_ungrab(evdev, client);
91 mutex_unlock(&evdev->mutex);