USB: usbtest: add a timeout for scatter-gather tests
In usbtest, tests 5 - 8 use the scatter-gather library in usbcore without any sort of timeout. If there's a problem in the gadget or host controller being tested, the test can hang. This patch adds a 10-second timeout to the tests, so that they will fail gracefully with an ETIMEDOUT error instead of hanging. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-by: Huang Rui <ray.huang@amd.com> Tested-by: Huang Rui <ray.huang@amd.com> CC: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b0a50e92bd
commit
32b36eeae6
|
@ -7,7 +7,7 @@
|
||||||
#include <linux/moduleparam.h>
|
#include <linux/moduleparam.h>
|
||||||
#include <linux/scatterlist.h>
|
#include <linux/scatterlist.h>
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
|
#include <linux/timer.h>
|
||||||
#include <linux/usb.h>
|
#include <linux/usb.h>
|
||||||
|
|
||||||
#define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */
|
#define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */
|
||||||
|
@ -484,6 +484,14 @@ alloc_sglist(int nents, int max, int vary)
|
||||||
return sg;
|
return sg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sg_timeout(unsigned long _req)
|
||||||
|
{
|
||||||
|
struct usb_sg_request *req = (struct usb_sg_request *) _req;
|
||||||
|
|
||||||
|
req->status = -ETIMEDOUT;
|
||||||
|
usb_sg_cancel(req);
|
||||||
|
}
|
||||||
|
|
||||||
static int perform_sglist(
|
static int perform_sglist(
|
||||||
struct usbtest_dev *tdev,
|
struct usbtest_dev *tdev,
|
||||||
unsigned iterations,
|
unsigned iterations,
|
||||||
|
@ -495,6 +503,9 @@ static int perform_sglist(
|
||||||
{
|
{
|
||||||
struct usb_device *udev = testdev_to_usbdev(tdev);
|
struct usb_device *udev = testdev_to_usbdev(tdev);
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
struct timer_list sg_timer;
|
||||||
|
|
||||||
|
setup_timer_on_stack(&sg_timer, sg_timeout, (unsigned long) req);
|
||||||
|
|
||||||
while (retval == 0 && iterations-- > 0) {
|
while (retval == 0 && iterations-- > 0) {
|
||||||
retval = usb_sg_init(req, udev, pipe,
|
retval = usb_sg_init(req, udev, pipe,
|
||||||
|
@ -505,7 +516,10 @@ static int perform_sglist(
|
||||||
|
|
||||||
if (retval)
|
if (retval)
|
||||||
break;
|
break;
|
||||||
|
mod_timer(&sg_timer, jiffies +
|
||||||
|
msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
|
||||||
usb_sg_wait(req);
|
usb_sg_wait(req);
|
||||||
|
del_timer_sync(&sg_timer);
|
||||||
retval = req->status;
|
retval = req->status;
|
||||||
|
|
||||||
/* FIXME check resulting data pattern */
|
/* FIXME check resulting data pattern */
|
||||||
|
|
Loading…
Reference in New Issue