staging: comedi: ni_tiocmd: clarify the cmd->start_arg validation and use
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 17 Apr 2014 17:08:03 +0000 (10:08 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Apr 2014 17:21:32 +0000 (10:21 -0700)
This driver supportes cmd->start_src sources of TRIG_NOW, TRIG_INT, TRIG_OTHER,
and TRIG_EXT. Refactor the (*do_cmdtest) to clarify the trivial validation of
the cmd->start_arg. For a TRIG_INT source, the cmd->start_arg is actually the
valid trig_num that is passed to the async (*inttrig) callback.

Refactor the (*inttrig) function so that the cmd->start_arg is used to check
the trig_num instead of the open coded value.

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

index 7d64f88..b9d23db 100644 (file)
@@ -89,14 +89,16 @@ static void ni_tio_configure_dma(struct ni_gpct *counter, short enable,
 
 static int ni_tio_input_inttrig(struct comedi_device *dev,
                                struct comedi_subdevice *s,
-                               unsigned int trignum)
+                               unsigned int trig_num)
 {
+       struct ni_gpct *counter = s->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
        unsigned long flags;
        int retval = 0;
-       struct ni_gpct *counter = s->private;
 
        BUG_ON(counter == NULL);
-       if (trignum != 0)
+
+       if (trig_num != cmd->start_src)
                return -EINVAL;
 
        spin_lock_irqsave(&counter->lock, flags);
@@ -271,8 +273,16 @@ int ni_tio_cmdtest(struct comedi_device *dev,
 
        /* Step 3: check if arguments are trivially valid */
 
-       if (cmd->start_src != TRIG_EXT)
+       switch (cmd->start_src) {
+       case TRIG_NOW:
+       case TRIG_INT:
+       case TRIG_OTHER:
                err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
+               break;
+       case TRIG_EXT:
+               /* start_arg is the start_trigger passed to ni_tio_arm() */
+               break;
+       }
 
        if (cmd->scan_begin_src != TRIG_EXT)
                err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);