Commit d0ffb9be authored by Dmitry Torokhov's avatar Dmitry Torokhov

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: default avatarDmitry Torokhov <dtor@mail.ru>
parent 5b2a0826
...@@ -29,11 +29,11 @@ struct evdev { ...@@ -29,11 +29,11 @@ struct evdev {
char name[16]; char name[16];
struct input_handle handle; struct input_handle handle;
wait_queue_head_t wait; wait_queue_head_t wait;
struct evdev_list *grab; struct evdev_client *grab;
struct list_head list; struct list_head client_list;
}; };
struct evdev_list { struct evdev_client {
struct input_event buffer[EVDEV_BUFFER_SIZE]; struct input_event buffer[EVDEV_BUFFER_SIZE];
int head; int head;
int tail; int tail;
...@@ -47,28 +47,28 @@ static struct evdev *evdev_table[EVDEV_MINORS]; ...@@ -47,28 +47,28 @@ static struct evdev *evdev_table[EVDEV_MINORS];
static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{ {
struct evdev *evdev = handle->private; struct evdev *evdev = handle->private;
struct evdev_list *list; struct evdev_client *client;
if (evdev->grab) { if (evdev->grab) {
list = evdev->grab; client = evdev->grab;
do_gettimeofday(&list->buffer[list->head].time); do_gettimeofday(&client->buffer[client->head].time);
list->buffer[list->head].type = type; client->buffer[client->head].type = type;
list->buffer[list->head].code = code; client->buffer[client->head].code = code;
list->buffer[list->head].value = value; client->buffer[client->head].value = value;
list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1); client->head = (client->head + 1) & (EVDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&client->fasync, SIGIO, POLL_IN);
} else } else
list_for_each_entry(list, &evdev->list, node) { list_for_each_entry(client, &evdev->client_list, node) {
do_gettimeofday(&list->buffer[list->head].time); do_gettimeofday(&client->buffer[client->head].time);
list->buffer[list->head].type = type; client->buffer[client->head].type = type;
list->buffer[list->head].code = code; client->buffer[client->head].code = code;
list->buffer[list->head].value = value; client->buffer[client->head].value = value;
list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1); client->head = (client->head + 1) & (EVDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&client->fasync, SIGIO, POLL_IN);
} }
wake_up_interruptible(&evdev->wait); wake_up_interruptible(&evdev->wait);
...@@ -76,22 +76,23 @@ static void evdev_event(struct input_handle *handle, unsigned int type, unsigned ...@@ -76,22 +76,23 @@ static void evdev_event(struct input_handle *handle, unsigned int type, unsigned
static int evdev_fasync(int fd, struct file *file, int on) static int evdev_fasync(int fd, struct file *file, int on)
{ {
struct evdev_client *client = file->private_data;
int retval; int retval;
struct evdev_list *list = file->private_data;
retval = fasync_helper(fd, file, on, &list->fasync); retval = fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0; return retval < 0 ? retval : 0;
} }
static int evdev_flush(struct file *file, fl_owner_t id) static int evdev_flush(struct file *file, fl_owner_t id)
{ {
struct evdev_list *list = file->private_data; struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
if (!list->evdev->exist) if (!evdev->exist)
return -ENODEV; return -ENODEV;
return input_flush_device(&list->evdev->handle, file); return input_flush_device(&evdev->handle, file);
} }
static void evdev_free(struct evdev *evdev) static void evdev_free(struct evdev *evdev)
...@@ -100,48 +101,55 @@ static void evdev_free(struct evdev *evdev) ...@@ -100,48 +101,55 @@ static void evdev_free(struct evdev *evdev)
kfree(evdev); kfree(evdev);
} }
static int evdev_release(struct inode * inode, struct file * file) static int evdev_release(struct inode *inode, struct file *file)
{ {
struct evdev_list *list = file->private_data; struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
if (list->evdev->grab == list) { if (evdev->grab == client) {
input_release_device(&list->evdev->handle); input_release_device(&evdev->handle);
list->evdev->grab = NULL; evdev->grab = NULL;
} }
evdev_fasync(-1, file, 0); evdev_fasync(-1, file, 0);
list_del(&list->node); list_del(&client->node);
kfree(client);
if (!--list->evdev->open) { if (!--evdev->open) {
if (list->evdev->exist) if (evdev->exist)
input_close_device(&list->evdev->handle); input_close_device(&evdev->handle);
else else
evdev_free(list->evdev); evdev_free(evdev);
} }
kfree(list);
return 0; return 0;
} }
static int evdev_open(struct inode * inode, struct file * file) static int evdev_open(struct inode *inode, struct file *file)
{ {
struct evdev_list *list; struct evdev_client *client;
struct evdev *evdev;
int i = iminor(inode) - EVDEV_MINOR_BASE; int i = iminor(inode) - EVDEV_MINOR_BASE;
if (i >= EVDEV_MINORS || !evdev_table[i] || !evdev_table[i]->exist) if (i >= EVDEV_MINORS)
return -ENODEV;
evdev = evdev_table[i];
if (!evdev || !evdev->exist)
return -ENODEV; return -ENODEV;
if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL))) client = kzalloc(sizeof(struct evdev_client), GFP_KERNEL);
if (!client)
return -ENOMEM; return -ENOMEM;
list->evdev = evdev_table[i]; client->evdev = evdev;
list_add_tail(&list->node, &evdev_table[i]->list); list_add_tail(&client->node, &evdev->client_list);
file->private_data = list;
if (!list->evdev->open++) if (!evdev->open++ && evdev->exist)
if (list->evdev->exist) input_open_device(&evdev->handle);
input_open_device(&list->evdev->handle);
file->private_data = client;
return 0; return 0;
} }
...@@ -243,54 +251,55 @@ static int evdev_event_to_user(char __user *buffer, const struct input_event *ev ...@@ -243,54 +251,55 @@ static int evdev_event_to_user(char __user *buffer, const struct input_event *ev
#endif /* CONFIG_COMPAT */ #endif /* CONFIG_COMPAT */
static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) static ssize_t evdev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
{ {
struct evdev_list *list = file->private_data; struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
struct input_event event; struct input_event event;
int retval = 0; int retval = 0;
if (!list->evdev->exist) if (!evdev->exist)
return -ENODEV; return -ENODEV;
while (retval < count) { while (retval < count) {
if (evdev_event_from_user(buffer + retval, &event)) if (evdev_event_from_user(buffer + retval, &event))
return -EFAULT; return -EFAULT;
input_inject_event(&list->evdev->handle, event.type, event.code, event.value); input_inject_event(&evdev->handle, event.type, event.code, event.value);
retval += evdev_event_size(); retval += evdev_event_size();
} }
return retval; return retval;
} }
static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) static ssize_t evdev_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
{ {
struct evdev_list *list = file->private_data; struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
int retval; int retval;
if (count < evdev_event_size()) if (count < evdev_event_size())
return -EINVAL; return -EINVAL;
if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK)) if (client->head == client->tail && evdev->exist && (file->f_flags & O_NONBLOCK))
return -EAGAIN; return -EAGAIN;
retval = wait_event_interruptible(list->evdev->wait, retval = wait_event_interruptible(evdev->wait,
list->head != list->tail || (!list->evdev->exist)); client->head != client->tail || !evdev->exist);
if (retval) if (retval)
return retval; return retval;
if (!list->evdev->exist) if (!evdev->exist)
return -ENODEV; return -ENODEV;
while (list->head != list->tail && retval + evdev_event_size() <= count) { while (client->head != client->tail && retval + evdev_event_size() <= count) {
struct input_event *event = (struct input_event *) list->buffer + list->tail; struct input_event *event = (struct input_event *) client->buffer + client->tail;
if (evdev_event_to_user(buffer + retval, event)) if (evdev_event_to_user(buffer + retval, event))
return -EFAULT; return -EFAULT;
list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); client->tail = (client->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
retval += evdev_event_size(); retval += evdev_event_size();
} }
...@@ -300,11 +309,12 @@ static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count ...@@ -300,11 +309,12 @@ static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count
/* No kernel lock - fine */ /* No kernel lock - fine */
static unsigned int evdev_poll(struct file *file, poll_table *wait) static unsigned int evdev_poll(struct file *file, poll_table *wait)
{ {
struct evdev_list *list = file->private_data; struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
poll_wait(file, &list->evdev->wait, wait); poll_wait(file, &evdev->wait, wait);
return ((list->head == list->tail) ? 0 : (POLLIN | POLLRDNORM)) | return ((client->head == client->tail) ? 0 : (POLLIN | POLLRDNORM)) |
(list->evdev->exist ? 0 : (POLLHUP | POLLERR)); (evdev->exist ? 0 : (POLLHUP | POLLERR));
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
...@@ -387,8 +397,8 @@ static int str_to_user(const char *str, unsigned int maxlen, void __user *p) ...@@ -387,8 +397,8 @@ static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
static long evdev_ioctl_handler(struct file *file, unsigned int cmd, static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
void __user *p, int compat_mode) void __user *p, int compat_mode)
{ {
struct evdev_list *list = file->private_data; struct evdev_client *client = file->private_data;
struct evdev *evdev = list->evdev; struct evdev *evdev = client->evdev;
struct input_dev *dev = evdev->handle.dev; struct input_dev *dev = evdev->handle.dev;
struct input_absinfo abs; struct input_absinfo abs;
struct ff_effect effect; struct ff_effect effect;
...@@ -476,10 +486,10 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd, ...@@ -476,10 +486,10 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
return -EBUSY; return -EBUSY;
if (input_grab_device(&evdev->handle)) if (input_grab_device(&evdev->handle))
return -EBUSY; return -EBUSY;
evdev->grab = list; evdev->grab = client;
return 0; return 0;
} else { } else {
if (evdev->grab != list) if (evdev->grab != client)
return -EINVAL; return -EINVAL;
input_release_device(&evdev->handle); input_release_device(&evdev->handle);
evdev->grab = NULL; evdev->grab = NULL;
...@@ -624,7 +634,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -624,7 +634,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
if (!evdev) if (!evdev)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&evdev->list); INIT_LIST_HEAD(&evdev->client_list);
init_waitqueue_head(&evdev->wait); init_waitqueue_head(&evdev->wait);
evdev->exist = 1; evdev->exist = 1;
...@@ -671,7 +681,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -671,7 +681,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
static void evdev_disconnect(struct input_handle *handle) static void evdev_disconnect(struct input_handle *handle)
{ {
struct evdev *evdev = handle->private; struct evdev *evdev = handle->private;
struct evdev_list *list; struct evdev_client *client;
input_unregister_handle(handle); input_unregister_handle(handle);
...@@ -684,8 +694,8 @@ static void evdev_disconnect(struct input_handle *handle) ...@@ -684,8 +694,8 @@ static void evdev_disconnect(struct input_handle *handle)
input_flush_device(handle, NULL); input_flush_device(handle, NULL);
input_close_device(handle); input_close_device(handle);
wake_up_interruptible(&evdev->wait); wake_up_interruptible(&evdev->wait);
list_for_each_entry(list, &evdev->list, node) list_for_each_entry(client, &evdev->client_list, node)
kill_fasync(&list->fasync, SIGIO, POLL_HUP); kill_fasync(&client->fasync, SIGIO, POLL_HUP);
} else } else
evdev_free(evdev); evdev_free(evdev);
} }
......
...@@ -43,7 +43,7 @@ struct joydev { ...@@ -43,7 +43,7 @@ struct joydev {
char name[16]; char name[16];
struct input_handle handle; struct input_handle handle;
wait_queue_head_t wait; wait_queue_head_t wait;
struct list_head list; struct list_head client_list;
struct js_corr corr[ABS_MAX + 1]; struct js_corr corr[ABS_MAX + 1];
struct JS_DATA_SAVE_TYPE glue; struct JS_DATA_SAVE_TYPE glue;
int nabs; int nabs;
...@@ -55,7 +55,7 @@ struct joydev { ...@@ -55,7 +55,7 @@ struct joydev {
__s16 abs[ABS_MAX + 1]; __s16 abs[ABS_MAX + 1];
}; };
struct joydev_list { struct joydev_client {
struct js_event buffer[JOYDEV_BUFFER_SIZE]; struct js_event buffer[JOYDEV_BUFFER_SIZE];
int head; int head;
int tail; int tail;
...@@ -87,7 +87,7 @@ static int joydev_correct(int value, struct js_corr *corr) ...@@ -87,7 +87,7 @@ static int joydev_correct(int value, struct js_corr *corr)
static void joydev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) static void joydev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{ {
struct joydev *joydev = handle->private; struct joydev *joydev = handle->private;
struct joydev_list *list; struct joydev_client *client;
struct js_event event; struct js_event event;
switch (type) { switch (type) {
...@@ -115,15 +115,15 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne ...@@ -115,15 +115,15 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
event.time = jiffies_to_msecs(jiffies); event.time = jiffies_to_msecs(jiffies);
list_for_each_entry(list, &joydev->list, node) { list_for_each_entry(client, &joydev->client_list, node) {
memcpy(list->buffer + list->head, &event, sizeof(struct js_event)); memcpy(client->buffer + client->head, &event, sizeof(struct js_event));
if (list->startup == joydev->nabs + joydev->nkey) if (client->startup == joydev->nabs + joydev->nkey)
if (list->tail == (list->head = (list->head + 1) & (JOYDEV_BUFFER_SIZE - 1))) if (client->tail == (client->head = (client->head + 1) & (JOYDEV_BUFFER_SIZE - 1)))
list->startup = 0; client->startup = 0;
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&client->fasync, SIGIO, POLL_IN);
} }
wake_up_interruptible(&joydev->wait); wake_up_interruptible(&joydev->wait);
...@@ -132,9 +132,9 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne ...@@ -132,9 +132,9 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
static int joydev_fasync(int fd, struct file *file, int on) static int joydev_fasync(int fd, struct file *file, int on)
{ {
int retval; int retval;
struct joydev_list *list = file->private_data; struct joydev_client *client = file->private_data;
retval = fasync_helper(fd, file, on, &list->fasync); retval = fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0; return retval < 0 ? retval : 0;
} }
...@@ -145,60 +145,66 @@ static void joydev_free(struct joydev *joydev) ...@@ -145,60 +145,66 @@ static void joydev_free(struct joydev *joydev)
kfree(joydev); kfree(joydev);
} }
static int joydev_release(struct inode * inode, struct file * file) static int joydev_release(struct inode *inode, struct file *file)
{ {
struct joydev_list *list = file->private_data; struct joydev_client *client = file->private_data;
struct joydev *joydev = client->joydev;
joydev_fasync(-1, file, 0); joydev_fasync(-1, file, 0);
list_del(&list->node); list_del(&client->node);
kfree(client);
if (!--list->joydev->open) { if (!--joydev->open) {
if (list->joydev->exist) if (joydev->exist)
input_close_device(&list->joydev->handle); input_close_device(&joydev->handle);
else else
joydev_free(list->joydev); joydev_free(joydev);
} }
kfree(list);
return 0; return 0;
} }
static int joydev_open(struct inode *inode, struct file *file) static int joydev_open(struct inode *inode, struct file *file)
{ {
struct joydev_list *list; struct joydev_client *client;
struct joydev *joydev;
int i = iminor(inode) - JOYDEV_MINOR_BASE; int i = iminor(inode) - JOYDEV_MINOR_BASE;
if (i >= JOYDEV_MINORS || !joydev_table[i]) if (i >= JOYDEV_MINORS)
return -ENODEV;
joydev = joydev_table[i];
if (!joydev || !joydev->exist)
return -ENODEV; return -ENODEV;
if (!(list = kzalloc(sizeof(struct joydev_list), GFP_KERNEL))) client = kzalloc(sizeof(struct joydev_client), GFP_KERNEL);
if (!client)
return -ENOMEM; return -ENOMEM;
list->joydev = joydev_table[i]; client->joydev = joydev;
list_add_tail(&list->node, &joydev_table[i]->list); list_add_tail(&client->node, &joydev->client_list);
file->private_data = list;
if (!list->joydev->open++) if (!joydev->open++ && joydev->exist)
if (list->joydev->exist) input_open_device(&joydev->handle);
input_open_device(&list->joydev->handle);
file->private_data = client;
return 0; return 0;
} }
static ssize_t joydev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) static ssize_t joydev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
{ {
return -EINVAL; return -EINVAL;
} }
static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{ {
struct joydev_list *list = file->private_data; struct joydev_client *client = file->private_data;
struct joydev *joydev = list->joydev; struct joydev *joydev = client->joydev;
struct input_dev *input = joydev->handle.dev; struct input_dev *input = joydev->handle.dev;
int retval = 0; int retval = 0;
if (!list->joydev->exist) if (!joydev->exist)
return -ENODEV; return -ENODEV;
if (count < sizeof(struct js_event)) if (count < sizeof(struct js_event))
...@@ -217,56 +223,55 @@ static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, lo ...@@ -217,56 +223,55 @@ static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, lo
if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE))) if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE)))
return -EFAULT; return -EFAULT;
list->startup = 0; client->startup = 0;
list->tail = list->head; client->tail = client->head;
return sizeof(struct JS_DATA_TYPE); return sizeof(struct JS_DATA_TYPE);
} }
if (list->startup == joydev->nabs + joydev->nkey && if (client->startup == joydev->nabs + joydev->nkey &&
list->head == list->tail && (file->f_flags & O_NONBLOCK)) client->head == client->tail && (file->f_flags & O_NONBLOCK))
return -EAGAIN; return -EAGAIN;
retval = wait_event_interruptible(list->joydev->wait, retval = wait_event_interruptible(joydev->wait,
!list->joydev->exist || !joydev->exist ||
list->startup < joydev->nabs + joydev->nkey || client->startup < joydev->nabs + joydev->nkey ||
list->head != list->tail); client->head != client->tail);
if (retval) if (retval)
return retval; return retval;
if (!list->joydev->exist) if (!joydev->exist)
return -ENODEV; return -ENODEV;
while (list->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) { while (client->startup < joydev->nabs + joydev->nkey && retval + sizeof(struct js_event) <= count) {
struct js_event event; struct js_event event;
event.time = jiffies_to_msecs(jiffies); event.time = jiffies_to_msecs(jiffies);
if (list->startup < joydev->nkey) { if (client->startup < joydev->nkey) {
event.type = JS_EVENT_BUTTON | JS_EVENT_INIT; event.type = JS_EVENT_BUTTON | JS_EVENT_INIT;
event.number = list->startup; event.number = client->startup;
event.value = !!test_bit(joydev->keypam[event.number], input->key); event.value = !!test_bit(joydev->keypam[event.number], input->key);
} else { } else {
event.type = JS_EVENT_AXIS | JS_EVENT_INIT; event.type = JS_EVENT_AXIS | JS_EVENT_INIT;
event.number = list->startup - joydev->nkey; event.number = client->startup - joydev->nkey;
event.value = joydev->abs[event.number]; event.value = joydev->abs[event.number];
} }
if (copy_to_user(buf + retval, &event, sizeof(struct js_event))) if (copy_to_user(buf + retval, &event, sizeof(struct js_event)))
return -EFAULT; return -EFAULT;
list->startup++; client->startup++;
retval += sizeof(struct js_event); retval += sizeof(struct js_event);
} }
while (list->head != list->tail && retval + sizeof(struct js_event) <= count) { while (client->head != client->tail && retval + sizeof(struct js_event) <= count) {
if (copy_to_user(buf + retval, list->buffer + list->tail, sizeof(struct js_event))) if (copy_to_user(buf + retval, client->buffer + client->tail, sizeof(struct js_event)))
return -EFAULT; return -EFAULT;
list->tail = (list->tail + 1) & (JOYDEV_BUFFER_SIZE - 1); client->tail = (client->tail + 1) & (JOYDEV_BUFFER_SIZE - 1);
retval += sizeof(struct js_event); retval += sizeof(struct js_event);
} }
...@@ -276,11 +281,12 @@ static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, lo ...@@ -276,11 +281,12 @@ static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, lo
/* No kernel lock - fine */ /* No kernel lock - fine */
static unsigned int joydev_poll(struct file *file, poll_table *wait) static unsigned int joydev_poll(struct file *file, poll_table *wait)
{ {
struct joydev_list *list = file->private_data; struct joydev_client *client = file->private_data;
struct joydev *joydev = client->joydev;
poll_wait(file, &list->joydev->wait, wait); poll_wait(file, &joydev->wait, wait);
return ((list->head != list->tail || list->startup < list->joydev->nabs + list->joydev->nkey) ? return ((client->head != client->tail || client->startup < joydev->nabs + joydev->nkey) ?
(POLLIN | POLLRDNORM) : 0) | (list->joydev->exist ? 0 : (POLLHUP | POLLERR)); (POLLIN | POLLRDNORM) : 0) | (joydev->exist ? 0 : (POLLHUP | POLLERR));
} }
static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp) static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp)
...@@ -374,8 +380,8 @@ static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __u ...@@ -374,8 +380,8 @@ static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __u
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct joydev_list *list = file->private_data; struct joydev_client *client = file->private_data;
struct joydev *joydev = list->joydev; struct joydev *joydev = client->joydev;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
s32 tmp32; s32 tmp32;
struct JS_DATA_SAVE_TYPE_32 ds32; struct JS_DATA_SAVE_TYPE_32 ds32;
...@@ -428,8 +434,8 @@ static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned lo ...@@ -428,8 +434,8 @@ static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned lo
static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct joydev_list *list = file->private_data; struct joydev_client *client = file->private_data;
struct joydev *joydev = list->joydev; struct joydev *joydev = client->joydev;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
if (!joydev->exist) if (!joydev->exist)
...@@ -484,7 +490,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -484,7 +490,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
if (!joydev) if (!joydev)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&joydev->list); INIT_LIST_HEAD(&joydev->client_list);
init_waitqueue_head(&joydev->wait); init_waitqueue_head(&joydev->wait);
joydev->minor = minor; joydev->minor = minor;
...@@ -572,7 +578,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -572,7 +578,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
static void joydev_disconnect(struct input_handle *handle) static void joydev_disconnect(struct input_handle *handle)
{ {
struct joydev *joydev = handle->private; struct joydev *joydev = handle->private;
struct joydev_list *list; struct joydev_client *client;
input_unregister_handle(handle); input_unregister_handle(handle);
...@@ -583,8 +589,8 @@ static void joydev_disconnect(struct input_handle *handle) ...@@ -583,8 +589,8 @@ static void joydev_disconnect(struct input_handle *handle)
if (joydev->open) { if (joydev->open) {
input_close_device(handle); input_close_device(handle);
wake_up_interruptible(&joydev->wait); wake_up_interruptible(&joydev->wait);
list_for_each_entry(list, &joydev->list, node) list_for_each_entry(client, &joydev->client_list, node)
kill_fasync(&list->fasync, SIGIO, POLL_HUP); kill_fasync(&client->fasync, SIGIO, POLL_HUP);
} else } else
joydev_free(joydev); joydev_free(joydev);
} }
......
...@@ -63,7 +63,7 @@ struct mousedev { ...@@ -63,7 +63,7 @@ struct mousedev {
int minor; int minor;
char name[16]; char name[16];
wait_queue_head_t wait; wait_queue_head_t wait;
struct list_head list; struct list_head client_list;
struct input_handle handle; struct input_handle handle;
struct mousedev_hw_data packet; struct mousedev_hw_data packet;
...@@ -85,7 +85,7 @@ struct mousedev_motion { ...@@ -85,7 +85,7 @@ struct mousedev_motion {
}; };
#define PACKET_QUEUE_LEN 16 #define PACKET_QUEUE_LEN 16
struct mousedev_list { struct mousedev_client {
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct mousedev *mousedev; struct mousedev *mousedev;
struct list_head node; struct list_head node;
...@@ -223,47 +223,47 @@ static void mousedev_key_event(struct mousedev *mousedev, unsigned int code, int ...@@ -223,47 +223,47 @@ static void mousedev_key_event(struct mousedev *mousedev, unsigned int code, int
static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_hw_data *packet) static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_hw_data *packet)
{ {
struct mousedev_list *list; struct mousedev_client *client;
struct mousedev_motion *p; struct mousedev_motion *p;
unsigned long flags; unsigned long flags;
int wake_readers = 0; int wake_readers = 0;
list_for_each_entry(list, &mousedev->list, node) { list_for_each_entry(client, &mousedev->client_list, node) {
spin_lock_irqsave(&list->packet_lock, flags); spin_lock_irqsave(&client->packet_lock, flags);
p = &list->packets[list->head]; p = &client->packets[client->head];
if (list->ready && p->buttons != mousedev->packet.buttons) { if (client->ready && p->buttons != mousedev->packet.buttons) {
unsigned int new_head = (list->head + 1) % PACKET_QUEUE_LEN; unsigned int new_head = (client->head + 1) % PACKET_QUEUE_LEN;
if (new_head != list->tail) { if (new_head != client->tail) {
p = &list->packets[list->head = new_head]; p = &client->packets[client->head = new_head];
memset(p, 0, sizeof(struct mousedev_motion)); memset(p, 0, sizeof(struct mousedev_motion));
} }
} }
if (packet->abs_event) { if (packet->abs_event) {
p->dx += packet->x - list->pos_x; p->dx += packet->x - client->pos_x;
p->dy += packet->y - list->pos_y; p->dy += packet->y - client->pos_y;
list->pos_x = packet->x; client->pos_x = packet->x;
list->pos_y = packet->y; client->pos_y = packet->y;
} }
list->pos_x += packet->dx; client->pos_x += packet->dx;
list->pos_x = list->pos_x < 0 ? 0 : (list->pos_x >= xres ? xres : list->pos_x); client->pos_x = client->pos_x < 0 ? 0 : (client->pos_x >= xres ? xres : client->pos_x);
list->pos_y += packet->dy; client->pos_y += packet->dy;
list->pos_y = list->pos_y < 0 ? 0 : (list->pos_y >= yres ? yres : list->pos_y); client->pos_y = client->pos_y < 0 ? 0 : (client->pos_y >= yres ? yres : client->pos_y);
p->dx += packet->dx; p->dx += packet->dx;
p->dy += packet->dy; p->dy += packet->dy;
p->dz += packet->dz; p->dz += packet->dz;
p->buttons = mousedev->packet.buttons; p->buttons = mousedev->packet.buttons;
if (p->dx || p->dy || p->dz || p->buttons != list->last_buttons) if (p->dx || p->dy || p->dz || p->buttons != client->last_buttons)
list->ready = 1; client->ready = 1;
spin_unlock_irqrestore(&list->packet_lock, flags); spin_unlock_irqrestore(&client->packet_lock, flags);
if (list->ready) { if (client->ready) {
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&client->fasync, SIGIO, POLL_IN);
wake_readers = 1; wake_readers = 1;
} }
} }
...@@ -351,9 +351,9 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig ...@@ -351,9 +351,9 @@ static void mousedev_event(struct input_handle *handle, unsigned int type, unsig
static int mousedev_fasync(int fd, struct file *file, int on) static int mousedev_fasync(int fd, struct file *file, int on)
{ {
int retval; int retval;
struct mousedev_list *list = file->private_data; struct mousedev_client *client = file->private_data;
retval = fasync_helper(fd, file, on, &list->fasync); retval = fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0; return retval < 0 ? retval : 0;
} }
...@@ -380,32 +380,33 @@ static void mixdev_release(void) ...@@ -380,32 +380,33 @@ static void mixdev_release(void)
} }
} }
static int mousedev_release(struct inode * inode, struct file * file) static int mousedev_release(struct inode *inode, struct file *file)
{ {
struct mousedev_list *list = file->private_data; struct mousedev_client *client = file->private_data;
struct mousedev *mousedev = client->mousedev;
mousedev_fasync(-1, file, 0); mousedev_fasync(-1, file, 0);
list_del(&list->node); list_del(&client->node);
kfree(client);
if (!--list->mousedev->open) { if (!--mousedev->open) {
if (list->mousedev->minor == MOUSEDEV_MIX) if (mousedev->minor == MOUSEDEV_MIX)
mixdev_release(); mixdev_release();
else if (!mousedev_mix.open) { else if (!mousedev_mix.open) {
if (list->mousedev->exist) if (mousedev->exist)
input_close_device(&list->mousedev->handle); input_close_device(&mousedev->handle);
else else
mousedev_free(list->mousedev); mousedev_free(mousedev);
} }
} }
kfree(list);
return 0; return 0;
} }
static int mousedev_open(struct inode * inode, struct file * file) static int mousedev_open(struct inode *inode, struct file *file)
{ {
struct mousedev_list *list; struct mousedev_client *client;
struct input_handle *handle; struct input_handle *handle;
struct mousedev *mousedev; struct mousedev *mousedev;
int i; int i;
...@@ -417,31 +418,36 @@ static int mousedev_open(struct inode * inode, struct file * file) ...@@ -417,31 +418,36 @@ static int mousedev_open(struct inode * inode, struct file * file)
#endif #endif
i = iminor(inode) - MOUSEDEV_MINOR_BASE; i = iminor(inode) - MOUSEDEV_MINOR_BASE;
if (i >= MOUSEDEV_MINORS || !mousedev_table[i]) if (i >= MOUSEDEV_MINORS)
return -ENODEV;
mousedev = mousedev_table[i];
if (!mousedev)
return -ENODEV; return -ENODEV;
if (!(list = kzalloc(sizeof(struct mousedev_list), GFP_KERNEL))) client = kzalloc(sizeof(struct mousedev_client), GFP_KERNEL);
if (!client)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&list->packet_lock); spin_lock_init(&client->packet_lock);
list->pos_x = xres / 2; client->pos_x = xres / 2;
list->pos_y = yres / 2; client->pos_y = yres / 2;
list->mousedev = mousedev_table[i]; client->mousedev = mousedev;
list_add_tail(&list->node, &mousedev_table[i]->list); list_add_tail(&client->node, &mousedev->client_list);
file->private_data = list;
if (!list->mousedev->open++) { if (!mousedev->open++) {
if (list->mousedev->minor == MOUSEDEV_MIX) { if (mousedev->minor == MOUSEDEV_MIX) {
list_for_each_entry(handle, &mousedev_handler.h_list, h_node) { list_for_each_entry(handle, &mousedev_handler.h_list, h_node) {
mousedev = handle->private; struct mousedev *md = handle->private;
if (!mousedev->open && mousedev->exist) if (!md->open && md->exist)
input_open_device(handle); input_open_device(handle);
} }
} else } else
if (!mousedev_mix.open && list->mousedev->exist) if (!mousedev_mix.open && mousedev->exist)
input_open_device(&list->mousedev->handle); input_open_device(&mousedev->handle);
} }
file->private_data = client;
return 0; return 0;
} }
...@@ -450,13 +456,13 @@ static inline int mousedev_limit_delta(int delta, int limit) ...@@ -450,13 +456,13 @@ static inline int mousedev_limit_delta(int delta, int limit)
return delta > limit ? limit : (delta < -limit ? -limit : delta); return delta > limit ? limit : (delta < -limit ? -limit : delta);
} }
static void mousedev_packet(struct mousedev_list *list, signed char *ps2_data) static void mousedev_packet(struct mousedev_client *client, signed char *ps2_data)
{ {
struct mousedev_motion *p; struct mousedev_motion *p;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&list->packet_lock, flags); spin_lock_irqsave(&client->packet_lock, flags);
p = &list->packets[list->tail]; p = &client->packets[client->tail];
ps2_data[0] = 0x08 | ((p->dx < 0) << 4) | ((p->dy < 0) << 5) | (p->buttons & 0x07); ps2_data[0] = 0x08 | ((p->dx < 0) << 4) | ((p->dy < 0) << 5) | (p->buttons & 0x07);
ps2_data[1] = mousedev_limit_delta(p->dx, 127); ps2_data[1] = mousedev_limit_delta(p->dx, 127);
...@@ -464,44 +470,44 @@ static void mousedev_packet(struct mousedev_list *list, signed char *ps2_data) ...@@ -464,44 +470,44 @@ static void mousedev_packet(struct mousedev_list *list, signed char *ps2_data)
p->dx -= ps2_data[1]; p->dx -= ps2_data[1];
p->dy -= ps2_data[2]; p->dy -= ps2_data[2];
switch (list->mode) { switch (client->mode) {
case MOUSEDEV_EMUL_EXPS: case MOUSEDEV_EMUL_EXPS:
ps2_data[3] = mousedev_limit_delta(p->dz, 7); ps2_data[3] = mousedev_limit_delta(p->dz, 7);
p->dz -= ps2_data[3]; p->dz -= ps2_data[3];
ps2_data[3] = (ps2_data[3] & 0x0f) | ((p->buttons & 0x18) << 1); ps2_data[3] = (ps2_data[3] & 0x0f) | ((p->buttons & 0x18) << 1);
list->bufsiz = 4; client->bufsiz = 4;
break; break;
case MOUSEDEV_EMUL_IMPS: case MOUSEDEV_EMUL_IMPS:
ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1); ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1);
ps2_data[3] = mousedev_limit_delta(p->dz, 127); ps2_data[3] = mousedev_limit_delta(p->dz, 127);
p->dz -= ps2_data[3]; p->dz -= ps2_data[3];
list->bufsiz = 4; client->bufsiz = 4;
break; break;
case MOUSEDEV_EMUL_PS2: case MOUSEDEV_EMUL_PS2:
default: default:
ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1); ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1);
p->dz = 0; p->dz = 0;
list->bufsiz = 3; client->bufsiz = 3;
break; break;
} }
if (!p->dx && !p->dy && !p->dz) { if (!p->dx && !p->dy && !p->dz) {
if (list->tail == list->head) { if (client->tail == client->head) {
list->ready = 0; client->ready = 0;
list->last_buttons = p->buttons; client->last_buttons = p->buttons;
} else } else
list->tail = (list->tail + 1) % PACKET_QUEUE_LEN; client->tail = (client->tail + 1) % PACKET_QUEUE_LEN;
} }
spin_unlock_irqrestore(&list->packet_lock, flags); spin_unlock_irqrestore(&client->packet_lock, flags);
} }
static ssize_t mousedev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) static ssize_t mousedev_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
{ {
struct mousedev_list *list = file->private_data; struct mousedev_client *client = file->private_data;
unsigned char c; unsigned char c;
unsigned int i; unsigned int i;
...@@ -510,95 +516,95 @@ static ssize_t mousedev_write(struct file * file, const char __user * buffer, si ...@@ -510,95 +516,95 @@ static ssize_t mousedev_write(struct file * file, const char __user * buffer, si
if (get_user(c, buffer + i)) if (get_user(c, buffer + i))
return -EFAULT; return -EFAULT;
if (c == mousedev_imex_seq[list->imexseq]) { if (c == mousedev_imex_seq[client->imexseq]) {
if (++list->imexseq == MOUSEDEV_SEQ_LEN) { if (++client->imexseq == MOUSEDEV_SEQ_LEN) {
list->imexseq = 0; client->imexseq = 0;
list->mode = MOUSEDEV_EMUL_EXPS; client->mode = MOUSEDEV_EMUL_EXPS;
} }
} else } else
list->imexseq = 0; client->imexseq = 0;
if (c == mousedev_imps_seq[list->impsseq]) { if (c == mousedev_imps_seq[client->impsseq]) {
if (++list->impsseq == MOUSEDEV_SEQ_LEN) { if (++client->impsseq == MOUSEDEV_SEQ_LEN) {
list->impsseq = 0; client->impsseq = 0;
list->mode = MOUSEDEV_EMUL_IMPS; client->mode = MOUSEDEV_EMUL_IMPS;
} }
} else } else
list->impsseq = 0; client->impsseq = 0;
list->ps2[0] = 0xfa; client->ps2[0] = 0xfa;
switch (c) { switch (c) {
case 0xeb: /* Poll */ case 0xeb: /* Poll */
mousedev_packet(list, &list->ps2[1]); mousedev_packet(client, &client->ps2[1]);
list->bufsiz++; /* account for leading ACK */ client->bufsiz++; /* account for leading ACK */
break; break;
case 0xf2: /* Get ID */ case 0xf2: /* Get ID */
switch (list->mode) { switch (client->mode) {
case MOUSEDEV_EMUL_PS2: list->ps2[1] = 0; break; case MOUSEDEV_EMUL_PS2: client->ps2[1] = 0; break;
case MOUSEDEV_EMUL_IMPS: list->ps2[1] = 3; break; case MOUSEDEV_EMUL_IMPS: client->ps2[1] = 3; break;
case MOUSEDEV_EMUL_EXPS: list->ps2[1] = 4; break; case MOUSEDEV_EMUL_EXPS: client->ps2[1] = 4; break;
} }
list->bufsiz = 2; client->bufsiz = 2;
break; break;
case 0xe9: /* Get info */ case 0xe9: /* Get info */
list->ps2[1] = 0x60; list->ps2[2] = 3; list->ps2[3] = 200; client->ps2[1] = 0x60; client->ps2[2] = 3; client->ps2[3] = 200;
list->bufsiz = 4; client->bufsiz = 4;
break; break;
case 0xff: /* Reset */ case 0xff: /* Reset */
list->impsseq = list->imexseq = 0; client->impsseq = client->imexseq = 0;
list->mode = MOUSEDEV_EMUL_PS2; client->mode = MOUSEDEV_EMUL_PS2;
list->ps2[1] = 0xaa; list->ps2[2] = 0x00; client->ps2[1] = 0xaa; client->ps2[2] = 0x00;
list->bufsiz = 3; client->bufsiz = 3;
break; break;
default: default:
list->bufsiz = 1; client->bufsiz = 1;
break; break;
} }
list->buffer = list->bufsiz; client->buffer = client->bufsiz;
} }
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&client->fasync, SIGIO, POLL_IN);
wake_up_interruptible(&list->mousedev->wait); wake_up_interruptible(&client->mousedev->wait);
return count; return count;
} }
static ssize_t mousedev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) static ssize_t mousedev_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
{ {
struct mousedev_list *list = file->private_data; struct mousedev_client *client = file->private_data;
int retval = 0; int retval = 0;
if (!list->ready && !list->buffer && (file->f_flags & O_NONBLOCK)) if (!client->ready && !client->buffer && (file->f_flags & O_NONBLOCK))
return -EAGAIN; return -EAGAIN;
retval = wait_event_interruptible(list->mousedev->wait, retval = wait_event_interruptible(client->mousedev->wait,
!list->mousedev->exist || list->ready || list->buffer); !client->mousedev->exist || client->ready || client->buffer);
if (retval) if (retval)
return retval; return retval;
if (!list->mousedev->exist) if (!client->mousedev->exist)
return -ENODEV; return -ENODEV;
if (!list->buffer && list->ready) { if (!client->buffer && client->ready) {
mousedev_packet(list, list->ps2); mousedev_packet(client, client->ps2);
list->buffer = list->bufsiz; client->buffer = client->bufsiz;
} }
if (count > list->buffer) if (count > client->buffer)
count = list->buffer; count = client->buffer;
list->buffer -= count; client->buffer -= count;
if (copy_to_user(buffer, list->ps2 + list->bufsiz - list->buffer - count, count)) if (copy_to_user(buffer, client->ps2 + client->bufsiz - client->buffer - count, count))
return -EFAULT; return -EFAULT;
return count; return count;
...@@ -607,11 +613,12 @@ static ssize_t mousedev_read(struct file * file, char __user * buffer, size_t co ...@@ -607,11 +613,12 @@ static ssize_t mousedev_read(struct file * file, char __user * buffer, size_t co
/* No kernel lock - fine */ /* No kernel lock - fine */
static unsigned int mousedev_poll(struct file *file, poll_table *wait) static unsigned int mousedev_poll(struct file *file, poll_table *wait)
{ {
struct mousedev_list *list = file->private_data; struct mousedev_client *client = file->private_data;
struct mousedev *mousedev = client->mousedev;
poll_wait(file, &list->mousedev->wait, wait); poll_wait(file, &mousedev->wait, wait);
return ((list->ready || list->buffer) ? (POLLIN | POLLRDNORM) : 0) | return ((client->ready || client->buffer) ? (POLLIN | POLLRDNORM) : 0) |
(list->mousedev->exist ? 0 : (POLLHUP | POLLERR)); (mousedev->exist ? 0 : (POLLHUP | POLLERR));
} }
static const struct file_operations mousedev_fops = { static const struct file_operations mousedev_fops = {
...@@ -643,7 +650,7 @@ static int mousedev_connect(struct input_handler *handler, struct input_dev *dev ...@@ -643,7 +650,7 @@ static int mousedev_connect(struct input_handler *handler, struct input_dev *dev
if (!mousedev) if (!mousedev)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&mousedev->list); INIT_LIST_HEAD(&mousedev->client_list);
INIT_LIST_HEAD(&mousedev->mixdev_node); INIT_LIST_HEAD(&mousedev->mixdev_node);
init_waitqueue_head(&mousedev->wait); init_waitqueue_head(&mousedev->wait);
...@@ -699,7 +706,7 @@ static int mousedev_connect(struct input_handler *handler, struct input_dev *dev ...@@ -699,7 +706,7 @@ static int mousedev_connect(struct input_handler *handler, struct input_dev *dev
static void mousedev_disconnect(struct input_handle *handle) static void mousedev_disconnect(struct input_handle *handle)
{ {
struct mousedev *mousedev = handle->private; struct mousedev *mousedev = handle->private;
struct mousedev_list *list; struct mousedev_client *client;
input_unregister_handle(handle); input_unregister_handle(handle);
...@@ -711,8 +718,8 @@ static void mousedev_disconnect(struct input_handle *handle) ...@@ -711,8 +718,8 @@ static void mousedev_disconnect(struct input_handle *handle)
if (mousedev->open) { if (mousedev->open) {
input_close_device(handle); input_close_device(handle);
wake_up_interruptible(&mousedev->wait); wake_up_interruptible(&mousedev->wait);
list_for_each_entry(list, &mousedev->list, node) list_for_each_entry(client, &mousedev->client_list, node)
kill_fasync(&list->fasync, SIGIO, POLL_HUP); kill_fasync(&client->fasync, SIGIO, POLL_HUP);
} else { } else {
if (mousedev_mix.open) if (mousedev_mix.open)
input_close_device(handle); input_close_device(handle);
...@@ -745,7 +752,7 @@ static const struct input_device_id mousedev_ids[] = { ...@@ -745,7 +752,7 @@ static const struct input_device_id mousedev_ids[] = {
.absbit = { BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) | BIT(ABS_TOOL_WIDTH) }, .absbit = { BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) | BIT(ABS_TOOL_WIDTH) },
}, /* A touchpad */ }, /* A touchpad */
{ }, /* Terminating entry */ { }, /* Terminating entry */
}; };
MODULE_DEVICE_TABLE(input, mousedev_ids); MODULE_DEVICE_TABLE(input, mousedev_ids);
...@@ -777,7 +784,7 @@ static int __init mousedev_init(void) ...@@ -777,7 +784,7 @@ static int __init mousedev_init(void)
return error; return error;
memset(&mousedev_mix, 0, sizeof(struct mousedev)); memset(&mousedev_mix, 0, sizeof(struct mousedev));
INIT_LIST_HEAD(&mousedev_mix.list); INIT_LIST_HEAD(&mousedev_mix.client_list);
init_waitqueue_head(&mousedev_mix.wait); init_waitqueue_head(&mousedev_mix.wait);
mousedev_table[MOUSEDEV_MIX] = &mousedev_mix; mousedev_table[MOUSEDEV_MIX] = &mousedev_mix;
mousedev_mix.exist = 1; mousedev_mix.exist = 1;
......
...@@ -111,13 +111,13 @@ struct tsdev { ...@@ -111,13 +111,13 @@ struct tsdev {
int minor; int minor;
char name[8]; char name[8];
wait_queue_head_t wait; wait_queue_head_t wait;
struct list_head list; struct list_head client_list;
struct input_handle handle; struct input_handle handle;
int x, y, pressure; int x, y, pressure;
struct ts_calibration cal; struct ts_calibration cal;
}; };
struct tsdev_list { struct tsdev_client {
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct list_head node; struct list_head node;
struct tsdev *tsdev; struct tsdev *tsdev;
...@@ -139,17 +139,18 @@ static struct tsdev *tsdev_table[TSDEV_MINORS/2]; ...@@ -139,17 +139,18 @@ static struct tsdev *tsdev_table[TSDEV_MINORS/2];
static int tsdev_fasync(int fd, struct file *file, int on) static int tsdev_fasync(int fd, struct file *file, int on)
{ {
struct tsdev_list *list = file->private_data; struct tsdev_client *client = file->private_data;
int retval; int retval;
retval = fasync_helper(fd, file, on, &list->fasync); retval = fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0; return retval < 0 ? retval : 0;
} }
static int tsdev_open(struct inode *inode, struct file *file) static int tsdev_open(struct inode *inode, struct file *file)
{ {
int i = iminor(inode) - TSDEV_MINOR_BASE; int i = iminor(inode) - TSDEV_MINOR_BASE;
struct tsdev_list *list; struct tsdev_client *client;
struct tsdev *tsdev;
printk(KERN_WARNING "tsdev (compaq touchscreen emulation) is scheduled " printk(KERN_WARNING "tsdev (compaq touchscreen emulation) is scheduled "
"for removal.\nSee Documentation/feature-removal-schedule.txt " "for removal.\nSee Documentation/feature-removal-schedule.txt "
...@@ -158,19 +159,22 @@ static int tsdev_open(struct inode *inode, struct file *file) ...@@ -158,19 +159,22 @@ static int tsdev_open(struct inode *inode, struct file *file)
if (i >= TSDEV_MINORS) if (i >= TSDEV_MINORS)
return -ENODEV; return -ENODEV;
if (!(list = kzalloc(sizeof(struct tsdev_list), GFP_KERNEL))) tsdev = tsdev_table[i & TSDEV_MINOR_MASK];
if (!tsdev || !tsdev->exist)
return -ENODEV;
client = kzalloc(sizeof(struct tsdev_client), GFP_KERNEL);
if (!client)
return -ENOMEM; return -ENOMEM;
list->raw = (i >= TSDEV_MINORS/2) ? 1 : 0; client->tsdev = tsdev;
client->raw = (i >= TSDEV_MINORS / 2) ? 1 : 0;
list_add_tail(&client->node, &tsdev->client_list);
i &= TSDEV_MINOR_MASK; if (!tsdev->open++ && tsdev->exist)
list->tsdev = tsdev_table[i]; input_open_device(&tsdev->handle);
list_add_tail(&list->node, &tsdev_table[i]->list);
file->private_data = list;
if (!list->tsdev->open++) file->private_data = client;
if (list->tsdev->exist)
input_open_device(&list->tsdev->handle);
return 0; return 0;
} }
...@@ -182,45 +186,48 @@ static void tsdev_free(struct tsdev *tsdev) ...@@ -182,45 +186,48 @@ static void tsdev_free(struct tsdev *tsdev)
static int tsdev_release(struct inode *inode, struct file *file) static int tsdev_release(struct inode *inode, struct file *file)
{ {
struct tsdev_list *list = file->private_data; struct tsdev_client *client = file->private_data;
struct tsdev *tsdev = client->tsdev;
tsdev_fasync(-1, file, 0); tsdev_fasync(-1, file, 0);
list_del(&list->node);
if (!--list->tsdev->open) { list_del(&client->node);
if (list->tsdev->exist) kfree(client);
input_close_device(&list->tsdev->handle);
if (!--tsdev->open) {
if (tsdev->exist)
input_close_device(&tsdev->handle);
else else
tsdev_free(list->tsdev); tsdev_free(tsdev);
} }
kfree(list);
return 0; return 0;
} }
static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count, static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count,
loff_t * ppos) loff_t *ppos)
{ {
struct tsdev_list *list = file->private_data; struct tsdev_client *client = file->private_data;
struct tsdev *tsdev = client->tsdev;
int retval = 0; int retval = 0;
if (list->head == list->tail && list->tsdev->exist && (file->f_flags & O_NONBLOCK)) if (client->head == client->tail && tsdev->exist && (file->f_flags & O_NONBLOCK))
return -EAGAIN; return -EAGAIN;
retval = wait_event_interruptible(list->tsdev->wait, retval = wait_event_interruptible(tsdev->wait,
list->head != list->tail || !list->tsdev->exist); client->head != client->tail || !tsdev->exist);
if (retval) if (retval)
return retval; return retval;
if (!list->tsdev->exist) if (!tsdev->exist)
return -ENODEV; return -ENODEV;
while (list->head != list->tail && while (client->head != client->tail &&
retval + sizeof (struct ts_event) <= count) { retval + sizeof (struct ts_event) <= count) {
if (copy_to_user (buffer + retval, list->event + list->tail, if (copy_to_user (buffer + retval, client->event + client->tail,
sizeof (struct ts_event))) sizeof (struct ts_event)))
return -EFAULT; return -EFAULT;
list->tail = (list->tail + 1) & (TSDEV_BUFFER_SIZE - 1); client->tail = (client->tail + 1) & (TSDEV_BUFFER_SIZE - 1);
retval += sizeof (struct ts_event); retval += sizeof (struct ts_event);
} }
...@@ -228,20 +235,21 @@ static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count, ...@@ -228,20 +235,21 @@ static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count,
} }
/* No kernel lock - fine */ /* No kernel lock - fine */
static unsigned int tsdev_poll(struct file *file, poll_table * wait) static unsigned int tsdev_poll(struct file *file, poll_table *wait)
{ {
struct tsdev_list *list = file->private_data; struct tsdev_client *client = file->private_data;
struct tsdev *tsdev = client->tsdev;
poll_wait(file, &list->tsdev->wait, wait); poll_wait(file, &tsdev->wait, wait);
return ((list->head == list->tail) ? 0 : (POLLIN | POLLRDNORM)) | return ((client->head == client->tail) ? 0 : (POLLIN | POLLRDNORM)) |
(list->tsdev->exist ? 0 : (POLLHUP | POLLERR)); (tsdev->exist ? 0 : (POLLHUP | POLLERR));
} }
static int tsdev_ioctl(struct inode *inode, struct file *file, static int tsdev_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct tsdev_list *list = file->private_data; struct tsdev_client *client = file->private_data;
struct tsdev *tsdev = list->tsdev; struct tsdev *tsdev = client->tsdev;
int retval = 0; int retval = 0;
switch (cmd) { switch (cmd) {
...@@ -279,7 +287,7 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -279,7 +287,7 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
unsigned int code, int value) unsigned int code, int value)
{ {
struct tsdev *tsdev = handle->private; struct tsdev *tsdev = handle->private;
struct tsdev_list *list; struct tsdev_client *client;
struct timeval time; struct timeval time;
switch (type) { switch (type) {
...@@ -343,18 +351,18 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -343,18 +351,18 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
if (type != EV_SYN || code != SYN_REPORT) if (type != EV_SYN || code != SYN_REPORT)
return; return;
list_for_each_entry(list, &tsdev->list, node) { list_for_each_entry(client, &tsdev->client_list, node) {
int x, y, tmp; int x, y, tmp;
do_gettimeofday(&time); do_gettimeofday(&time);
list->event[list->head].millisecs = time.tv_usec / 100; client->event[client->head].millisecs = time.tv_usec / 100;
list->event[list->head].pressure = tsdev->pressure; client->event[client->head].pressure = tsdev->pressure;
x = tsdev->x; x = tsdev->x;
y = tsdev->y; y = tsdev->y;
/* Calibration */ /* Calibration */
if (!list->raw) { if (!client->raw) {
x = ((x * tsdev->cal.xscale) >> 8) + tsdev->cal.xtrans; x = ((x * tsdev->cal.xscale) >> 8) + tsdev->cal.xtrans;
y = ((y * tsdev->cal.yscale) >> 8) + tsdev->cal.ytrans; y = ((y * tsdev->cal.yscale) >> 8) + tsdev->cal.ytrans;
if (tsdev->cal.xyswap) { if (tsdev->cal.xyswap) {
...@@ -362,10 +370,10 @@ static void tsdev_event(struct input_handle *handle, unsigned int type, ...@@ -362,10 +370,10 @@ static void tsdev_event(struct input_handle *handle, unsigned int type,
} }
} }
list->event[list->head].x = x; client->event[client->head].x = x;
list->event[list->head].y = y; client->event[client->head].y = y;
list->head = (list->head + 1) & (TSDEV_BUFFER_SIZE - 1); client->head = (client->head + 1) & (TSDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN); kill_fasync(&client->fasync, SIGIO, POLL_IN);
} }
wake_up_interruptible(&tsdev->wait); wake_up_interruptible(&tsdev->wait);
} }
...@@ -390,7 +398,7 @@ static int tsdev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -390,7 +398,7 @@ static int tsdev_connect(struct input_handler *handler, struct input_dev *dev,
if (!tsdev) if (!tsdev)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&tsdev->list); INIT_LIST_HEAD(&tsdev->client_list);
init_waitqueue_head(&tsdev->wait); init_waitqueue_head(&tsdev->wait);
sprintf(tsdev->name, "ts%d", minor); sprintf(tsdev->name, "ts%d", minor);
...@@ -451,7 +459,7 @@ static int tsdev_connect(struct input_handler *handler, struct input_dev *dev, ...@@ -451,7 +459,7 @@ static int tsdev_connect(struct input_handler *handler, struct input_dev *dev,
static void tsdev_disconnect(struct input_handle *handle) static void tsdev_disconnect(struct input_handle *handle)
{ {
struct tsdev *tsdev = handle->private; struct tsdev *tsdev = handle->private;
struct tsdev_list *list; struct tsdev_client *client;
input_unregister_handle(handle); input_unregister_handle(handle);
...@@ -463,8 +471,8 @@ static void tsdev_disconnect(struct input_handle *handle) ...@@ -463,8 +471,8 @@ static void tsdev_disconnect(struct input_handle *handle)
if (tsdev->open) { if (tsdev->open) {
input_close_device(handle); input_close_device(handle);
wake_up_interruptible(&tsdev->wait); wake_up_interruptible(&tsdev->wait);
list_for_each_entry(list, &tsdev->list, node) list_for_each_entry(client, &tsdev->client_list, node)
kill_fasync(&list->fasync, SIGIO, POLL_HUP); kill_fasync(&client->fasync, SIGIO, POLL_HUP);
} else } else
tsdev_free(tsdev); tsdev_free(tsdev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment