staging: comedi: usbduxsigma: don't clobber ao_timer in command test
authorIan Abbott <abbotti@mev.co.uk>
Thu, 23 Jul 2015 15:46:58 +0000 (16:46 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Oct 2015 21:39:21 +0000 (14:39 -0700)
commit c04a1f17803e0d3eeada586ca34a6b436959bc20 upstream.

`devpriv->ao_timer` is used while an asynchronous command is running on
the AO subdevice.  It also gets modified by the subdevice's `cmdtest`
handler for checking new asynchronous commands,
`usbduxsigma_ao_cmdtest()`, which is not correct as it's allowed to
check new commands while an old command is still running.  Fix it by
moving the code which sets up `devpriv->ao_timer` into the subdevice's
`cmd` handler, `usbduxsigma_ao_cmd()`.

Note that the removed code in `usbduxsigma_ao_cmdtest()` checked that
`devpriv->ao_timer` did not end up less that 1, but that could not
happen due because `cmd->scan_begin_arg` or `cmd->convert_arg` had
already been range-checked.

Also note that we tested the `high_speed` variable in the old code, but
that is currently always 0 and means that we always use "scan" timing
(`cmd->scan_begin_src == TRIG_TIMER` and `cmd->convert_src == TRIG_NOW`)
and never "convert" (individual sample) timing (`cmd->scan_begin_src ==
TRIG_FOLLOW` and `cmd->convert_src == TRIG_TIMER`).  The moved code
tests `cmd->convert_src` instead to decide whether "scan" or "convert"
timing is being used, although currently only "scan" timing is
supported.

Fixes: fb1ef622e7a3 ("staging: comedi: usbduxsigma: tidy up analog output command support")
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: Bernd Porr <mail@berndporr.me.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/usbduxsigma.c

index ba970d9d2b489b75afd5113f3470b15599242197..c4ee9fa1dc91f0df073d3228906114d47db42aab 100644 (file)
@@ -951,10 +951,24 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
        if (err)
                return 3;
 
-       /* Step 4: fix up any arguments */
+       return 0;
+}
+
+static int usbduxsigma_ao_cmd(struct comedi_device *dev,
+                             struct comedi_subdevice *s)
+{
+       struct usbduxsigma_private *devpriv = dev->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
+       int ret;
+       int i;
+
+       down(&devpriv->sem);
+
+       /* set current channel of the running acquisition to zero */
+       s->async->cur_chan = 0;
 
        /* we count in timer steps */
-       if (high_speed) {
+       if (cmd->convert_src == TRIG_TIMER) {
                /* timing of the conversion itself: every 125 us */
                devpriv->ao_timer = cmd->convert_arg / 125000;
        } else {
@@ -964,12 +978,9 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
                 */
                devpriv->ao_timer = cmd->scan_begin_arg / 1000000;
        }
-       if (devpriv->ao_timer < 1)
-               err |= -EINVAL;
-
        if (cmd->stop_src == TRIG_COUNT) {
                /* not continuous, use counter */
-               if (high_speed) {
+               if (cmd->convert_src == TRIG_TIMER) {
                        /* high speed also scans everything at once */
                        devpriv->ao_sample_count = cmd->stop_arg *
                                                   cmd->scan_end_arg;
@@ -988,24 +999,6 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
                devpriv->ao_sample_count = 0;
        }
 
-       if (err)
-               return 4;
-
-       return 0;
-}
-
-static int usbduxsigma_ao_cmd(struct comedi_device *dev,
-                             struct comedi_subdevice *s)
-{
-       struct usbduxsigma_private *devpriv = dev->private;
-       struct comedi_cmd *cmd = &s->async->cmd;
-       int ret;
-       int i;
-
-       down(&devpriv->sem);
-
-       /* set current channel of the running acquisition to zero */
-       s->async->cur_chan = 0;
        for (i = 0; i < cmd->chanlist_len; ++i)
                devpriv->ao_chanlist[i] = CR_CHAN(cmd->chanlist[i]);