Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79819986 authored by Oliver Neukum's avatar Oliver Neukum Committed by Greg Kroah-Hartman
Browse files

USB: make usb-skeleton honor O_NONBLOCK in write path



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: default avatarOliver Neukum <oliver@neukum.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e7389cc9
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -399,10 +399,17 @@ 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 (!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);
	if ((retval = dev->errors) < 0) {