From e0f58beb381249a44d73b8b2a51c92cb45a99bd7 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sun, 3 Nov 2002 16:33:15 +0000 Subject: [PATCH] fix possibility of endless loop when divisor > 0x80000000 --- include/asm/div64.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/asm/div64.h b/include/asm/div64.h index 778f61ed..e9f9e5a2 100644 --- a/include/asm/div64.h +++ b/include/asm/div64.h @@ -23,7 +23,7 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0) -extern inline u64 my_ull_div(u64 numerator, unsigned long denominator) +static inline u64 my_ull_div(u64 numerator, unsigned long denominator) { u32 value; u64 remainder, temp, answer = 0; @@ -37,13 +37,20 @@ extern inline u64 my_ull_div(u64 numerator, unsigned long denominator) shift = 0; numerator = remainder; // shift most significant bits into 32 bit variable - while(numerator > max_u32) + while( numerator > max_u32 ) { numerator >>= 1; shift++; } - value = numerator; - value /= denominator; + if( numerator < denominator ) + { + shift--; + value = 1; + }else + { + value = numerator; + value /= denominator; + } temp = ((u64) value) << shift; answer += temp; remainder -= temp * denominator; -- 2.26.2