Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 328514
b: refs/heads/master
c: 929d1af
h: refs/heads/master
v: v3
  • Loading branch information
Dmitry Torokhov committed Aug 22, 2012
1 parent 99aa3e4 commit 5d0140c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 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: c0bb1f975ca06b17d595937c5e91578b36047039
refs/heads/master: 929d1af5478dec82903e05aa9662a4ec12ad655b
27 changes: 24 additions & 3 deletions trunk/drivers/input/misc/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,28 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t
return retval;
}

static bool uinput_fetch_next_event(struct uinput_device *udev,
struct input_event *event)
{
bool have_event;

spin_lock_irq(&udev->dev->event_lock);

have_event = udev->head != udev->tail;
if (have_event) {
*event = udev->buff[udev->tail];
udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE;
}

spin_unlock_irq(&udev->dev->event_lock);

return have_event;
}

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

if (udev->state != UIST_CREATED)
Expand All @@ -477,12 +496,14 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count,
goto out;
}

while (udev->head != udev->tail && retval + input_event_size() <= count) {
if (input_event_to_user(buffer + retval, &udev->buff[udev->tail])) {
while (retval + input_event_size() <= count &&
uinput_fetch_next_event(udev, &event)) {

if (input_event_to_user(buffer + retval, &event)) {
retval = -EFAULT;
goto out;
}
udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE;

retval += input_event_size();
}

Expand Down

0 comments on commit 5d0140c

Please sign in to comment.