Commit 8e2a589a authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: dt3000: Fix rounding up of timer divisor

`dt3k_ns_to_timer()` determines the prescaler and divisor to use to
produce a desired timing period.  It is influenced by a rounding mode
and can round the divisor up, down, or to the nearest value.  However,
the code for rounding up currently does the same as rounding down!  Fix
ir by using the `DIV_ROUND_UP()` macro to calculate the divisor when
rounding up.

Also, change the types of the `divider`, `base` and `prescale` variables
from `int` to `unsigned int` to avoid mixing signed and unsigned types
in the calculations.

Also fix a typo in a nearby comment: "improvment" => "improvement".
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20190812120814.21188-1-abbotti@mev.co.ukSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b4d98bc3
...@@ -342,9 +342,9 @@ static irqreturn_t dt3k_interrupt(int irq, void *d) ...@@ -342,9 +342,9 @@ static irqreturn_t dt3k_interrupt(int irq, void *d)
static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec,
unsigned int flags) unsigned int flags)
{ {
int divider, base, prescale; unsigned int divider, base, prescale;
/* This function needs improvment */ /* This function needs improvement */
/* Don't know if divider==0 works. */ /* Don't know if divider==0 works. */
for (prescale = 0; prescale < 16; prescale++) { for (prescale = 0; prescale < 16; prescale++) {
...@@ -358,7 +358,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, ...@@ -358,7 +358,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec,
divider = (*nanosec) / base; divider = (*nanosec) / base;
break; break;
case CMDF_ROUND_UP: case CMDF_ROUND_UP:
divider = (*nanosec) / base; divider = DIV_ROUND_UP(*nanosec, base);
break; break;
} }
if (divider < 65536) { if (divider < 65536) {
......
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