Commit 5c2d0de5 authored by Vasily Khoruzhick's avatar Vasily Khoruzhick Committed by Takashi Iwai

ALSA: line6: hwdep: add support for O_NONBLOCK opening mode

Currently line6 hwdep interface ignores O_NONBLOCK flag when
opening device and it renders it somewhat useless when using poll.

Check for O_NONBLOCK flag when opening device and don't block read()
if it is set.
Signed-off-by: default avatarVasily Khoruzhick <anarsoul@gmail.com>
Link: https://lore.kernel.org/r/20200502193120.79115-2-anarsoul@gmail.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 7f0d5053
...@@ -550,6 +550,7 @@ static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file) ...@@ -550,6 +550,7 @@ static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)
/* NOTE: hwdep layer provides atomicity here */ /* NOTE: hwdep layer provides atomicity here */
line6->messages.active = 1; line6->messages.active = 1;
line6->messages.nonblock = file->f_flags & O_NONBLOCK ? 1 : 0;
return 0; return 0;
} }
...@@ -579,6 +580,9 @@ line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, ...@@ -579,6 +580,9 @@ line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
while (kfifo_len(&line6->messages.fifo) == 0) { while (kfifo_len(&line6->messages.fifo) == 0) {
mutex_unlock(&line6->messages.read_lock); mutex_unlock(&line6->messages.read_lock);
if (line6->messages.nonblock)
return -EAGAIN;
rv = wait_event_interruptible( rv = wait_event_interruptible(
line6->messages.wait_queue, line6->messages.wait_queue,
kfifo_len(&line6->messages.fifo) != 0); kfifo_len(&line6->messages.fifo) != 0);
......
...@@ -163,6 +163,7 @@ struct usb_line6 { ...@@ -163,6 +163,7 @@ struct usb_line6 {
struct mutex read_lock; struct mutex read_lock;
wait_queue_head_t wait_queue; wait_queue_head_t wait_queue;
unsigned int active:1; unsigned int active:1;
unsigned int nonblock:1;
STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT) STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
fifo; fifo;
} messages; } messages;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment