Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 328516
b: refs/heads/master
c: 22ae19c
h: refs/heads/master
v: v3
  • Loading branch information
Dmitry Torokhov committed Aug 22, 2012
1 parent 7c99865 commit cbe4af4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 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: f40033acc2d14acecd1b27a79dc8a0ad437e619a
refs/heads/master: 22ae19c6e3c22b390952e90f452f26adad9b8687
74 changes: 44 additions & 30 deletions trunk/drivers/input/misc/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t
struct uinput_device *udev = file->private_data;
int retval;

if (count == 0)
return 0;

retval = mutex_lock_interruptible(&udev->mutex);
if (retval)
return retval;
Expand Down Expand Up @@ -470,48 +473,59 @@ static bool uinput_fetch_next_event(struct uinput_device *udev,
return have_event;
}

static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
static ssize_t uinput_events_to_user(struct uinput_device *udev,
char __user *buffer, size_t count)
{
struct uinput_device *udev = file->private_data;
struct input_event event;
int retval = 0;
size_t read = 0;
int error = 0;

if (count != 0 && count < input_event_size())
return -EINVAL;
while (read + input_event_size() <= count &&
uinput_fetch_next_event(udev, &event)) {

if (udev->state != UIST_CREATED)
return -ENODEV;
if (input_event_to_user(buffer + read, &event)) {
error = -EFAULT;
break;
}

if (udev->head == udev->tail && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
read += input_event_size();
}

retval = wait_event_interruptible(udev->waitq,
udev->head != udev->tail || udev->state != UIST_CREATED);
if (retval)
return retval;
return read ?: error;
}

retval = mutex_lock_interruptible(&udev->mutex);
if (retval)
return retval;
static ssize_t uinput_read(struct file *file, char __user *buffer,
size_t count, loff_t *ppos)
{
struct uinput_device *udev = file->private_data;
ssize_t retval;

if (udev->state != UIST_CREATED) {
retval = -ENODEV;
goto out;
}
if (count != 0 && count < input_event_size())
return -EINVAL;

while (retval + input_event_size() <= count &&
uinput_fetch_next_event(udev, &event)) {
do {
retval = mutex_lock_interruptible(&udev->mutex);
if (retval)
return retval;

if (input_event_to_user(buffer + retval, &event)) {
retval = -EFAULT;
goto out;
}
if (udev->state != UIST_CREATED)
retval = -ENODEV;
else if (udev->head == udev->tail &&
(file->f_flags & O_NONBLOCK))
retval = -EAGAIN;
else
retval = uinput_events_to_user(udev, buffer, count);

retval += input_event_size();
}
mutex_unlock(&udev->mutex);

out:
mutex_unlock(&udev->mutex);
if (retval || count == 0)
break;

if (!(file->f_flags & O_NONBLOCK))
retval = wait_event_interruptible(udev->waitq,
udev->head != udev->tail ||
udev->state != UIST_CREATED);
} while (retval == 0);

return retval;
}
Expand Down

0 comments on commit cbe4af4

Please sign in to comment.