Commit 32b36eeae6a859670d2939a7d6136cb5e9ed64f8

Authored by Alan Stern
Committed by Greg Kroah-Hartman
1 parent b0a50e92bd

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>

Showing 1 changed file with 15 additions and 1 deletions Side-by-side Diff

drivers/usb/misc/usbtest.c
... ... @@ -7,7 +7,7 @@
7 7 #include <linux/moduleparam.h>
8 8 #include <linux/scatterlist.h>
9 9 #include <linux/mutex.h>
10   -
  10 +#include <linux/timer.h>
11 11 #include <linux/usb.h>
12 12  
13 13 #define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */
... ... @@ -484,6 +484,14 @@
484 484 return sg;
485 485 }
486 486  
  487 +static void sg_timeout(unsigned long _req)
  488 +{
  489 + struct usb_sg_request *req = (struct usb_sg_request *) _req;
  490 +
  491 + req->status = -ETIMEDOUT;
  492 + usb_sg_cancel(req);
  493 +}
  494 +
487 495 static int perform_sglist(
488 496 struct usbtest_dev *tdev,
489 497 unsigned iterations,
490 498  
... ... @@ -495,7 +503,10 @@
495 503 {
496 504 struct usb_device *udev = testdev_to_usbdev(tdev);
497 505 int retval = 0;
  506 + struct timer_list sg_timer;
498 507  
  508 + setup_timer_on_stack(&sg_timer, sg_timeout, (unsigned long) req);
  509 +
499 510 while (retval == 0 && iterations-- > 0) {
500 511 retval = usb_sg_init(req, udev, pipe,
501 512 (udev->speed == USB_SPEED_HIGH)
502 513  
... ... @@ -505,7 +516,10 @@
505 516  
506 517 if (retval)
507 518 break;
  519 + mod_timer(&sg_timer, jiffies +
  520 + msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
508 521 usb_sg_wait(req);
  522 + del_timer_sync(&sg_timer);
509 523 retval = req->status;
510 524  
511 525 /* FIXME check resulting data pattern */