1 From a6b37451a52ae7d30c2493b9cc14b8604e81587d Mon Sep 17 00:00:00 2001
2 From: mokopatches <mokopatches@openmoko.org>
3 Date: Sun, 13 Apr 2008 07:23:53 +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 e5b4e9b..2f3d825 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 @@ -135,14 +132,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 @@ -150,12 +148,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 @@ -230,7 +228,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);