Commit 3c50bbb7 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 81e80134
...@@ -249,53 +249,39 @@ struct usbdux_private { ...@@ -249,53 +249,39 @@ struct usbdux_private {
struct semaphore sem; struct semaphore sem;
}; };
/* static void usbduxsub_unlink_inurbs(struct comedi_device *dev)
* 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)
{ {
int i = 0; struct usbdux_private *devpriv = dev->private;
int err = 0; int i;
if (usbduxsub_tmp && usbduxsub_tmp->urb_in) { if (devpriv->urb_in) {
for (i = 0; i < usbduxsub_tmp->num_in_buffers; i++) { for (i = 0; i < devpriv->num_in_buffers; i++)
if (usbduxsub_tmp->urb_in[i]) { usb_kill_urb(devpriv->urb_in[i]);
/* We wait here until all transfers have been
* cancelled. */
usb_kill_urb(usbduxsub_tmp->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; struct usbdux_private *devpriv = dev->private;
int ret = 0;
if (do_unlink) if (do_unlink)
ret = usbduxsub_unlink_inurbs(devpriv); usbduxsub_unlink_inurbs(dev);
devpriv->ai_cmd_running = 0; devpriv->ai_cmd_running = 0;
return ret;
} }
static int usbdux_ai_cancel(struct comedi_device *dev, static int usbdux_ai_cancel(struct comedi_device *dev,
struct comedi_subdevice *s) struct comedi_subdevice *s)
{ {
struct usbdux_private *devpriv = dev->private; struct usbdux_private *devpriv = dev->private;
int ret = 0;
/* prevent other CPUs from submitting new commands just now */ /* prevent other CPUs from submitting new commands just now */
down(&devpriv->sem); down(&devpriv->sem);
/* unlink only if the urb really has been submitted */ /* 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); up(&devpriv->sem);
return ret; return 0;
} }
/* analogue IN - interrupt service routine */ /* analogue IN - interrupt service routine */
...@@ -422,46 +408,39 @@ static void usbduxsub_ai_isoc_irq(struct urb *urb) ...@@ -422,46 +408,39 @@ static void usbduxsub_ai_isoc_irq(struct urb *urb)
comedi_event(dev, s); 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; struct usbdux_private *devpriv = dev->private;
int err = 0; int i;
if (usbduxsub_tmp && usbduxsub_tmp->urb_out) { if (devpriv->urb_out) {
for (i = 0; i < usbduxsub_tmp->num_out_buffers; i++) { for (i = 0; i < devpriv->num_out_buffers; i++)
if (usbduxsub_tmp->urb_out[i]) usb_kill_urb(devpriv->urb_out[i]);
usb_kill_urb(usbduxsub_tmp->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; struct usbdux_private *devpriv = dev->private;
int ret = 0;
if (do_unlink) if (do_unlink)
ret = usbduxsub_unlink_outurbs(devpriv); usbduxsub_unlink_outurbs(dev);
devpriv->ao_cmd_running = 0; devpriv->ao_cmd_running = 0;
return ret;
} }
static int usbdux_ao_cancel(struct comedi_device *dev, static int usbdux_ao_cancel(struct comedi_device *dev,
struct comedi_subdevice *s) struct comedi_subdevice *s)
{ {
struct usbdux_private *devpriv = dev->private; struct usbdux_private *devpriv = dev->private;
int ret = 0;
/* prevent other CPUs from submitting a command just now */ /* prevent other CPUs from submitting a command just now */
down(&devpriv->sem); down(&devpriv->sem);
/* unlink only if it is really running */ /* 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); up(&devpriv->sem);
return ret; return 0;
} }
static void usbduxsub_ao_isoc_irq(struct urb *urb) static void usbduxsub_ao_isoc_irq(struct urb *urb)
...@@ -1403,31 +1382,21 @@ static int usbdux_counter_config(struct comedi_device *dev, ...@@ -1403,31 +1382,21 @@ static int usbdux_counter_config(struct comedi_device *dev,
return 2; return 2;
} }
/***********************************/ static void usbduxsub_unlink_pwm_urbs(struct comedi_device *dev)
/* PWM */
static int usbduxsub_unlink_pwm_urbs(struct usbdux_private *usbduxsub_tmp)
{ {
int err = 0; struct usbdux_private *devpriv = dev->private;
if (usbduxsub_tmp && usbduxsub_tmp->urb_pwm) { usb_kill_urb(devpriv->urb_pwm);
if (usbduxsub_tmp->urb_pwm)
usb_kill_urb(usbduxsub_tmp->urb_pwm);
}
return err;
} }
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; struct usbdux_private *devpriv = dev->private;
int ret = 0;
if (do_unlink) if (do_unlink)
ret = usbduxsub_unlink_pwm_urbs(devpriv); usbduxsub_unlink_pwm_urbs(dev);
devpriv->pwm_cmd_running = 0; devpriv->pwm_cmd_running = 0;
return ret;
} }
static int usbdux_pwm_cancel(struct comedi_device *dev, static int usbdux_pwm_cancel(struct comedi_device *dev,
...@@ -1437,15 +1406,9 @@ static int usbdux_pwm_cancel(struct comedi_device *dev, ...@@ -1437,15 +1406,9 @@ static int usbdux_pwm_cancel(struct comedi_device *dev,
int ret; int ret;
down(&devpriv->sem); down(&devpriv->sem);
/* unlink only if it is really running */ /* unlink only if it is really running */
ret = usbdux_pwm_stop(dev, devpriv->pwm_cmd_running); usbdux_pwm_stop(dev, devpriv->pwm_cmd_running);
if (ret)
goto pwm_cancel_exit;
ret = send_dux_commands(dev, SENDPWMOFF); ret = send_dux_commands(dev, SENDPWMOFF);
pwm_cancel_exit:
up(&devpriv->sem); up(&devpriv->sem);
return ret; return ret;
...@@ -1979,11 +1942,11 @@ static void usbdux_detach(struct comedi_device *dev) ...@@ -1979,11 +1942,11 @@ static void usbdux_detach(struct comedi_device *dev)
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
if (devpriv->pwm_cmd_running) if (devpriv->pwm_cmd_running)
usbduxsub_unlink_pwm_urbs(devpriv); usbduxsub_unlink_pwm_urbs(dev);
if (devpriv->ao_cmd_running) if (devpriv->ao_cmd_running)
usbduxsub_unlink_outurbs(devpriv); usbduxsub_unlink_outurbs(dev);
if (devpriv->ai_cmd_running) if (devpriv->ai_cmd_running)
usbduxsub_unlink_inurbs(devpriv); usbduxsub_unlink_inurbs(dev);
usbdux_free_usb_buffers(devpriv); usbdux_free_usb_buffers(devpriv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment