Skip to contentSkip to conversation

usb: usbtest: Add timetout to simple_io()

PATCH In review Roger Quadros 4 participants 9 messages Dec 18, 2013 – Dec 19, 2013 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 usb: usbtest: Add timetout to simple_io()

Without a timetout some tests e.g. test_halt() can remain stuck forever.

---
 drivers/usb/misc/usbtest.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +11 -3
index b415282..6294e1b 100644
@@ -10,6 +10,7 @@
 
 #include <linux/usb.h>
 
+#define SIMPLE_IO_TIMEOUT	10000	/* in milliseconds */
 
 /*-------------------------------------------------------------------------*/
 
@@ -366,6 +367,7 @@ static int simple_io(
 	int			max = urb->transfer_buffer_length;
 	struct completion	completion;
 	int			retval = 0;
+	unsigned long		expire;
 
 	urb->context = &completion;
 	while (retval == 0 && iterations-- > 0) {
@@ -378,9 +380,15 @@ static int simple_io(
 		if (retval != 0)
 			break;
 
-		/* NOTE:  no timeouts; can't be broken out of by interrupt */
-		wait_for_completion(&completion);
-		retval = urb->status;
+		expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT);
+		if (!wait_for_completion_timeout(&completion, expire)) {
+			usb_kill_urb(urb);
+			retval = (urb->status == -ENOENT ?
+				  -ETIMEDOUT : urb->status);
+		} else {
+			retval = urb->status;
+		}
+
 		urb->dev = udev;
 		if (retval == 0 && usb_pipein(urb->pipe))
 			retval = simple_check_buf(tdev, urb);
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 2/2 usb: usbtest: Always clear halt else further tests will fail

In test_halt() we set an endpoint halt condition and return on halt verification failure, then the enpoint will remain halted and all further tests related to that enpoint will fail. This is because we don't tackle endpoint halt error condition in any of the tests. To avoid that situation, make sure to clear the
halt condition before exiting test_halt().

---
 drivers/usb/misc/usbtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/misc/usbtest.c +10 -1
index 6294e1b..300b726 100644
@@ -1545,8 +1545,17 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
 		return retval;
 	}
 	retval = verify_halted(tdev, ep, urb);
-	if (retval < 0)
+	if (retval < 0) {
+		int ret;
+
+		/* clear halt anyways, else further tests will fail */
+		ret = usb_clear_halt(urb->dev, urb->pipe);
+		if (ret)
+			ERROR(tdev, "ep %02x couldn't clear halt, %d\n",
+			      ep, ret);
+
 		return retval;
+	}
 
 	/* clear halt (tests API + protocol), verify it worked */
 	retval = usb_clear_halt(urb->dev, urb->pipe);
Signature · 1 line
1.8.3.2
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] usb: usbtest: Always clear halt else further tests will fail

Quoted 8 lines · Roger Quadros

In test_halt() we set an endpoint halt condition and return on halt verification failure, then the enpoint will remain halted and all further tests related to that enpoint will fail. This is because we don't tackle endpoint halt error condition in any of the tests. To avoid that situation, make sure to clear the
halt condition before exiting test_halt().

Quoted 31 lines
---
 drivers/usb/misc/usbtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/misc/usbtest.c +10 -1
index 6294e1b..300b726 100644
@@ -1545,8 +1545,17 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
 		return retval;
 	}
 	retval = verify_halted(tdev, ep, urb);
-	if (retval < 0)
+	if (retval < 0) {
+		int ret;
+
+		/* clear halt anyways, else further tests will fail */
+		ret = usb_clear_halt(urb->dev, urb->pipe);
+		if (ret)
+			ERROR(tdev, "ep %02x couldn't clear halt, %d\n",
+			      ep, ret);
+
 		return retval;
+	}
 
 	/* clear halt (tests API + protocol), verify it worked */
 	retval = usb_clear_halt(urb->dev, urb->pipe);
