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: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
H Hartley Sweeten 2014-04-17 10:07:51 -07:00 committed by Greg Kroah-Hartman
parent 6e1d1f336e
commit 9b799edccb
1 changed files with 23 additions and 15 deletions

View 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]; */