Skip to content

Commit

Permalink
HID: uhid: allow poll()'ing on uhid devices
Browse files Browse the repository at this point in the history
As long as the internal buffer is not empty, we return POLLIN to
user-space.

uhid->head and uhid->tail are no atomics so the comparison may return
inexact results. However, this doesn't matter here as user-space would
need to poll() in two threads simultaneously to trigger this. And in this
case it doesn't matter if a cached result is returned or the exact new
result as user-space does not know which thread returns first from poll()
and the following read(). So it is safe to compare the values without
locking.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
David Herrmann authored and Jiri Kosina committed Jun 18, 2012
1 parent ace3d86 commit 1f9dec1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/hid/uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ static ssize_t uhid_char_write(struct file *file, const char __user *buffer,

static unsigned int uhid_char_poll(struct file *file, poll_table *wait)
{
struct uhid_device *uhid = file->private_data;

poll_wait(file, &uhid->waitq, wait);

if (uhid->head != uhid->tail)
return POLLIN | POLLRDNORM;

return 0;
}

Expand Down

0 comments on commit 1f9dec1

Please sign in to comment.