Oliver Neukum <oneukum@xxxxxxxx> wrote:
Okay. But O_NONBLOCK flag check already exists, and I don't know
if we need to branch separately to mutex_trylock just because O_NONBLOCK
flag exists. I think mutex_lock_interruptible is enough.
And the point of locking is too late. I think it would be more appropriate to
read file->private_data and then lock it right away.
I think this patch is a more appropriate patch:
---
drivers/usb/misc/iowarrior.c | 41 +++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 6d28467ce352..6fb4ecebbc15 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -277,28 +277,40 @@ static ssize_t iowarrior_read(struct file *file,
char __user *buffer,
struct iowarrior *dev;
int read_idx;
int offset;
+ int retval = 0;
dev = file->private_data;
+ if (mutex_lock_interruptible(&dev->mutex)) {
+unlock_exit:
+ mutex_unlock(&dev->mutex);
+exit:
+ return retval;