All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] usb: gadget: function: printer: avoid wrong list handling in printer_write()
@ 2018-05-18  8:37 ` Yoshihiro Shimoda
  0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2018-05-18  8:37 UTC (permalink / raw)
  To: balbi; +Cc: gregkh, linux-usb, linux-renesas-soc, Yoshihiro Shimoda

The usb_ep_queue() in printer_write() is possible to call req->complete().
In that case, since tx_complete() calls list_add(&req->list, &dev->tx_reqs),
printer_write() should not call list_add(&req->list, &dev->tx_reqs_active)
because the transfer has already finished. So, this patch checks
the condition of req->list before adding the list in printer_write().

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 This issue can be caused by renesas_usbhs udc driver. I'm not sure
 this patch is acceptable or not. So, I marked RFC on this patch.

 drivers/usb/gadget/function/f_printer.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index d359efe..01de45e 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -640,10 +640,14 @@ static void tx_complete(struct usb_ep *ep, struct usb_request *req)
 			spin_unlock_irqrestore(&dev->lock, flags);
 			mutex_unlock(&dev->lock_printer_io);
 			return -EAGAIN;
+		} else if (list_empty(&req->list)) {
+			/*
+			 * Since usb_ep_queue() is possible to call complete,
+			 * we should check the req->list here, and then add
+			 * it into dev->tx_reqs_active.
+			 */
+			list_add(&req->list, &dev->tx_reqs_active);
 		}
-
-		list_add(&req->list, &dev->tx_reqs_active);
-
 	}
 
 	spin_unlock_irqrestore(&dev->lock, flags);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-05-21 11:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-18  8:37 [PATCH/RFC] usb: gadget: function: printer: avoid wrong list handling in printer_write() Yoshihiro Shimoda
2018-05-18  8:37 ` Yoshihiro Shimoda
2018-05-21  6:57 ` Felipe Balbi
2018-05-21  6:57   ` Felipe Balbi
2018-05-21  7:57   ` Yoshihiro Shimoda
2018-05-21  7:57     ` Yoshihiro Shimoda
2018-05-21  8:04     ` Felipe Balbi
2018-05-21  8:04       ` Felipe Balbi
2018-05-21  8:57       ` Yoshihiro Shimoda
2018-05-21  8:57         ` Yoshihiro Shimoda
2018-05-21 10:18         ` Felipe Balbi
2018-05-21 10:18           ` Felipe Balbi
2018-05-21 11:16           ` Yoshihiro Shimoda
2018-05-21 11:16             ` Yoshihiro Shimoda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.