diff mbox series

[1/2] hw/core/ptimer: Support ptimer being disabled by timer callback

Message ID 20201015151829.14656-2-peter.maydell@linaro.org
State New
Headers show
Series armv7m_systick: Rewrite to use ptimers | expand

Commit Message

Peter Maydell Oct. 15, 2020, 3:18 p.m. UTC
In ptimer_reload(), we call the callback function provided by the
timer device that is using the ptimer.  This callback might disable
the ptimer.  The code mostly handles this correctly, except that
we'll still print the warning about "Timer with delta zero,
disabling" if the now-disabled timer happened to be set such that it
would fire again immediately if it were enabled (eg because the
limit/reload value is zero).

Suppress the spurious warning message and the unnecessary
repeat-deletion of the underlying timer in this case.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/core/ptimer.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Philippe Mathieu-Daudé Oct. 26, 2020, 9:45 p.m. UTC | #1
On 10/15/20 5:18 PM, Peter Maydell wrote:
> In ptimer_reload(), we call the callback function provided by the
> timer device that is using the ptimer.  This callback might disable
> the ptimer.  The code mostly handles this correctly, except that
> we'll still print the warning about "Timer with delta zero,
> disabling" if the now-disabled timer happened to be set such that it
> would fire again immediately if it were enabled (eg because the
> limit/reload value is zero).
> 
> Suppress the spurious warning message and the unnecessary
> repeat-deletion of the underlying timer in this case.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/core/ptimer.c | 4 ++++
>   1 file changed, 4 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index c6d2beb1dac..2aa97cb665c 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -117,6 +117,10 @@  static void ptimer_reload(ptimer_state *s, int delta_adjust)
     }
 
     if (delta == 0) {
+        if (s->enabled == 0) {
+            /* trigger callback disabled the timer already */
+            return;
+        }
         if (!qtest_enabled()) {
             fprintf(stderr, "Timer with delta zero, disabling\n");
         }