Skip to content

Commit 4e653e0

Browse files
mhennerichBryan Wu
authored andcommitted
Blackfin arch: Fix udelay implementation
Avoid possible overflow during 32*32->32 multiplies. Reported-by: Marco Reppenhagen <[email protected]> Signed-off-by: Michael Hennerich <[email protected]> Signed-off-by: Bryan Wu <[email protected]>
1 parent 972de7d commit 4e653e0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

arch/blackfin/include/asm/delay.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ static inline void __delay(unsigned long loops)
4747
#include <linux/param.h> /* needed for HZ */
4848

4949
/*
50-
* Use only for very small delays ( < 1 msec). Should probably use a
51-
* lookup table, really, as the multiplications take much too long with
52-
* short delays. This is a "reasonable" implementation, though (and the
53-
* first constant multiplications gets optimized away if the delay is
54-
* a constant)
50+
* close approximation borrowed from m68knommu to avoid 64-bit math
5551
*/
52+
53+
#define HZSCALE (268435456 / (1000000/HZ))
54+
5655
static inline void udelay(unsigned long usecs)
5756
{
5857
extern unsigned long loops_per_jiffy;
59-
__delay(usecs * loops_per_jiffy / (1000000 / HZ));
58+
__delay((((usecs * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6);
6059
}
6160

6261
#endif

0 commit comments

Comments
 (0)