aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/evdev.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2007-04-12 01:30:00 -0400
committerDmitry Torokhov <dtor@insightbb.com>2007-04-12 01:30:00 -0400
commitd0ffb9be866519775da19c0a6790f5431c1a8dc6 (patch)
tree0ded8723264a1e9e41f34ea1e05740496f317e6a /drivers/input/evdev.c
parent5b2a08262a8c952fef008154933953f083ca5766 (diff)
Input: handlers - rename 'list' to 'client'
The naming convention in input handlers was very confusing - client stuctures were called lists, regular lists were also called lists making anyone looking at the code go mad. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/evdev.c')
-rw-r--r--drivers/input/evdev.c150
1 files changed, 80 insertions, 70 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 840fa1986527..8a4cce5c7806 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -29,11 +29,11 @@ struct evdev {
29 char name[16]; 29 char name[16];
30 struct input_handle handle; 30 struct input_handle handle;
31 wait_queue_head_t wait; 31 wait_queue_head_t wait;
32 struct evdev_list *grab; 32 struct evdev_client *grab;
33 struct list_head list; 33 struct list_head client_list;
34}; 34};
35 35
36struct evdev_list { 36struct evdev_client {
37 struct input_event buffer[EVDEV_BUFFER_SIZE]; 37 struct input_event buffer[EVDEV_BUFFER_SIZE];
38 int head; 38 int head;
39 int tail; 39 int tail;
@@ -47,28 +47,28 @@ static struct evdev *evdev_table[EVDEV_MINORS];
47static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) 47static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
48{ 48{
49 struct evdev *evdev = handle->private; 49 struct evdev *evdev = handle->private;
50 struct evdev_list *list; 50 struct evdev_client *client;
51 51
52 if (evdev->grab) { 52 if (evdev->grab) {
53 list = evdev->grab; 53 client = evdev->grab;
54 54
55 do_gettimeofday(&list->buffer[list->head].time); 55 do_gettimeofday(&client->buffer[client->head].time);
56 list->buffer[list->head].type = type; 56 client->buffer[client->head].type = type;
57 list->buffer[list->head].code = code; 57 client->buffer[client->head].code = code;
58 list->buffer[list->head].value = value; 58 client->buffer[client->head].value = value;
59 list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1); 59 client->head = (client->head + 1) & (EVDEV_BUFFER_SIZE - 1);
60 60
61 kill_fasync(&list->fasync, SIGIO, POLL_IN); 61 kill_fasync(&client->fasync, SIGIO, POLL_IN);
62 } else 62 } else
63 list_for_each_entry(list, &evdev->list, node) { 63 list_for_each_entry(client, &evdev->client_list, node) {
64 64
65 do_gettimeofday(&list->buffer[list->head].time); 65 do_gettimeofday(&client->buffer[client->head].time);
66 list->buffer[list->head].type = type; 66 client->buffer[client->head].type = type;
67 list->buffer[list->head].code = code; 67 client->buffer[client->head].code = code;
68 list->buffer[list->head].value = value; 68 client->buffer[client->head].value = value;
69 list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1); 69 client->head = (client->head + 1) & (EVDEV_BUFFER_SIZE - 1);
70 70
71 kill_fasync(&list->fasync, SIGIO, POLL_IN); 71 kill_fasync(&client->fasync, SIGIO, POLL_IN);
72 } 72 }
73 73
74 wake_up_interruptible(&evdev->wait); 74 wake_up_interruptible(&evdev->wait);
@@ -76,22 +76,23 @@ static void evdev_event(struct input_handle *handle, unsigned int type, unsigned
76 76
77static int evdev_fasync(int fd, struct file *file, int on) 77static int evdev_fasync(int fd, struct file *file, int on)
78{ 78{
79 struct evdev_client *client = file->private_data;
79 int retval; 80 int retval;
80 struct evdev_list *list = file->private_data;
81 81
82 retval = fasync_helper(fd, file, on, &list->fasync); 82 retval = fasync_helper(fd, file, on, &client->fasync);
83 83
84 return retval < 0 ? retval : 0; 84 return retval < 0 ? retval : 0;
85} 85}
86 86
87static int evdev_flush(struct file *file, fl_owner_t id) 87static int evdev_flush(struct file *file, fl_owner_t id)
88{ 88{
89 struct evdev_list *list = file->private_data; 89 struct evdev_client *client = file->private_data;
90 struct evdev *evdev = client->evdev;
90 91
91 if (!list->evdev->exist) 92 if (!evdev->exist)
92 return -ENODEV; 93 return -ENODEV;
93 94
94 return input_flush_device(&list->evdev->handle, file); 95 return input_flush_device(&evdev->handle, file);
95} 96}
96 97
97static void evdev_free(struct evdev *evdev) 98static void evdev_free(struct evdev *evdev)
@@ -100,48 +101,55 @@ static void evdev_free(struct evdev *evdev)
100 kfree(evdev); 101 kfree(evdev);
101} 102}
102 103
103static int evdev_release(struct inode * inode, struct file * file) 104static int evdev_release(struct inode *inode, struct file *file)
104{ 105{
105 struct evdev_list *list = file->private_data; 106 struct evdev_client *client = file->private_data;
107 struct evdev *evdev = client->evdev;
106 108
107 if (list->evdev->grab == list) { 109 if (evdev->grab == client) {
108 input_release_device(&list->evdev->handle); 110 input_release_device(&evdev->handle);
109 list->evdev->grab = NULL; 111 evdev->grab = NULL;
110 } 112 }
111 113
112 evdev_fasync(-1, file, 0); 114 evdev_fasync(-1, file, 0);
113 list_del(&list->node); 115 list_del(&client->node);
116 kfree(client);
114 117
115 if (!--list->evdev->open) { 118 if (!--evdev->open) {
116 if (list->evdev->exist) 119 if (evdev->exist)
117 input_close_device(&list->evdev->handle); 120 input_close_device(&evdev->handle);
118 else 121 else
119 evdev_free(list->evdev); 122 evdev_free(evdev);
120 } 123 }
121 124
122 kfree(list);
123 return 0; 125 return 0;
124} 126}
125 127
126static int evdev_open(struct inode * inode, struct file * file) 128static int evdev_open(struct inode *inode, struct file *file)
127{ 129{
128 struct evdev_list *list; 130 struct evdev_client *client;
131 struct evdev *evdev;
129 int i = iminor(inode) - EVDEV_MINOR_BASE; 132 int i = iminor(inode) - EVDEV_MINOR_BASE;
130 133
131 if (i >= EVDEV_MINORS || !evdev_table[i] || !evdev_table[i]->exist) 134 if (i >= EVDEV_MINORS)
135 return -ENODEV;
136
137 evdev = evdev_table[i];
138
139 if (!evdev || !evdev->exist)
132 return -ENODEV; 140 return -ENODEV;
133 141
134 if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL))) 142 client = kzalloc(sizeof(struct evdev_client), GFP_KERNEL);
143 if (!client)
135 return -ENOMEM; 144 return -ENOMEM;
136 145
137 list->evdev = evdev_table[i]; 146 client->evdev = evdev;
138 list_add_tail(&list->node, &evdev_table[i]->list); 147 list_add_tail(&client->node, &evdev->client_list);
139 file->private_data = list;
140 148
141 if (!list->evdev->open++) 149 if (!evdev->open++ && evdev->exist)
142 if (list->evdev->exist) 150 input_open_device(&evdev->handle);
143 input_open_device(&list->evdev->handle);
144 151
152 file->private_data = client;
145 return 0; 153 return 0;
146} 154}
147 155
@@ -243,54 +251,55 @@ static int evdev_event_to_user(char __user *buffer, const struct input_event *ev
243 251
244#endif /* CONFIG_COMPAT */ 252#endif /* CONFIG_COMPAT */
245 253
246static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) 254static ssize_t evdev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
247{ 255{
248 struct evdev_list *list = file->private_data; 256 struct evdev_client *client = file->private_data;
257 struct evdev *evdev = client->evdev;
249 struct input_event event; 258 struct input_event event;
250 int retval = 0; 259 int retval = 0;
251 260
252 if (!list->evdev->exist) 261 if (!evdev->exist)
253 return -ENODEV; 262 return -ENODEV;
254 263
255 while (retval < count) { 264 while (retval < count) {
256 265
257 if (evdev_event_from_user(buffer + retval, &event)) 266 if (evdev_event_from_user(buffer + retval, &event))
258 return -EFAULT; 267 return -EFAULT;
259 input_inject_event(&list->evdev->handle, event.type, event.code, event.value); 268 input_inject_event(&evdev->handle, event.type, event.code, event.value);
260 retval += evdev_event_size(); 269 retval += evdev_event_size();
261 } 270 }
262 271
263 return retval; 272 return retval;
264} 273}
265 274
266static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) 275static ssize_t evdev_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
267{ 276{
268 struct evdev_list *list = file->private_data; 277 struct evdev_client *client = file->private_data;
278 struct evdev *evdev = client->evdev;
269 int retval; 279 int retval;
270 280
271 if (count < evdev_event_size()) 281 if (count < evdev_event_size())
272 return -EINVAL; 282 return -EINVAL;
273 283
274 if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK)) 284 if (client->head == client->tail && evdev->exist && (file->f_flags & O_NONBLOCK))
275 return -EAGAIN; 285 return -EAGAIN;
276 286
277 retval = wait_event_interruptible(list->evdev->wait, 287 retval = wait_event_interruptible(evdev->wait,
278 list->head != list->tail || (!list->evdev->exist)); 288 client->head != client->tail || !evdev->exist);
279
280 if (retval) 289 if (retval)
281 return retval; 290 return retval;
282 291
283 if (!list->evdev->exist) 292 if (!evdev->exist)
284 return -ENODEV; 293 return -ENODEV;
285 294
286 while (list->head != list->tail && retval + evdev_event_size() <= count) { 295 while (client->head != client->tail && retval + evdev_event_size() <= count) {
287 296
288 struct input_event *event = (struct input_event *) list->buffer + list->tail; 297 struct input_event *event = (struct input_event *) client->buffer + client->tail;
289 298
290 if (evdev_event_to_user(buffer + retval, event)) 299 if (evdev_event_to_user(buffer + retval, event))
291 return -EFAULT; 300 return -EFAULT;
292 301
293 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); 302 client->tail = (client->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
294 retval += evdev_event_size(); 303 retval += evdev_event_size();
295 } 304 }
296 305
@@ -300,11 +309,12 @@ static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count
300/* No kernel lock - fine */ 309/* No kernel lock - fine */
301static unsigned int evdev_poll(struct file *file, poll_table *wait) 310static unsigned int evdev_poll(struct file *file, poll_table *wait)
302{ 311{
303 struct evdev_list *list = file->private_data; 312 struct evdev_client *client = file->private_data;
313 struct evdev *evdev = client->evdev;
304 314
305 poll_wait(file, &list->evdev->wait, wait); 315 poll_wait(file, &evdev->wait, wait);
306 return ((list->head == list->tail) ? 0 : (POLLIN | POLLRDNORM)) | 316 return ((client->head == client->tail) ? 0 : (POLLIN | POLLRDNORM)) |
307 (list->evdev->exist ? 0 : (POLLHUP | POLLERR)); 317 (evdev->exist ? 0 : (POLLHUP | POLLERR));
308} 318}
309 319
310#ifdef CONFIG_COMPAT 320#ifdef CONFIG_COMPAT
@@ -387,8 +397,8 @@ static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
387static long evdev_ioctl_handler(struct file *file, unsigned int cmd, 397static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
388 void __user *p, int compat_mode) 398 void __user *p, int compat_mode)
389{ 399{
390 struct evdev_list *list = file->private_data; 400 struct evdev_client *client = file->private_data;
391 struct evdev *evdev = list->evdev; 401 struct evdev *evdev = client->evdev;
392 struct input_dev *dev = evdev->handle.dev; 402 struct input_dev *dev = evdev->handle.dev;
393 struct input_absinfo abs; 403 struct input_absinfo abs;
394 struct ff_effect effect; 404 struct ff_effect effect;
@@ -476,10 +486,10 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
476 return -EBUSY; 486 return -EBUSY;
477 if (input_grab_device(&evdev->handle)) 487 if (input_grab_device(&evdev->handle))
478 return -EBUSY; 488 return -EBUSY;
479 evdev->grab = list; 489 evdev->grab = client;
480 return 0; 490 return 0;
481 } else { 491 } else {
482 if (evdev->grab != list) 492 if (evdev->grab != client)
483 return -EINVAL; 493 return -EINVAL;
484 input_release_device(&evdev->handle); 494 input_release_device(&evdev->handle);
485 evdev->grab = NULL; 495 evdev->grab = NULL;
@@ -624,7 +634,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
624 if (!evdev) 634 if (!evdev)
625 return -ENOMEM; 635 return -ENOMEM;
626 636
627 INIT_LIST_HEAD(&evdev->list); 637 INIT_LIST_HEAD(&evdev->client_list);
628 init_waitqueue_head(&evdev->wait); 638 init_waitqueue_head(&evdev->wait);
629 639
630 evdev->exist = 1; 640 evdev->exist = 1;
@@ -671,7 +681,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
671static void evdev_disconnect(struct input_handle *handle) 681static void evdev_disconnect(struct input_handle *handle)
672{ 682{
673 struct evdev *evdev = handle->private; 683 struct evdev *evdev = handle->private;
674 struct evdev_list *list; 684 struct evdev_client *client;
675 685
676 input_unregister_handle(handle); 686 input_unregister_handle(handle);
677 687
@@ -684,8 +694,8 @@ static void evdev_disconnect(struct input_handle *handle)
684 input_flush_device(handle, NULL); 694 input_flush_device(handle, NULL);
685 input_close_device(handle); 695 input_close_device(handle);
686 wake_up_interruptible(&evdev->wait); 696 wake_up_interruptible(&evdev->wait);
687 list_for_each_entry(list, &evdev->list, node) 697 list_for_each_entry(client, &evdev->client_list, node)
688 kill_fasync(&list->fasync, SIGIO, POLL_HUP); 698 kill_fasync(&client->fasync, SIGIO, POLL_HUP);
689 } else 699 } else
690 evdev_free(evdev); 700 evdev_free(evdev);
691} 701}