]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging: comedi: hwdrv_apci3200: properly validata the ai cmd->start_arg
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 17 Apr 2014 17:07:51 +0000 (10:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Apr 2014 17:21:30 +0000 (10:21 -0700)
The async command 'arguments' should be trivially validated in Step 3 of
the (*do_cmdtest) not Step 2b. Move the validataion in this driver to the
proper place.

This driver supports two cmd->start_src values, TRIG_NOW and TRIG_EXT.
TRIG_NOW sources should always have an arg of 0. The arg for TRIG_EXT
sources is driver specific.

Properly validate the cmd->start_arg based on the cmd->start_src. Remove
the noise when the arg is invalid and modify the cmd->start_arg so that
a valid value is returned to the user.

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/addi-data/hwdrv_apci3200.c

index 76a66820775e113c17094c69ca5c33505cf37e1f..9b8851c7e07214afe62f7ddb3cf6a4ee895f3a57 100644 (file)
@@ -2221,12 +2221,11 @@ static int apci3200_ai_cmdtest(struct comedi_device *dev,
        unsigned int ui_ConvertTimeBase = 0;
        unsigned int ui_DelayTime = 0;
        unsigned int ui_DelayTimeBase = 0;
-       int i_Triggermode = 0;
-       int i_TriggerEdge = 0;
        int i_NbrOfChannel = 0;
        int i_Cpt = 0;
        double d_ConversionTimeForAllChannels = 0.0;
        double d_SCANTimeNewUnit = 0.0;
+       unsigned int arg;
 
        /* Step 1 : check if triggers are trivially valid */
 
@@ -2253,19 +2252,6 @@ static int apci3200_ai_cmdtest(struct comedi_device *dev,
 
        /* Step 2b : and mutually compatible */
 
-       if (cmd->start_src == TRIG_EXT) {
-               i_TriggerEdge = cmd->start_arg & 0xFFFF;
-               i_Triggermode = cmd->start_arg >> 16;
-               if (i_TriggerEdge < 1 || i_TriggerEdge > 3) {
-                       err++;
-                       printk("\nThe trigger edge selection is in error\n");
-               }
-               if (i_Triggermode != 2) {
-                       err++;
-                       printk("\nThe trigger mode selection is in error\n");
-               }
-       }
-
        if (err) {
                apci3200_reset(dev);
                return 2;
@@ -2273,6 +2259,28 @@ static int apci3200_ai_cmdtest(struct comedi_device *dev,
 
        /* 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:
+               /* validate the trigger edge selection */
+               arg = cmd->start_arg & 0xffff;
+               if (arg < 1 || arg > 3) {
+                       cmd->start_arg &= ~0xffff;
+                       cmd->start_arg |= 1;
+                       err |= -EINVAL;
+               }
+               /* validate the trigger mode selection */
+               arg = cmd->start_arg >> 16;
+               if (arg != 2) {
+                       cmd->start_arg &= ~(0xffff << 16);
+                       cmd->start_arg |= (2 << 16);
+                       err |= -EINVAL;
+               }
+               break;
+       }
+
        err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
 
        /* i_FirstChannel=cmd->chanlist[0]; */