diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c index 768fda9064e914362f7387c2e012f6a018f7013c..ef8c877cdd4116e0ccc50ea35cdeba79fe247cf9 100644 --- a/drivers/usb/usb-skeleton.c +++ b/drivers/usb/usb-skeleton.c @@ -268,6 +268,11 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t * spin_unlock_irq(&dev->err_lock); if (ongoing_io) { + /* nonblocking IO shall not wait */ + if (file->f_flags & O_NONBLOCK) { + rv = -EAGAIN; + goto exit; + } /* * IO may take forever * hence wait in an interruptible state @@ -351,8 +356,9 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t * rv = skel_do_read_io(dev, count); if (rv < 0) goto exit; - else + else if (!file->f_flags & O_NONBLOCK) goto retry; + rv = -EAGAIN; } exit: mutex_unlock(&dev->io_mutex);