Skip to content

Commit

Permalink
USB: make usb-skeleton honor O_NONBLOCK in write path
Browse files Browse the repository at this point in the history
usb:usb-skeleton: honor O_NONBLOCK in write path

nonblocking writes are allowed by using down_trylock if necessary
to reserve an URB

Signed-off-by: Oliver Neukum <oliver@neukum.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Oliver Neukum authored and Greg Kroah-Hartman committed Sep 23, 2009
1 parent e7389cc commit 7981998
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/usb/usb-skeleton.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,16 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
goto exit;

/* limit the number of URBs in flight to stop a user from using up all RAM */
if (down_interruptible(&dev->limit_sem)) {
retval = -ERESTARTSYS;
goto exit;
if (!file->f_flags & O_NONBLOCK) {
if (down_interruptible(&dev->limit_sem)) {
retval = -ERESTARTSYS;
goto exit;
}
} else {
if (down_trylock(&dev->limit_sem)) {
retval = -EAGAIN;
goto exit;
}
}

spin_lock_irq(&dev->err_lock);
Expand Down

0 comments on commit 7981998

Please sign in to comment.