diff options
author | Matthias Kaehlcke <matthias@kaehlcke.net> | 2010-03-09 22:13:20 +0100 |
---|---|---|
committer | trix <trix@windriver.com> | 2010-03-22 11:58:28 -0500 |
commit | 7e67fb5bf27a07d3b8d6b97c76f7195f7d68af58 (patch) | |
tree | 21ba319c816d0bba02f6a6ea1fb85c34cdd181ea /cpu/arm920t | |
parent | daa989b47297c9f73426783599c286ef3a1f3f49 (diff) | |
download | u-boot-imx-7e67fb5bf27a07d3b8d6b97c76f7195f7d68af58.zip u-boot-imx-7e67fb5bf27a07d3b8d6b97c76f7195f7d68af58.tar.gz u-boot-imx-7e67fb5bf27a07d3b8d6b97c76f7195f7d68af58.tar.bz2 |
ep93xx timer: Fix possible overflow in usecs_to_ticks()
ep93xx timer: Use 64-bit values in usecs_to_ticks() in order to avoid
overflows in intermediate values
Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
Diffstat (limited to 'cpu/arm920t')
-rw-r--r-- | cpu/arm920t/ep93xx/timer.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/cpu/arm920t/ep93xx/timer.c b/cpu/arm920t/ep93xx/timer.c index b1a01a0..bc4ec8f 100644 --- a/cpu/arm920t/ep93xx/timer.c +++ b/cpu/arm920t/ep93xx/timer.c @@ -36,7 +36,7 @@ #define TIMER_CLKSEL (1 << 3) #define TIMER_ENABLE (1 << 7) -#define TIMER_FREQ 508469 +#define TIMER_FREQ 508469 /* ticks / second */ #define TIMER_MAX_VAL 0xFFFFFFFF static struct ep93xx_timer @@ -53,18 +53,10 @@ static inline unsigned long clk_to_systicks(unsigned long long clk_ticks) return (unsigned long)sys_ticks; } -static inline unsigned long usecs_to_ticks(unsigned long usecs) +static inline unsigned long long usecs_to_ticks(unsigned long usecs) { - unsigned long ticks; - - if (usecs >= 1000) { - ticks = usecs / 1000; - ticks *= TIMER_FREQ; - ticks /= 1000; - } else { - ticks = usecs * TIMER_FREQ; - ticks /= (1000 * 1000); - } + unsigned long long ticks = (unsigned long long)usecs * TIMER_FREQ; + do_div(ticks, 1000 * 1000); return ticks; } |