From: H Hartley Sweeten Date: Tue, 27 May 2014 17:12:59 +0000 (-0700) Subject: staging: comedi: s626: use comedi_fc helpers to validate timer args X-Git-Tag: firefly_0821_release~176^2~3465^2~39^2~68 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c646efe13fd1e76d00b25d1c4ebc7d8053ae907b;p=firefly-linux-kernel-4.4.55.git staging: comedi: s626: use comedi_fc helpers to validate timer args Use the comedi_fc helper cfc_check_trigger_arg_is() to validate the trigger arguments when the source is TRIG_TIMER. Use cfc_check_trigger_arg_min() to vaidate the scan_begin_arg when the scan_begin_src and convert_src are both TRIG_TIMER. All the arguments are unsigned int, change the local variable to an unsigned int and rename it for aesthetic reasons. Change the type of the first parameter to s626_ns_to_timer() to remove the need for the casts. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 33b4d027a5cb..0838f8aa6951 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -2098,7 +2098,7 @@ static int s626_ai_inttrig(struct comedi_device *dev, * Also, it should adjust ns so that it cooresponds to the actual time * that the device will use. */ -static int s626_ns_to_timer(int *nanosec, int round_mode) +static int s626_ns_to_timer(unsigned int *nanosec, int round_mode) { int divider, base; @@ -2206,7 +2206,7 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) * interval */ k = &s626_enc_chan_info[5]; - tick = s626_ns_to_timer((int *)&cmd->scan_begin_arg, + tick = s626_ns_to_timer(&cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); /* load timer value and enable interrupt */ @@ -2229,7 +2229,7 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) * interval */ k = &s626_enc_chan_info[4]; - tick = s626_ns_to_timer((int *)&cmd->convert_arg, + tick = s626_ns_to_timer(&cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); /* load timer value and enable interrupt */ @@ -2288,7 +2288,7 @@ static int s626_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { int err = 0; - int tmp; + unsigned int arg; /* Step 1 : check if triggers are trivially valid */ @@ -2371,24 +2371,20 @@ static int s626_ai_cmdtest(struct comedi_device *dev, /* step 4: fix up any arguments */ if (cmd->scan_begin_src == TRIG_TIMER) { - tmp = cmd->scan_begin_arg; - s626_ns_to_timer((int *)&cmd->scan_begin_arg, - cmd->flags & TRIG_ROUND_MASK); - if (tmp != cmd->scan_begin_arg) - err++; + arg = cmd->scan_begin_arg; + s626_ns_to_timer(&arg, cmd->flags & TRIG_ROUND_MASK); + err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, arg); } + if (cmd->convert_src == TRIG_TIMER) { - tmp = cmd->convert_arg; - s626_ns_to_timer((int *)&cmd->convert_arg, - cmd->flags & TRIG_ROUND_MASK); - if (tmp != cmd->convert_arg) - err++; - if (cmd->scan_begin_src == TRIG_TIMER && - cmd->scan_begin_arg < cmd->convert_arg * - cmd->scan_end_arg) { - cmd->scan_begin_arg = cmd->convert_arg * - cmd->scan_end_arg; - err++; + arg = cmd->convert_arg; + s626_ns_to_timer(&arg, cmd->flags & TRIG_ROUND_MASK); + err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg); + + if (cmd->scan_begin_src == TRIG_TIMER) { + arg = cmd->convert_arg * cmd->scan_end_arg; + err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, + arg); } }