Commit 9b799edc authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: hwdrv_apci3200: properly validata the ai cmd->start_arg

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6e1d1f33
......@@ -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]; */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment