[PATCH] usb: core: update wait routine to set a timeout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, in usb_sg_wait routine there isn't a timeout on waiting for
completion signal. When using TEST 5 -> 8 at usbtest module to verify
a new device controller with gadget zero, it would be hang on this
phase and this routine waits forever. So it should add a timeout about
10s to export a TIMEOUT error to return.

Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Huang Rui <ray.huang@xxxxxxx>
---
 drivers/usb/core/message.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 0c8a7fc..b9c2841 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -507,6 +507,8 @@ void usb_sg_wait(struct usb_sg_request *io)
 {
 	int i;
 	int entries = io->entries;
+	unsigned long timeout;
+	long timeleft;
 
 	/* queue the urbs.  */
 	spin_lock_irq(&io->lock);
@@ -561,7 +563,13 @@ void usb_sg_wait(struct usb_sg_request *io)
 	 * So could the submit loop above ... but it's easier to
 	 * solve neither problem than to solve both!
 	 */
-	wait_for_completion(&io->complete);
+	timeout = msecs_to_jiffies(10000);
+	timeleft = wait_for_completion_timeout(&io->complete, timeout);
+	if (timeleft <= 0) {
+		usb_sg_cancel(io);
+		if (timeleft == 0)
+			io->status = -ETIMEDOUT;
+	}
 
 	sg_clean(io);
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]