diff mbox

hw/timer/grlib_gptimer: Avoid integer overflow

Message ID 1392282978-19368-1-git-send-email-sebastian.huber@embedded-brains.de
State New
Headers show

Commit Message

Sebastian Huber Feb. 13, 2014, 9:16 a.m. UTC
The GPTIMER uses 32-bit registers.  Use a 64-bit operation to get the
ptimer count, otherwise we end up with a count of 0 for GPTIMER counter
values of 0xffffffff.
---
 hw/timer/grlib_gptimer.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Comments

Fabien Chouteau Feb. 13, 2014, 11:44 a.m. UTC | #1
On 02/13/2014 10:16 AM, Sebastian Huber wrote:
> The GPTIMER uses 32-bit registers.  Use a 64-bit operation to get the
> ptimer count, otherwise we end up with a count of 0 for GPTIMER counter
> values of 0xffffffff.

Looks good, thanks Sebastian.

Reviewed-by: Fabien Chouteau <chouteau@adacore.com>

> ---
>  hw/timer/grlib_gptimer.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
> index d5687f6..343563c 100644
> --- a/hw/timer/grlib_gptimer.c
> +++ b/hw/timer/grlib_gptimer.c
> @@ -106,9 +106,9 @@ static void grlib_gptimer_enable(GPTimer *timer)
>      /* ptimer is triggered when the counter reach 0 but GPTimer is triggered at
>         underflow. Set count + 1 to simulate the GPTimer behavior. */
>  
> -    trace_grlib_gptimer_enable(timer->id, timer->counter + 1);
> +    trace_grlib_gptimer_enable(timer->id, timer->counter);
>  
> -    ptimer_set_count(timer->ptimer, timer->counter + 1);
> +    ptimer_set_count(timer->ptimer, (uint64_t)timer->counter + 1);
>      ptimer_run(timer->ptimer, 1);
>  }
>  
>
Michael Tokarev Feb. 15, 2014, 12:21 p.m. UTC | #2
13.02.2014 13:16, Sebastian Huber wrote:
> The GPTIMER uses 32-bit registers.  Use a 64-bit operation to get the
> ptimer count, otherwise we end up with a count of 0 for GPTIMER counter
> values of 0xffffffff.

Signed-off-by?

Thanks,

/mjt
Peter Maydell Feb. 15, 2014, 12:38 p.m. UTC | #3
On 13 February 2014 09:16, Sebastian Huber
<sebastian.huber@embedded-brains.de> wrote:
> The GPTIMER uses 32-bit registers.  Use a 64-bit operation to get the
> ptimer count, otherwise we end up with a count of 0 for GPTIMER counter
> values of 0xffffffff.
> ---
>  hw/timer/grlib_gptimer.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
> index d5687f6..343563c 100644
> --- a/hw/timer/grlib_gptimer.c
> +++ b/hw/timer/grlib_gptimer.c
> @@ -106,9 +106,9 @@ static void grlib_gptimer_enable(GPTimer *timer)
>      /* ptimer is triggered when the counter reach 0 but GPTimer is triggered at
>         underflow. Set count + 1 to simulate the GPTimer behavior. */
>
> -    trace_grlib_gptimer_enable(timer->id, timer->counter + 1);
> +    trace_grlib_gptimer_enable(timer->id, timer->counter);

This change isn't mentioned in the commit message...

> -    ptimer_set_count(timer->ptimer, timer->counter + 1);
> +    ptimer_set_count(timer->ptimer, (uint64_t)timer->counter + 1);
>      ptimer_run(timer->ptimer, 1);
>  }

thanks
-- PMM
diff mbox

Patch

diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
index d5687f6..343563c 100644
--- a/hw/timer/grlib_gptimer.c
+++ b/hw/timer/grlib_gptimer.c
@@ -106,9 +106,9 @@  static void grlib_gptimer_enable(GPTimer *timer)
     /* ptimer is triggered when the counter reach 0 but GPTimer is triggered at
        underflow. Set count + 1 to simulate the GPTimer behavior. */
 
-    trace_grlib_gptimer_enable(timer->id, timer->counter + 1);
+    trace_grlib_gptimer_enable(timer->id, timer->counter);
 
-    ptimer_set_count(timer->ptimer, timer->counter + 1);
+    ptimer_set_count(timer->ptimer, (uint64_t)timer->counter + 1);
     ptimer_run(timer->ptimer, 1);
 }