staging: comedi: usbdux: tidy up unlink and stop helpers
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 25 Jul 2013 23:07:57 +0000 (16:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Jul 2013 22:10:07 +0000 (15:10 -0700)
For aesthetic reasons, pass the comedi_device pointer to the unlink
helpers instead of the private data pointer.

All the unlink helpers simply call usb_kill_urb() to cancel any pending
transfer requests. The usb passed to usb_kill_urb() can be NULL so the
extra sanity check is not required.

The unlink helpers will always return success so just make them void
functions.

Since the stop helpers will also always return success, make them void
functions as well.

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/usbdux.c

index 0337da1f36fa2e3fcddd3184ec9ff5a7db372f82..7077d268f883571af983fa100cc845e92944758b 100644 (file)
@@ -249,53 +249,39 @@ struct usbdux_private {
        struct semaphore sem;
 };
 
-/*
- * Stops the data acquision
- * It should be safe to call this function from any context
- */
-static int usbduxsub_unlink_inurbs(struct usbdux_private *usbduxsub_tmp)
+static void usbduxsub_unlink_inurbs(struct comedi_device *dev)
 {
-       int i = 0;
-       int err = 0;
+       struct usbdux_private *devpriv = dev->private;
+       int i;
 
-       if (usbduxsub_tmp && usbduxsub_tmp->urb_in) {
-               for (i = 0; i < usbduxsub_tmp->num_in_buffers; i++) {
-                       if (usbduxsub_tmp->urb_in[i]) {
-                               /* We wait here until all transfers have been
-                                * cancelled. */
-                               usb_kill_urb(usbduxsub_tmp->urb_in[i]);
-                       }
-               }
+       if (devpriv->urb_in) {
+               for (i = 0; i < devpriv->num_in_buffers; i++)
+                       usb_kill_urb(devpriv->urb_in[i]);
        }
-       return err;
 }
 
-static int usbdux_ai_stop(struct comedi_device *dev, int do_unlink)
+static void usbdux_ai_stop(struct comedi_device *dev, int do_unlink)
 {
        struct usbdux_private *devpriv = dev->private;
-       int ret = 0;
 
        if (do_unlink)
-               ret = usbduxsub_unlink_inurbs(devpriv);
+               usbduxsub_unlink_inurbs(dev);
 
        devpriv->ai_cmd_running = 0;
-
-       return ret;
 }
 
 static int usbdux_ai_cancel(struct comedi_device *dev,
                            struct comedi_subdevice *s)
 {
        struct usbdux_private *devpriv = dev->private;
-       int ret = 0;
 
        /* prevent other CPUs from submitting new commands just now */
        down(&devpriv->sem);
        /* unlink only if the urb really has been submitted */
-       ret = usbdux_ai_stop(dev, devpriv->ai_cmd_running);
+       usbdux_ai_stop(dev, devpriv->ai_cmd_running);
        up(&devpriv->sem);
 
-       return ret;
+       return 0;
 }
 
 /* analogue IN - interrupt service routine */
@@ -422,46 +408,39 @@ static void usbduxsub_ai_isoc_irq(struct urb *urb)
        comedi_event(dev, s);
 }
 
-static int usbduxsub_unlink_outurbs(struct usbdux_private *usbduxsub_tmp)
+static void usbduxsub_unlink_outurbs(struct comedi_device *dev)
 {
-       int i = 0;
-       int err = 0;
+       struct usbdux_private *devpriv = dev->private;
+       int i;
 
-       if (usbduxsub_tmp && usbduxsub_tmp->urb_out) {
-               for (i = 0; i < usbduxsub_tmp->num_out_buffers; i++) {
-                       if (usbduxsub_tmp->urb_out[i])
-                               usb_kill_urb(usbduxsub_tmp->urb_out[i]);
-               }
+       if (devpriv->urb_out) {
+               for (i = 0; i < devpriv->num_out_buffers; i++)
+                       usb_kill_urb(devpriv->urb_out[i]);
        }
-       return err;
 }
 
-static int usbdux_ao_stop(struct comedi_device *dev, int do_unlink)
+static void usbdux_ao_stop(struct comedi_device *dev, int do_unlink)
 {
        struct usbdux_private *devpriv = dev->private;
-       int ret = 0;
 
        if (do_unlink)
-               ret = usbduxsub_unlink_outurbs(devpriv);
+               usbduxsub_unlink_outurbs(dev);
 
        devpriv->ao_cmd_running = 0;
-
-       return ret;
 }
 
 static int usbdux_ao_cancel(struct comedi_device *dev,
                            struct comedi_subdevice *s)
 {
        struct usbdux_private *devpriv = dev->private;
-       int ret = 0;
 
        /* prevent other CPUs from submitting a command just now */
        down(&devpriv->sem);
        /* unlink only if it is really running */
-       ret = usbdux_ao_stop(dev, devpriv->ao_cmd_running);
+       usbdux_ao_stop(dev, devpriv->ao_cmd_running);
        up(&devpriv->sem);
 
-       return ret;
+       return 0;
 }
 
 static void usbduxsub_ao_isoc_irq(struct urb *urb)
@@ -1403,31 +1382,21 @@ static int usbdux_counter_config(struct comedi_device *dev,
        return 2;
 }
 
-/***********************************/
-/* PWM */
-
-static int usbduxsub_unlink_pwm_urbs(struct usbdux_private *usbduxsub_tmp)
+static void usbduxsub_unlink_pwm_urbs(struct comedi_device *dev)
 {
-       int err = 0;
+       struct usbdux_private *devpriv = dev->private;
 
-       if (usbduxsub_tmp && usbduxsub_tmp->urb_pwm) {
-               if (usbduxsub_tmp->urb_pwm)
-                       usb_kill_urb(usbduxsub_tmp->urb_pwm);
-       }
-       return err;
+       usb_kill_urb(devpriv->urb_pwm);
 }
 
-static int usbdux_pwm_stop(struct comedi_device *dev, int do_unlink)
+static void usbdux_pwm_stop(struct comedi_device *dev, int do_unlink)
 {
        struct usbdux_private *devpriv = dev->private;
-       int ret = 0;
 
        if (do_unlink)
-               ret = usbduxsub_unlink_pwm_urbs(devpriv);
+               usbduxsub_unlink_pwm_urbs(dev);
 
        devpriv->pwm_cmd_running = 0;
-
-       return ret;
 }
 
 static int usbdux_pwm_cancel(struct comedi_device *dev,
@@ -1437,15 +1406,9 @@ static int usbdux_pwm_cancel(struct comedi_device *dev,
        int ret;
 
        down(&devpriv->sem);
-
        /* unlink only if it is really running */
-       ret = usbdux_pwm_stop(dev, devpriv->pwm_cmd_running);
-       if (ret)
-               goto pwm_cancel_exit;
-
+       usbdux_pwm_stop(dev, devpriv->pwm_cmd_running);
        ret = send_dux_commands(dev, SENDPWMOFF);
-
-pwm_cancel_exit:
        up(&devpriv->sem);
 
        return ret;
@@ -1979,11 +1942,11 @@ static void usbdux_detach(struct comedi_device *dev)
                usb_set_intfdata(intf, NULL);
 
                if (devpriv->pwm_cmd_running)
-                       usbduxsub_unlink_pwm_urbs(devpriv);
+                       usbduxsub_unlink_pwm_urbs(dev);
                if (devpriv->ao_cmd_running)
-                       usbduxsub_unlink_outurbs(devpriv);
+                       usbduxsub_unlink_outurbs(dev);
                if (devpriv->ai_cmd_running)
-                       usbduxsub_unlink_inurbs(devpriv);
+                       usbduxsub_unlink_inurbs(dev);
 
                usbdux_free_usb_buffers(devpriv);