staging: comedi: usbduxsigma: set *_cmd_running flags before submitting urbs
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 25 Jul 2013 23:21:13 +0000 (16:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Jul 2013 22:05:04 +0000 (15:05 -0700)
As pointed out by Ian Abbott, the *_cmd_running flags should be set
before submitting the urbs. There is a possible race condition where
an urb could complete and the flag is checked in the completion
routine before it's set.

Reported-by: Ian Abbott <abbotti@mev.co.uk>
Acked-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/usbduxsigma.c

index 40eeb8c683062bd2bd749b6c241787e0da850981..1af235407eb42da89af20cbd60c0c1fac43530b1 100644 (file)
@@ -686,13 +686,14 @@ static int usbduxsigma_ai_inttrig(struct comedi_device *dev,
 
        down(&devpriv->sem);
        if (!devpriv->ai_cmd_running) {
+               devpriv->ai_cmd_running = 1;
                ret = usbduxsigma_submit_urbs(dev, devpriv->ai_urbs,
                                              devpriv->n_ai_urbs, 1);
                if (ret < 0) {
+                       devpriv->ai_cmd_running = 0;
                        up(&devpriv->sem);
                        return ret;
                }
-               devpriv->ai_cmd_running = 1;
                s->async->inttrig = NULL;
        }
        up(&devpriv->sem);
@@ -740,14 +741,15 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
 
        if (cmd->start_src == TRIG_NOW) {
                /* enable this acquisition operation */
+               devpriv->ai_cmd_running = 1;
                ret = usbduxsigma_submit_urbs(dev, devpriv->ai_urbs,
                                              devpriv->n_ai_urbs, 1);
                if (ret < 0) {
+                       devpriv->ai_cmd_running = 0;
                        up(&devpriv->sem);
                        return ret;
                }
                s->async->inttrig = NULL;
-               devpriv->ai_cmd_running = 1;
        } else {        /* TRIG_INT */
                /* wait for an internal signal and submit the urbs later */
                s->async->inttrig = usbduxsigma_ai_inttrig;
@@ -876,13 +878,14 @@ static int usbduxsigma_ao_inttrig(struct comedi_device *dev,
 
        down(&devpriv->sem);
        if (!devpriv->ao_cmd_running) {
+               devpriv->ao_cmd_running = 1;
                ret = usbduxsigma_submit_urbs(dev, devpriv->ao_urbs,
                                              devpriv->n_ao_urbs, 0);
                if (ret < 0) {
+                       devpriv->ao_cmd_running = 0;
                        up(&devpriv->sem);
                        return ret;
                }
-               devpriv->ao_cmd_running = 1;
                s->async->inttrig = NULL;
        }
        up(&devpriv->sem);
@@ -1026,14 +1029,15 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev,
 
        if (cmd->start_src == TRIG_NOW) {
                /* enable this acquisition operation */
+               devpriv->ao_cmd_running = 1;
                ret = usbduxsigma_submit_urbs(dev, devpriv->ao_urbs,
                                              devpriv->n_ao_urbs, 0);
                if (ret < 0) {
+                       devpriv->ao_cmd_running = 0;
                        up(&devpriv->sem);
                        return ret;
                }
                s->async->inttrig = NULL;
-               devpriv->ao_cmd_running = 1;
        } else {        /* TRIG_INT */
                /* wait for an internal signal and submit the urbs later */
                s->async->inttrig = usbduxsigma_ao_inttrig;
@@ -1237,10 +1241,12 @@ static int usbduxsigma_pwm_start(struct comedi_device *dev,
 
        memset(devpriv->pwm_urb->transfer_buffer, 0, devpriv->pwm_buf_sz);
 
+       devpriv->pwm_cmd_running = 1;
        ret = usbduxsigma_submit_pwm_urb(dev);
-       if (ret < 0)
+       if (ret < 0) {
+               devpriv->pwm_cmd_running = 0;
                return ret;
-       devpriv->pwm_cmd_running = 1;
+       }
 
        return 0;
 }