staging: comedi: adl_pci9118: fix the ai cmd->start_arg validation and use
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 17 Apr 2014 17:07:52 +0000 (10:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Apr 2014 17:21:30 +0000 (10:21 -0700)
This driver supports three cmd->start_src values, TRIG_NOW, TRIG_EXT, and
TRIG_INT. TRIG_NOW sources should always have an arg of 0 and arg for TRIG_EXT
sources is driver specific. This driver does not use the cmd->start_arg with
the TRIG_EXT source so a trivial value of 0 is good.

When the cmd->start_src is TRIG_INT the cmd->start_arg is actually the valid
trig_num that is passed to the async (*inttrig) callback. This driver allows
any value to be used and currently carries that value in the private data.

Refactor the (*do_cmdtest) so that the trivial validation of the cmd->start_arg
is clear.

Refactor the (*inttrig) so that the cmd->start_arg is used directly to check
the trig_num and remove the then unused 'ai_inttrig_start' member from the
private data.

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/adl_pci9118.c

index 53bbc59f617663be546093e0eb55fb8e0de2e3da..4be5f67cf14ad129648251f698bf1037afd02d14 100644 (file)
@@ -411,7 +411,6 @@ struct pci9118_private {
                                         */
        unsigned int ai_maskerr;        /* which warning was printed */
        unsigned int ai_maskharderr;    /* on which error bits stops */
-       unsigned int ai_inttrig_start;  /* TRIG_INT for start */
 };
 
 static int check_channel_list(struct comedi_device *dev,
@@ -1135,11 +1134,13 @@ static irqreturn_t interrupt_pci9118(int irq, void *d)
 }
 
 static int pci9118_ai_inttrig(struct comedi_device *dev,
-                             struct comedi_subdevice *s, unsigned int trignum)
+                             struct comedi_subdevice *s,
+                             unsigned int trig_num)
 {
        struct pci9118_private *devpriv = dev->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
 
-       if (trignum != devpriv->ai_inttrig_start)
+       if (trig_num != cmd->start_arg)
                return -EINVAL;
 
        devpriv->ai12_startstop &= ~START_AI_INT;
@@ -1221,8 +1222,15 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
 
        /* Step 3: check if arguments are trivially valid */
 
-       if (cmd->start_src & (TRIG_NOW | TRIG_EXT))
+       switch (cmd->start_src) {
+       case TRIG_NOW:
+       case TRIG_EXT:
                err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
+               break;
+       case TRIG_INT:
+               /* start_arg is the internal trigger (any value) */
+               break;
+       }
 
        if (cmd->scan_begin_src & (TRIG_FOLLOW | TRIG_EXT))
                err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
@@ -1627,7 +1635,6 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
        if (cmd->start_src == TRIG_INT) {
                devpriv->ai12_startstop |= START_AI_INT;
-               devpriv->ai_inttrig_start = cmd->start_arg;
                s->async->inttrig = pci9118_ai_inttrig;
        }
 #if 0
This page took 0.028038 seconds and 5 git commands to generate.