[PATCH 08/11] Handle a non blocking read without blocking

From: stefani
Date: Wed Jun 06 2012 - 12:27:39 EST


From: Stefani Seibold <stefani@xxxxxxxxxxx>

Signed-off-by: Stefani Seibold <stefani@xxxxxxxxxxx>
---
drivers/usb/usb-skeleton.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index cab16e2..46c1bbb 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -241,9 +241,14 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
return 0;

/* no concurrent readers */
- retval = mutex_lock_interruptible(&dev->io_mutex);
- if (retval < 0)
- return retval;
+ if (file->f_flags & O_NONBLOCK) {
+ if (!mutex_trylock(&dev->io_mutex))
+ return -EAGAIN;
+ } else {
+ retval = mutex_lock_interruptible(&dev->io_mutex);
+ if (retval < 0)
+ return retval;
+ }

if (!dev->connected) { /* disconnect() was called */
retval = -ENODEV;
--
1.7.8.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/