View | Details | Raw Unified | Return to bug 1219832
Collapse All | Expand All

(-)a/drivers/usb/gadget/function/f_printer.c (-14 / +24 lines)
Lines 577-582 printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) Link Here
577
	size_t			bytes_copied = 0;
577
	size_t			bytes_copied = 0;
578
	struct usb_request	*req;
578
	struct usb_request	*req;
579
	int			value;
579
	int			value;
580
	int err = -ENODEV;
580
581
581
	DBG(dev, "printer_write trying to send %d bytes\n", (int)len);
582
	DBG(dev, "printer_write trying to send %d bytes\n", (int)len);
582
583
Lines 586-596 printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) Link Here
586
	mutex_lock(&dev->lock_printer_io);
587
	mutex_lock(&dev->lock_printer_io);
587
	spin_lock_irqsave(&dev->lock, flags);
588
	spin_lock_irqsave(&dev->lock, flags);
588
589
589
	if (dev->interface < 0) {
590
	if (dev->interface < 0)
590
		spin_unlock_irqrestore(&dev->lock, flags);
591
		goto error_spin;
591
		mutex_unlock(&dev->lock_printer_io);
592
		return -ENODEV;
593
	}
594
592
595
	/* Check if a printer reset happens while we have interrupts on */
593
	/* Check if a printer reset happens while we have interrupts on */
596
	dev->reset_printer = 0;
594
	dev->reset_printer = 0;
Lines 605-612 printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) Link Here
605
		 * a NON-Blocking call or not.
603
		 * a NON-Blocking call or not.
606
		 */
604
		 */
607
		if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
605
		if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
608
			mutex_unlock(&dev->lock_printer_io);
606
			err = -EAGAIN;
609
			return -EAGAIN;
607
			goto error_mutex;
610
		}
608
		}
611
609
612
		/* Sleep until a write buffer is available */
610
		/* Sleep until a write buffer is available */
Lines 657-665 printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) Link Here
657
		/* We've disconnected or reset so free the req and buffer */
655
		/* We've disconnected or reset so free the req and buffer */
658
		if (dev->reset_printer) {
656
		if (dev->reset_printer) {
659
			list_add(&req->list, &dev->tx_reqs);
657
			list_add(&req->list, &dev->tx_reqs);
660
			spin_unlock_irqrestore(&dev->lock, flags);
658
			err = -EAGAIN;
661
			mutex_unlock(&dev->lock_printer_io);
659
			goto error_spin;
662
			return -EAGAIN;
660
		}
661
662
		/*
663
		 * We cannot guarantee user space is using the API nicely
664
		 * This check needs to be duplicated
665
		 */
666
		if (!dev->in_ep->enabled && dev->in_ep->address) {
667
			err = -ESHUTDOWN;
668
			goto error_spin;
663
		}
669
		}
664
670
665
		list_add(&req->list, &dev->tx_reqs_active);
671
		list_add(&req->list, &dev->tx_reqs_active);
Lines 670-678 printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) Link Here
670
		spin_lock(&dev->lock);
676
		spin_lock(&dev->lock);
671
		if (value) {
677
		if (value) {
672
			list_move(&req->list, &dev->tx_reqs);
678
			list_move(&req->list, &dev->tx_reqs);
673
			spin_unlock_irqrestore(&dev->lock, flags);
679
			err = -EAGAIN;
674
			mutex_unlock(&dev->lock_printer_io);
680
			goto error_spin;
675
			return -EAGAIN;
676
		}
681
		}
677
	}
682
	}
678
683
Lines 685-690 printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) Link Here
685
		return bytes_copied;
690
		return bytes_copied;
686
	else
691
	else
687
		return -EAGAIN;
692
		return -EAGAIN;
693
694
error_spin:
695
	spin_unlock_irqrestore(&dev->lock, flags);
696
error_mutex:
697
	mutex_unlock(&dev->lock_printer_io);
698
	return err;
688
}
699
}
689
700
690
static int
701
static int
691
- 

Return to bug 1219832