Skip to content

Commit 9ada8c5

Browse files
shimodayFelipe Balbi
authored andcommitted
usb: gadget: function: printer: avoid spinlock recursion
If usb_gadget_giveback_request() is called in usb_ep_queue(), this printer_write() is possible to cause spinlock recursion. So, this patch adds spin_unlock() before calls usb_ep_queue() to avoid it. Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 97e133d commit 9ada8c5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/usb/gadget/function/f_printer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
555555
size_t size; /* Amount of data in a TX request. */
556556
size_t bytes_copied = 0;
557557
struct usb_request *req;
558+
int value;
558559

559560
DBG(dev, "printer_write trying to send %d bytes\n", (int)len);
560561

@@ -634,7 +635,11 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
634635
return -EAGAIN;
635636
}
636637

637-
if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) {
638+
/* here, we unlock, and only unlock, to avoid deadlock. */
639+
spin_unlock(&dev->lock);
640+
value = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
641+
spin_lock(&dev->lock);
642+
if (value) {
638643
list_add(&req->list, &dev->tx_reqs);
639644
spin_unlock_irqrestore(&dev->lock, flags);
640645
mutex_unlock(&dev->lock_printer_io);

0 commit comments

Comments
 (0)