]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: comedi: usbdux: fix usbdux_pwm_start()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 25 Jul 2013 23:07:39 +0000 (16:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Jul 2013 22:10:00 +0000 (15:10 -0700)
Add the missing down/up of the semaphore to prevent other commands
from being issued to the usb device while the pwn is being stopped.

Rename the local variable used for the private data pointer to the
comedi "norm".

Use memset() to initialize the urb transfer buffer.

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 14c26e559cb7685fa5f99d7491302fea626362f8..0337da1f36fa2e3fcddd3184ec9ff5a7db372f82 100644 (file)
@@ -1544,34 +1544,34 @@ static int usbdux_pwm_period(struct comedi_device *dev,
        return 0;
 }
 
-/* is called from insn so there's no need to do all the sanity checks */
 static int usbdux_pwm_start(struct comedi_device *dev,
                            struct comedi_subdevice *s)
 {
-       int ret, i;
-       struct usbdux_private *this_usbduxsub = dev->private;
+       struct usbdux_private *devpriv = dev->private;
+       int ret = 0;
 
-       if (this_usbduxsub->pwm_cmd_running) {
-               /* already running */
-               return 0;
-       }
+       down(&devpriv->sem);
+
+       if (devpriv->pwm_cmd_running)
+               goto pwm_start_exit;
 
-       this_usbduxsub->dux_commands[1] = ((int8_t) this_usbduxsub->pwn_delay);
+       devpriv->dux_commands[1] = devpriv->pwn_delay;
        ret = send_dux_commands(dev, SENDPWMON);
        if (ret < 0)
-               return ret;
+               goto pwm_start_exit;
 
        /* initialise the buffer */
-       for (i = 0; i < this_usbduxsub->size_pwm_buf; i++)
-               ((char *)(this_usbduxsub->urb_pwm->transfer_buffer))[i] = 0;
+       memset(devpriv->urb_pwm->transfer_buffer, 0, devpriv->size_pwm_buf);
 
-       this_usbduxsub->pwm_cmd_running = 1;
+       devpriv->pwm_cmd_running = 1;
        ret = usbduxsub_submit_pwm_urbs(dev);
-       if (ret < 0) {
-               this_usbduxsub->pwm_cmd_running = 0;
-               return ret;
-       }
-       return 0;
+       if (ret < 0)
+               devpriv->pwm_cmd_running = 0;
+
+pwm_start_exit:
+       up(&devpriv->sem);
+
+       return ret;
 }
 
 /* generates the bit pattern for PWM with the optional sign bit */