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

staging: comedi: adl_pci9118: use comedi_fc helpers to validate timer args

Use the comedi_fc helper, cfc_check_trigger_arg_is(), to validate the
arguments for the TRIG_TIMER command sources. Pass the local variable to
i8253_cascade_ns_to_timer() instead of the cmd argument. This value
is modified by that function to return the actual time (in nanoseconds)
that the timer will be programmed with based on the calculated divisors.
The cfc_check_trigger_arg_is() helper will then validate that the argument
is that value and modify it if not.

Use cfc_check_trigger_arg_min() to do validate the cmd->scan_begin_arg
when the scan_begin_src is TRIG_TIMER and the convert_src is TRIG_NOW.

All the arguments are unsigned int, change the local variable to an
unsigned int and rename it for aesthetic reasons.
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 1406057d
...@@ -1120,7 +1120,7 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev, ...@@ -1120,7 +1120,7 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
struct pci9118_private *devpriv = dev->private; struct pci9118_private *devpriv = dev->private;
int err = 0; int err = 0;
unsigned int flags; unsigned int flags;
int tmp; unsigned int arg;
unsigned int divisor1 = 0, divisor2 = 0; unsigned int divisor1 = 0, divisor2 = 0;
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
...@@ -1237,45 +1237,30 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev, ...@@ -1237,45 +1237,30 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
/* step 4: fix up any arguments */ /* step 4: fix up any arguments */
if (cmd->scan_begin_src == TRIG_TIMER) { if (cmd->scan_begin_src == TRIG_TIMER) {
tmp = cmd->scan_begin_arg; arg = cmd->scan_begin_arg;
i8253_cascade_ns_to_timer(I8254_OSC_BASE_4MHZ, i8253_cascade_ns_to_timer(I8254_OSC_BASE_4MHZ,
&divisor1, &divisor2, &divisor1, &divisor2,
&cmd->scan_begin_arg, cmd->flags); &arg, cmd->flags);
if (cmd->scan_begin_arg < this_board->ai_ns_min) err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
cmd->scan_begin_arg = this_board->ai_ns_min;
if (tmp != cmd->scan_begin_arg)
err++;
} }
if (cmd->convert_src & (TRIG_TIMER | TRIG_NOW)) { if (cmd->convert_src & (TRIG_TIMER | TRIG_NOW)) {
tmp = cmd->convert_arg; arg = cmd->convert_arg;
i8253_cascade_ns_to_timer(I8254_OSC_BASE_4MHZ, i8253_cascade_ns_to_timer(I8254_OSC_BASE_4MHZ,
&divisor1, &divisor2, &divisor1, &divisor2,
&cmd->convert_arg, cmd->flags); &arg, cmd->flags);
if (cmd->convert_arg < this_board->ai_ns_min) err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);
cmd->convert_arg = this_board->ai_ns_min;
if (tmp != cmd->convert_arg) if (cmd->scan_begin_src == TRIG_TIMER &&
err++; cmd->convert_src == TRIG_NOW) {
if (cmd->scan_begin_src == TRIG_TIMER
&& cmd->convert_src == TRIG_NOW) {
if (cmd->convert_arg == 0) { if (cmd->convert_arg == 0) {
if (cmd->scan_begin_arg < arg = this_board->ai_ns_min *
this_board->ai_ns_min *
(cmd->scan_end_arg + 2)) {
cmd->scan_begin_arg =
this_board->ai_ns_min *
(cmd->scan_end_arg + 2); (cmd->scan_end_arg + 2);
err++;
}
} else { } else {
if (cmd->scan_begin_arg < arg = cmd->convert_arg * cmd->chanlist_len;
cmd->convert_arg * cmd->chanlist_len) {
cmd->scan_begin_arg =
cmd->convert_arg *
cmd->chanlist_len;
err++;
}
} }
err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
arg);
} }
} }
......
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