[U-Boot] [PATCH] time: fix usec_to_tick()

From: Stephen Warren swarren@nvidia.com
Commit 8dfafdde88eb ("Introduce common timer functions") created a common definition of usec_to_tick() which had a couple problems:
static unsigned long long usec_to_tick(unsigned long usec) { uint64_t tick = usec * get_tbclk();
That likely overflows.
usec *= get_tbclk();
That was an attempt to fix it by performing the multiply after the promotion of usec to 64-bit, but was applied to the wrong variable, which was never used.
This patch fixes these issues. A user-visible symptom of the problem was the e.g. "dhcp zImage" using an ASIX USB Ethernet dongle would print:
Waiting for Ethernet connection... unable to connect.
... with no delay before "unable to connect". There are likely other symptoms.
Signed-off-by: Stephen Warren swarren@nvidia.com --- lib/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/time.c b/lib/time.c index 09bb05a24d33..8085aa40d1c9 100644 --- a/lib/time.c +++ b/lib/time.c @@ -71,8 +71,8 @@ unsigned long __weak notrace timer_get_us(void) } static unsigned long long usec_to_tick(unsigned long usec) { - uint64_t tick = usec * get_tbclk(); - usec *= get_tbclk(); + uint64_t tick = usec; + tick *= get_tbclk(); do_div(tick, 1000000); return tick; }

On Thu, Dec 5, 2013 at 1:08 PM, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
Commit 8dfafdde88eb ("Introduce common timer functions") created a common definition of usec_to_tick() which had a couple problems:
static unsigned long long usec_to_tick(unsigned long usec) { uint64_t tick = usec * get_tbclk();
That likely overflows.
usec *= get_tbclk();
That was an attempt to fix it by performing the multiply after the promotion of usec to 64-bit, but was applied to the wrong variable, which was never used.
This patch fixes these issues. A user-visible symptom of the problem was the e.g. "dhcp zImage" using an ASIX USB Ethernet dongle would print:
Waiting for Ethernet connection... unable to connect.
... with no delay before "unable to connect". There are likely other symptoms.
Signed-off-by: Stephen Warren swarren@nvidia.com
Acked-by: Rob Herring rob.herring@calxeda.com
Tom,
Can you please merge this and VExpress timer fix [1] ASAP. Multiple fixes keep getting sent to the list.
Rob
[1] http://patchwork.ozlabs.org/patch/294336/
lib/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/time.c b/lib/time.c index 09bb05a24d33..8085aa40d1c9 100644 --- a/lib/time.c +++ b/lib/time.c @@ -71,8 +71,8 @@ unsigned long __weak notrace timer_get_us(void) } static unsigned long long usec_to_tick(unsigned long usec) {
uint64_t tick = usec * get_tbclk();
usec *= get_tbclk();
uint64_t tick = usec;
tick *= get_tbclk(); do_div(tick, 1000000); return tick;
}
1.8.1.5
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

On Thu, Dec 05, 2013 at 12:08:09PM -0700, Stephen Warren wrote:
From: Stephen Warren swarren@nvidia.com
Commit 8dfafdde88eb ("Introduce common timer functions") created a common definition of usec_to_tick() which had a couple problems:
static unsigned long long usec_to_tick(unsigned long usec) { uint64_t tick = usec * get_tbclk();
That likely overflows.
usec *= get_tbclk();
That was an attempt to fix it by performing the multiply after the promotion of usec to 64-bit, but was applied to the wrong variable, which was never used.
This patch fixes these issues. A user-visible symptom of the problem was the e.g. "dhcp zImage" using an ASIX USB Ethernet dongle would print:
Waiting for Ethernet connection... unable to connect.
... with no delay before "unable to connect". There are likely other symptoms.
Signed-off-by: Stephen Warren swarren@nvidia.com Acked-by: Rob Herring rob.herring@calxeda.com
Applied to u-boot/master, thanks!
participants (3)
-
Rob Herring
-
Stephen Warren
-
Tom Rini