Skip to content

Commit

Permalink
HID: hidraw, uhid: Always report EPOLLOUT
Browse files Browse the repository at this point in the history
hidraw and uhid device nodes are always available for writing so we should
always report EPOLLOUT and EPOLLWRNORM bits, not only in the cases when
there is nothing to read.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Fixes: be54e74 ("HID: uhid: Fix returning EPOLLOUT from uhid_char_poll")
Fixes: 9f3b61d ("HID: hidraw: Fix returning EPOLLOUT from hidraw_poll")
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Jiri Kosina committed Jan 10, 2020
1 parent 20eee6e commit 9e635c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions drivers/hid/hidraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t
static __poll_t hidraw_poll(struct file *file, poll_table *wait)
{
struct hidraw_list *list = file->private_data;
__poll_t mask = EPOLLOUT | EPOLLWRNORM; /* hidraw is always writable */

poll_wait(file, &list->hidraw->wait, wait);
if (list->head != list->tail)
return EPOLLIN | EPOLLRDNORM;
mask |= EPOLLIN | EPOLLRDNORM;
if (!list->hidraw->exist)
return EPOLLERR | EPOLLHUP;
return EPOLLOUT | EPOLLWRNORM;
mask |= EPOLLERR | EPOLLHUP;
return mask;
}

static int hidraw_open(struct inode *inode, struct file *file)
Expand Down
5 changes: 3 additions & 2 deletions drivers/hid/uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,14 @@ static ssize_t uhid_char_write(struct file *file, const char __user *buffer,
static __poll_t uhid_char_poll(struct file *file, poll_table *wait)
{
struct uhid_device *uhid = file->private_data;
__poll_t mask = EPOLLOUT | EPOLLWRNORM; /* uhid is always writable */

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

if (uhid->head != uhid->tail)
return EPOLLIN | EPOLLRDNORM;
mask |= EPOLLIN | EPOLLRDNORM;

return EPOLLOUT | EPOLLWRNORM;
return mask;
}

static const struct file_operations uhid_fops = {
Expand Down

0 comments on commit 9e635c2

Please sign in to comment.