Signature · 1 line
1.8.3.2
#3 lore raw

Re: [PATCH 2/2] usb: usbtest: Always clear halt else further tests will fail

Quoted 3 lines · Huang Rui
Quoted 2 lines · Roger Quadros

In test_halt() we set an endpoint halt condition and return on halt verification failure, then the enpoint will remain halted and all further tests related

                      ^^^^^^^
Quoted 1 line
Quoted 1 line

to that enpoint will fail. This is because we don't tackle endpoint halt error condition

            ^^^^^^^

BTW, please fix these typo.

Thanks,
Rui

Quoted 45 lines
Quoted 5 lines

in any of the tests. To avoid that situation, make sure to clear the halt condition before exiting test_halt().

Quoted 31 lines
---
 drivers/usb/misc/usbtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/misc/usbtest.c +10 -1
index 6294e1b..300b726 100644
@@ -1545,8 +1545,17 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
 		return retval;
 	}
 	retval = verify_halted(tdev, ep, urb);
-	if (retval < 0)
+	if (retval < 0) {
+		int ret;
+
+		/* clear halt anyways, else further tests will fail */
+		ret = usb_clear_halt(urb->dev, urb->pipe);
+		if (ret)
+			ERROR(tdev, "ep %02x couldn't clear halt, %d\n",
+			      ep, ret);
+
 		return retval;
+	}
 
 	/* clear halt (tests API + protocol), verify it worked */
 	retval = usb_clear_halt(urb->dev, urb->pipe);
Signature · 1 line
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH 2/2] usb: usbtest: Always clear halt else further tests will fail

Quoted 8 lines · Huang Rui
Quoted 3 lines · Huang Rui
Quoted 2 lines · Roger Quadros

In test_halt() we set an endpoint halt condition and return on halt verification failure, then the enpoint will remain halted and all further tests related

                      ^^^^^^^
Quoted 1 line
Quoted 1 line

to that enpoint will fail. This is because we don't tackle endpoint halt error condition

            ^^^^^^^

BTW, please fix these typo.

Hi Rui,

These patches have been already applied to Greg's usb tree without your Ack's or the typo fix.

Greg,

do you want me to resend the patches?

cheers,
-roger

Quoted 50 lines

Thanks,
Rui

Quoted 45 lines
Quoted 5 lines

in any of the tests. To avoid that situation, make sure to clear the halt condition before exiting test_halt().

Quoted 31 lines
---
 drivers/usb/misc/usbtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/misc/usbtest.c +10 -1
index 6294e1b..300b726 100644
@@ -1545,8 +1545,17 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
 		return retval;
 	}
 	retval = verify_halted(tdev, ep, urb);
-	if (retval < 0)
+	if (retval < 0) {
+		int ret;
+
+		/* clear halt anyways, else further tests will fail */
+		ret = usb_clear_halt(urb->dev, urb->pipe);
+		if (ret)
+			ERROR(tdev, "ep %02x couldn't clear halt, %d\n",
+			      ep, ret);
+
 		return retval;
+	}
 
 	/* clear halt (tests API + protocol), verify it worked */
 	retval = usb_clear_halt(urb->dev, urb->pipe);
Signature · 1 line
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#5 lore raw

Re: [PATCH 2/2] usb: usbtest: Always clear halt else further tests will fail

Quoted 10 lines · Roger Quadros
Quoted 8 lines · Huang Rui
Quoted 3 lines · Huang Rui
Quoted 2 lines · Roger Quadros

In test_halt() we set an endpoint halt condition and return on halt verification failure, then the enpoint will remain halted and all further tests related

                      ^^^^^^^
Quoted 1 line
Quoted 1 line

to that enpoint will fail. This is because we don't tackle endpoint halt error condition

            ^^^^^^^

BTW, please fix these typo.

Quoted 7 lines

Hi Rui,

These patches have been already applied to Greg's usb tree without your Ack's or the typo fix.

