staging: comedi: usbduxsigma: generalize the ai/ao usb_kill_urb()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 30 Jul 2013 00:43:36 +0000 (17:43 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Aug 2013 00:44:52 +0000 (17:44 -0700)
Generalize a helper function to replace for() loops in usbduxsigma_{ai,ao}_stop()
that call usb_kill_urb() to unlink all the urbs.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/usbduxsigma.c

index 1af235407eb42da89af20cbd60c0c1fac43530b1..b31e400faf45f5e35c17f7c4b4fc46f7c36513e1 100644 (file)
@@ -195,18 +195,20 @@ struct usbduxsigma_private {
        struct semaphore sem;
 };
 
+static void usbduxsigma_unlink_urbs(struct urb **urbs, int num_urbs)
+{
+       int i;
+
+       for (i = 0; i < num_urbs; i++)
+               usb_kill_urb(urbs[i]);
+}
+
 static void usbduxsigma_ai_stop(struct comedi_device *dev, int do_unlink)
 {
        struct usbduxsigma_private *devpriv = dev->private;
 
-       if (do_unlink) {
-               int i;
-
-               for (i = 0; i < devpriv->n_ai_urbs; i++) {
-                       if (devpriv->ai_urbs[i])
-                               usb_kill_urb(devpriv->ai_urbs[i]);
-               }
-       }
+       if (do_unlink && devpriv->ai_urbs)
+               usbduxsigma_unlink_urbs(devpriv->ai_urbs, devpriv->n_ai_urbs);
 
        devpriv->ai_cmd_running = 0;
 }
@@ -342,14 +344,8 @@ static void usbduxsigma_ao_stop(struct comedi_device *dev, int do_unlink)
 {
        struct usbduxsigma_private *devpriv = dev->private;
 
-       if (do_unlink) {
-               int i;
-
-               for (i = 0; i < devpriv->n_ao_urbs; i++) {
-                       if (devpriv->ao_urbs[i])
-                               usb_kill_urb(devpriv->ao_urbs[i]);
-               }
-       }
+       if (do_unlink && devpriv->ao_urbs)
+               usbduxsigma_unlink_urbs(devpriv->ao_urbs, devpriv->n_ao_urbs);
 
        devpriv->ao_cmd_running = 0;
 }