qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-arm] [PATCH v2 11/21] aspeed/timer: Ensure positive muldiv del


From: Andrew Jeffery
Subject: Re: [Qemu-arm] [PATCH v2 11/21] aspeed/timer: Ensure positive muldiv delta
Date: Thu, 20 Jun 2019 11:35:49 +0930
User-agent: Cyrus-JMAP/3.1.6-666-gb2312fa-fmstable-20190614v4


On Wed, 19 Jun 2019, at 02:24, Cédric Le Goater wrote:
> From: Christian Svensson <address@hidden>
> 
> If the host decrements the counter register that results in a negative
> delta. This is then passed to muldiv64 which only handles unsigned
> numbers resulting in bogus results.
> 
> This fix ensures the delta being operated on is positive.
> 
> Test case: kexec a kernel using aspeed_timer and it will freeze on the
> second bootup when the kernel initializes the timer. With this patch
> that no longer happens and the timer appears to run OK.
> 
> Signed-off-by: Christian Svensson <address@hidden>
> Signed-off-by: Cédric Le Goater <address@hidden>

Reviewed-by: Andrew Jeffery <address@hidden>

> ---
>  hw/timer/aspeed_timer.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
> index 6501fa0768e7..1f0f1886fb2a 100644
> --- a/hw/timer/aspeed_timer.c
> +++ b/hw/timer/aspeed_timer.c
> @@ -275,7 +275,11 @@ static void 
> aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
>              int64_t delta = (int64_t) value - (int64_t) 
> calculate_ticks(t, now);
>              uint32_t rate = calculate_rate(t);
>  
> -            t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
> +            if (delta >= 0) {
> +                t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
> +            } else {
> +                t->start -= muldiv64(-delta, NANOSECONDS_PER_SECOND, rate);
> +            }
>              aspeed_timer_mod(t);
>          }
>          break;
> -- 
> 2.21.0
> 
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]