Greg,

do you want me to resend the patches?

Nope, it's not a big deal, typo's in changelog comments isn't a worry.

greg k-h

#6 lore raw
In reply to Roger Quadros

Hi Roger,

Quoted 13 lines · Roger Quadros

Without a timetout some tests e.g. test_halt() can remain stuck forever.

---
 drivers/usb/misc/usbtest.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +0 -0
index b415282..6294e1b 100644

drivers/usb/misc/usbtest.c line 14

Quoted 5 lines
drivers/usb/misc/usbtest.c +1 -0
@@ -10,6 +10,7 @@
 
 #include <linux/usb.h>
 
+#define SIMPLE_IO_TIMEOUT	10000	/* in milliseconds */
 

Only one question, how do you confirm the timeout value?

Thanks,
Rui

Quoted 33 lines
drivers/usb/misc/usbtest.c +10 -3
 /*-------------------------------------------------------------------------*/
 
@@ -366,6 +367,7 @@ static int simple_io(
 	int			max = urb->transfer_buffer_length;
 	struct completion	completion;
 	int			retval = 0;
+	unsigned long		expire;
 
 	urb->context = &completion;
 	while (retval == 0 && iterations-- > 0) {
@@ -378,9 +380,15 @@ static int simple_io(
 		if (retval != 0)
 			break;
 
-		/* NOTE:  no timeouts; can't be broken out of by interrupt */
-		wait_for_completion(&completion);
-		retval = urb->status;
+		expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT);
+		if (!wait_for_completion_timeout(&completion, expire)) {
+			usb_kill_urb(urb);
+			retval = (urb->status == -ENOENT ?
+				  -ETIMEDOUT : urb->status);
+		} else {
+			retval = urb->status;
+		}
+
 		urb->dev = udev;
 		if (retval == 0 && usb_pipein(urb->pipe))
 			retval = simple_check_buf(tdev, urb);
Signature · 1 line
1.8.3.2
#7 lore raw
Quoted 17 lines · Huang Rui

Hi Roger,

Quoted 14 lines · Roger Quadros

Without a timetout some tests e.g. test_halt() can remain stuck forever.

---
 drivers/usb/misc/usbtest.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +0 -0
index b415282..6294e1b 100644
@@ -10,6 +10,7 @@
 
Quoted 6 lines

drivers/usb/misc/usbtest.c line 14

Quoted 4 lines
drivers/usb/misc/usbtest.c +1 -0
 #include <linux/usb.h>
 
+#define SIMPLE_IO_TIMEOUT	10000	/* in milliseconds */
 

Only one question, how do you confirm the timeout value?

dude, it's just a timeout. It could be anything, really. 10 seconds is just large enough value that would allow even the slowest scenarios (host + device) to complete, while not being so slow that you would wanna kill yourself after waiting for such a long time ;-)

Signature · 1 line
balbi
Acked-by
#8 lore raw
Quoted 25 lines · Felipe Balbi
Quoted 17 lines · Huang Rui

Hi Roger,

Quoted 14 lines · Roger Quadros

Without a timetout some tests e.g. test_halt() can remain stuck forever.

---
 drivers/usb/misc/usbtest.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/usb/misc/usbtest.c +0 -0
index b415282..6294e1b 100644
@@ -10,6 +10,7 @@
 
Quoted 6 lines

drivers/usb/misc/usbtest.c line 14

Quoted 4 lines
drivers/usb/misc/usbtest.c +1 -0
 #include <linux/usb.h>
 
+#define SIMPLE_IO_TIMEOUT	10000	/* in milliseconds */
 

Only one question, how do you confirm the timeout value?

Quoted 5 lines

dude, it's just a timeout. It could be anything, really. 10 seconds is just large enough value that would allow even the slowest scenarios (host + device) to complete, while not being so slow that you would wanna kill yourself after waiting for such a long time ;-)

OK. I've tested in my side.