[PATCH 39/53] staging: comedi: usbdux: tidy up usbdux_ao_inttrig()
Ian Abbott
abbotti at mev.co.uk
Thu Jul 25 15:15:00 UTC 2013
On 2013-07-24 22:21, H Hartley Sweeten wrote:
> Rename the local variable used for the private data pointer to the
> comedi "norm".
>
> Remove the unnecessary sanity check of the private data pointer. This
> function can only be called is the private data was allocated during
> the attach.
>
> Tidy up the exit path using goto to ensure that the semaphore it
> released.
>
> Set the ao_cmd_running flag after submitting the urbs to remove the
> need to clear the flag if the submit fails.
As for AI, the URB completion handler usbduxsub_ao_isoc_irq() could
execute before you set ao_cmd_running.
>
> Return -EBUSY if an ao command is already running.
>
> Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
> Cc: Ian Abbott <abbotti at mev.co.uk>
> Cc: Greg Kroah-Hartman <gregkh at linuxfondation.org>
> ---
> drivers/staging/comedi/drivers/usbdux.c | 38 ++++++++++++++++-----------------
> 1 file changed, 19 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
> index 3898aea..9efd125 100644
> --- a/drivers/staging/comedi/drivers/usbdux.c
> +++ b/drivers/staging/comedi/drivers/usbdux.c
> @@ -1072,31 +1072,31 @@ ao_write_exit:
> }
>
> static int usbdux_ao_inttrig(struct comedi_device *dev,
> - struct comedi_subdevice *s, unsigned int trignum)
> + struct comedi_subdevice *s,
> + unsigned int trignum)
> {
> - int ret;
> - struct usbdux_private *this_usbduxsub = dev->private;
> + struct usbdux_private *devpriv = dev->private;
> + int ret = -EINVAL;
>
> - if (!this_usbduxsub)
> - return -EFAULT;
> + down(&devpriv->sem);
>
> - down(&this_usbduxsub->sem);
> - if (trignum != 0) {
> - up(&this_usbduxsub->sem);
> - return -EINVAL;
> - }
> - if (!(this_usbduxsub->ao_cmd_running)) {
> - this_usbduxsub->ao_cmd_running = 1;
> + if (trignum != 0)
> + goto ao_trig_exit;
> +
> + if (!devpriv->ao_cmd_running) {
> ret = usbduxsub_submit_outurbs(dev);
> - if (ret < 0) {
> - this_usbduxsub->ao_cmd_running = 0;
> - up(&this_usbduxsub->sem);
> - return ret;
> - }
> + if (ret < 0)
> + goto ao_trig_exit;
> +
> + devpriv->ao_cmd_running = 1;
> s->async->inttrig = NULL;
> + } else {
> + ret = -EBUSY;
> }
> - up(&this_usbduxsub->sem);
> - return 1;
> +
> +ao_trig_exit:
> + up(&devpriv->sem);
> + return ret;
> }
>
> static int usbdux_ao_cmdtest(struct comedi_device *dev,
>
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti at mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
More information about the devel
mailing list