From f40b0e226417334db8a7ad7b3c26498bbc6d6e90 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 21 Feb 2005 20:52:55 +0000 Subject: [PATCH] patch from Ian Abbott : Here's a couple more minor patches for the i8253_cascade_ns_to_timer_2div function, which I should have spotted earlier. 8253_dupcalc.patch gets rid of a duplicate calculation 8253_overflow.patch adds some arithmetic overflow checks to the "early exit" test. --- comedi/drivers/8253.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/comedi/drivers/8253.h b/comedi/drivers/8253.h index 97066b71..12f9ae44 100644 --- a/comedi/drivers/8253.h +++ b/comedi/drivers/8253.h @@ -133,9 +133,14 @@ static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, * and execution) */ div1 = *d1 ? *d1 : 0x10000; div2 = *d2 ? *d2 : 0x10000; + divider = div1 * div2; if(div1 * div2 * i8253_osc_base == *nanosec && div1 > 1 && div1 <= 0x10000 && - div2 > 1 && div2 <= 0x10000) + div2 > 1 && div2 <= 0x10000 && + /* check for overflow */ + divider > div1 && divider > div2 && + divider * i8253_osc_base > divider && + divider * i8253_osc_base > i8253_osc_base) { return; } @@ -160,7 +165,6 @@ static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, div2_glb = div2; } if (div2 <= 0x10000) { - ns = i8253_osc_base * div1 * div2; if (ns >= *nanosec && ns < ns_lub) { ns_lub = ns; div1_lub = div1; -- 2.26.2