staging: comedi: cb_pcidas64: validate the ai/ao cmd->start_arg
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 17 Apr 2014 17:07:58 +0000 (10:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Apr 2014 17:21:31 +0000 (10:21 -0700)
The cmd->start_arg should be trivially validated in Step 3 of the
(*do_cmdtest) functions. Add the necessary code.

For the analog output, a cmd->start_src of TRIG_NOW and TRIG_INT is
supported. For both sources the cmd->start_arg is validated to be 0.
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/cb_pcidas64.c

index 0a2b928..4061f04 100644 (file)
@@ -2087,6 +2087,18 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 
        /* Step 3: check if arguments are trivially valid */
 
+       switch (cmd->start_src) {
+       case TRIG_NOW:
+               err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
+               break;
+       case TRIG_EXT:
+               /*
+                * start_arg is the CR_CHAN | CR_INVERT of the
+                * external trigger.
+                */
+               break;
+       }
+
        if (cmd->convert_src == TRIG_TIMER) {
                if (thisboard->layout == LAYOUT_4020) {
                        err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
@@ -3215,7 +3227,7 @@ static int ao_inttrig(struct comedi_device *dev, struct comedi_subdevice *s,
        struct comedi_cmd *cmd = &s->async->cmd;
        int retval;
 
-       if (trig_num != 0)
+       if (trig_num != cmd->start_arg)
                return -EINVAL;
 
        retval = prep_ao_dma(dev, cmd);
@@ -3315,6 +3327,8 @@ static int ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 
        /* Step 3: check if arguments are trivially valid */
 
+       err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
+
        if (cmd->scan_begin_src == TRIG_TIMER) {
                err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
                                                 thisboard->ao_scan_speed);