Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 306608
b: refs/heads/master
c: 2872a9b
h: refs/heads/master
v: v3
  • Loading branch information
Dmitry Torokhov committed May 2, 2012
1 parent 8a843a8 commit a2650c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 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: dba4258068f822b7dafc78c28fe9c99c551eca7e
refs/heads/master: 2872a9b521ac936c7a8525a8c2bdfb9b4ccf5cfc
61 changes: 38 additions & 23 deletions trunk/drivers/input/evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
struct input_event event;
int retval = 0;

if (count < input_event_size())
if (count != 0 && count < input_event_size())
return -EINVAL;

retval = mutex_lock_interruptible(&evdev->mutex);
Expand All @@ -357,7 +357,8 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
goto out;
}

do {
while (retval + input_event_size() <= count) {

if (input_event_from_user(buffer + retval, &event)) {
retval = -EFAULT;
goto out;
Expand All @@ -366,7 +367,7 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,

input_inject_event(&evdev->handle,
event.type, event.code, event.value);
} while (retval + input_event_size() <= count);
}

out:
mutex_unlock(&evdev->mutex);
Expand Down Expand Up @@ -397,35 +398,49 @@ static ssize_t evdev_read(struct file *file, char __user *buffer,
struct evdev_client *client = file->private_data;
struct evdev *evdev = client->evdev;
struct input_event event;
int retval = 0;
size_t read = 0;
int error;

if (count < input_event_size())
if (count != 0 && count < input_event_size())
return -EINVAL;

if (!(file->f_flags & O_NONBLOCK)) {
retval = wait_event_interruptible(evdev->wait,
client->packet_head != client->tail ||
!evdev->exist);
if (retval)
return retval;
}
for (;;) {
if (!evdev->exist)
return -ENODEV;

if (!evdev->exist)
return -ENODEV;
if (client->packet_head == client->tail &&
(file->f_flags & O_NONBLOCK))
return -EAGAIN;

/*
* count == 0 is special - no IO is done but we check
* for error conditions (see above).
*/
if (count == 0)
break;

while (retval + input_event_size() <= count &&
evdev_fetch_next_event(client, &event)) {
while (read + input_event_size() <= count &&
evdev_fetch_next_event(client, &event)) {

if (input_event_to_user(buffer + retval, &event))
return -EFAULT;
if (input_event_to_user(buffer + read, &event))
return -EFAULT;

retval += input_event_size();
}
read += input_event_size();
}

if (retval == 0 && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
if (read)
break;

return retval;
if (!(file->f_flags & O_NONBLOCK)) {
error = wait_event_interruptible(evdev->wait,
client->packet_head != client->tail ||
!evdev->exist);
if (error)
return error;
}
}

return read;
}

/* No kernel lock - fine */
Expand Down

0 comments on commit a2650c5

Please sign in to comment.