if (err)
return 2;
- /* Step 3: make sure arguments are trivially compatible.
- * "invalid argument" returned by comedilib to user mode process
- * if this fails. */
+ /* Step 3: check if arguments are trivially valid */
+
+ err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
- if (cmd->start_arg != 0) {
- cmd->start_arg = 0;
- err++;
- }
#define MAX_SPEED_AO 8000 /* 8000 ns => 125 kHz */
#define MIN_SPEED_AO 4294967295u /* 4294967295ns = 4.29s */
/*- Comedi limit due to unsigned int cmd. Driver limit
switch (cmd->scan_begin_src) {
case TRIG_TIMER:
- if (cmd->scan_begin_arg < MAX_SPEED_AO) {
- cmd->scan_begin_arg = MAX_SPEED_AO;
- err++;
- }
- if (cmd->scan_begin_arg > MIN_SPEED_AO) {
- cmd->scan_begin_arg = MIN_SPEED_AO;
- err++;
- }
+ err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
+ MAX_SPEED_AO);
+ err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg,
+ MIN_SPEED_AO);
break;
case TRIG_EXT:
/* External trigger - for PCI230+ hardware version 2 onwards. */
if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) {
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
~CR_FLAGS_MASK);
- err++;
+ err |= -EINVAL;
}
/* The only flags allowed are CR_EDGE and CR_INVERT. The
* CR_EDGE flag is ignored. */
if ((cmd->scan_begin_arg
& (CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT))) != 0) {
- cmd->scan_begin_arg =
- COMBINE(cmd->scan_begin_arg, 0,
- CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT));
- err++;
+ cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
+ CR_FLAGS_MASK &
+ ~(CR_EDGE | CR_INVERT));
+ err |= -EINVAL;
}
break;
default:
- if (cmd->scan_begin_arg != 0) {
- cmd->scan_begin_arg = 0;
- err++;
- }
+ err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
break;
}
- if (cmd->scan_end_arg != cmd->chanlist_len) {
- cmd->scan_end_arg = cmd->chanlist_len;
- err++;
- }
- if (cmd->stop_src == TRIG_NONE) {
- /* TRIG_NONE */
- if (cmd->stop_arg != 0) {
- cmd->stop_arg = 0;
- err++;
- }
- }
+ err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
+
+ if (cmd->stop_src == TRIG_NONE)
+ err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
if (err)
return 3;
if (err)
return 2;
- /* Step 3: make sure arguments are trivially compatible.
- * "invalid argument" returned by comedilib to user mode process
- * if this fails. */
+ /* Step 3: check if arguments are trivially valid */
+
+ err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
- if (cmd->start_arg != 0) {
- cmd->start_arg = 0;
- err++;
- }
#define MAX_SPEED_AI_SE 3200 /* PCI230 SE: 3200 ns => 312.5 kHz */
#define MAX_SPEED_AI_DIFF 8000 /* PCI230 DIFF: 8000 ns => 125 kHz */
#define MAX_SPEED_AI_PLUS 4000 /* PCI230+: 4000 ns => 250 kHz */
max_speed_ai = MAX_SPEED_AI_PLUS;
}
- if (cmd->convert_arg < max_speed_ai) {
- cmd->convert_arg = max_speed_ai;
- err++;
- }
- if (cmd->convert_arg > MIN_SPEED_AI) {
- cmd->convert_arg = MIN_SPEED_AI;
- err++;
- }
+ err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
+ max_speed_ai);
+ err |= cfc_check_trigger_arg_max(&cmd->convert_arg,
+ MIN_SPEED_AI);
} else if (cmd->convert_src == TRIG_EXT) {
/*
* external trigger
if ((cmd->convert_arg & ~CR_FLAGS_MASK) != 0) {
cmd->convert_arg = COMBINE(cmd->convert_arg, 0,
~CR_FLAGS_MASK);
- err++;
+ err |= -EINVAL;
}
/* The only flags allowed are CR_INVERT and CR_EDGE.
* CR_EDGE is required. */
if ((cmd->convert_arg & (CR_FLAGS_MASK & ~CR_INVERT))
!= CR_EDGE) {
/* Set CR_EDGE, preserve CR_INVERT. */
- cmd->convert_arg =
- COMBINE(cmd->start_arg, (CR_EDGE | 0),
- CR_FLAGS_MASK & ~CR_INVERT);
- err++;
+ cmd->convert_arg = COMBINE(cmd->start_arg,
+ (CR_EDGE | 0),
+ CR_FLAGS_MASK &
+ ~CR_INVERT);
+ err |= -EINVAL;
}
} else {
/* Backwards compatibility with previous versions. */
/* convert_arg == 0 => trigger on -ve edge. */
/* convert_arg == 1 => trigger on +ve edge. */
- if (cmd->convert_arg > 1) {
- /* Default to trigger on +ve edge. */
- cmd->convert_arg = 1;
- err++;
- }
+ err |= cfc_check_trigger_arg_max(&cmd->convert_arg, 1);
}
} else {
- if (cmd->convert_arg != 0) {
- cmd->convert_arg = 0;
- err++;
- }
+ err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
}
- if (cmd->scan_end_arg != cmd->chanlist_len) {
- cmd->scan_end_arg = cmd->chanlist_len;
- err++;
- }
+ err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
- if (cmd->stop_src == TRIG_NONE) {
- if (cmd->stop_arg != 0) {
- cmd->stop_arg = 0;
- err++;
- }
- }
+ if (cmd->stop_src == TRIG_NONE)
+ err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
if (cmd->scan_begin_src == TRIG_EXT) {
/* external "trigger" to begin each scan
if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) {
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
~CR_FLAGS_MASK);
- err++;
+ err |= -EINVAL;
}
/* The only flag allowed is CR_EDGE, which is ignored. */
if ((cmd->scan_begin_arg & CR_FLAGS_MASK & ~CR_EDGE) != 0) {
cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0,
CR_FLAGS_MASK & ~CR_EDGE);
- err++;
+ err |= -EINVAL;
}
} else if (cmd->scan_begin_src == TRIG_TIMER) {
/* N.B. cmd->convert_arg is also TRIG_TIMER */
if (!pci230_ai_check_scan_period(cmd))
- err++;
+ err |= -EINVAL;
} else {
- if (cmd->scan_begin_arg != 0) {
- cmd->scan_begin_arg = 0;
- err++;
- }
+ err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
}
if (err)