patch from Ian Abbott <abbotti@mev.co.uk>:
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 21 Feb 2005 20:52:55 +0000 (20:52 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 21 Feb 2005 20:52:55 +0000 (20:52 +0000)
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

index 97066b712839d0727e6a6fd31769e89fb26ddfde..12f9ae449aa31fe3e2ee313ca7ac21619610b96c 100644 (file)
@@ -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;