usb: usbtest: Convert timers to use timer_setup()
authorKees Cook <keescook@chromium.org>
Mon, 23 Oct 2017 00:57:22 +0000 (17:57 -0700)
committerKees Cook <keescook@chromium.org>
Wed, 1 Nov 2017 18:44:52 +0000 (11:44 -0700)
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Also adds missing call to
destroy_timer_on_stack();

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/misc/usbtest.c

index eee82ca55b7b383bc507c39af7e64bb66a63c6a8..b1ad69edf8395fe6106280cf6fe9c91d2e6225e3 100644 (file)
@@ -575,11 +575,16 @@ alloc_sglist(int nents, int max, int vary, struct usbtest_dev *dev, int pipe)
        return sg;
 }
 
-static void sg_timeout(unsigned long _req)
+struct sg_timeout {
+       struct timer_list timer;
+       struct usb_sg_request *req;
+};
+
+static void sg_timeout(struct timer_list *t)
 {
-       struct usb_sg_request   *req = (struct usb_sg_request *) _req;
+       struct sg_timeout *timeout = from_timer(timeout, t, timer);
 
-       usb_sg_cancel(req);
+       usb_sg_cancel(timeout->req);
 }
 
 static int perform_sglist(
@@ -593,9 +598,11 @@ static int perform_sglist(
 {
        struct usb_device       *udev = testdev_to_usbdev(tdev);
        int                     retval = 0;
-       struct timer_list       sg_timer;
+       struct sg_timeout       timeout = {
+               .req = req,
+       };
 
-       setup_timer_on_stack(&sg_timer, sg_timeout, (unsigned long) req);
+       timer_setup_on_stack(&timeout.timer, sg_timeout, 0);
 
        while (retval == 0 && iterations-- > 0) {
                retval = usb_sg_init(req, udev, pipe,
@@ -606,13 +613,14 @@ static int perform_sglist(
 
                if (retval)
                        break;
-               mod_timer(&sg_timer, jiffies +
+               mod_timer(&timeout.timer, jiffies +
                                msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
                usb_sg_wait(req);
-               if (!del_timer_sync(&sg_timer))
+               if (!del_timer_sync(&timeout.timer))
                        retval = -ETIMEDOUT;
                else
                        retval = req->status;
+               destroy_timer_on_stack(&timeout.timer);
 
                /* FIXME check resulting data pattern */