mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 22:51:37 +00:00
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>
This commit is contained in:
parent
daa989b472
commit
7e67fb5bf2
1 changed files with 4 additions and 12 deletions
|
@ -36,7 +36,7 @@
|
||||||
#define TIMER_CLKSEL (1 << 3)
|
#define TIMER_CLKSEL (1 << 3)
|
||||||
#define TIMER_ENABLE (1 << 7)
|
#define TIMER_ENABLE (1 << 7)
|
||||||
|
|
||||||
#define TIMER_FREQ 508469
|
#define TIMER_FREQ 508469 /* ticks / second */
|
||||||
#define TIMER_MAX_VAL 0xFFFFFFFF
|
#define TIMER_MAX_VAL 0xFFFFFFFF
|
||||||
|
|
||||||
static struct ep93xx_timer
|
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;
|
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;
|
unsigned long long ticks = (unsigned long long)usecs * TIMER_FREQ;
|
||||||
|
do_div(ticks, 1000 * 1000);
|
||||||
if (usecs >= 1000) {
|
|
||||||
ticks = usecs / 1000;
|
|
||||||
ticks *= TIMER_FREQ;
|
|
||||||
ticks /= 1000;
|
|
||||||
} else {
|
|
||||||
ticks = usecs * TIMER_FREQ;
|
|
||||||
ticks /= (1000 * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ticks;
|
return ticks;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue