From 3c50bbb7cb0ba0d66aab4446b0554bd22e76f524 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 25 Jul 2013 16:07:57 -0700 Subject: [PATCH] staging: comedi: usbdux: tidy up unlink and stop helpers 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/usbdux.c | 95 ++++++++----------------- 1 file changed, 29 insertions(+), 66 deletions(-) diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c index 0337da1f36fa..7077d268f883 100644 --- a/drivers/staging/comedi/drivers/usbdux.c +++ b/drivers/staging/comedi/drivers/usbdux.c @@ -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); -- 2.39.5