]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/timer/npcm7xx_timer: Prevent timer from counting down past zero
authorChris Rauer <crauer@google.com>
Fri, 22 Sep 2023 18:14:11 +0000 (18:14 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 19 Oct 2023 13:32:13 +0000 (14:32 +0100)
The counter register is only 24-bits and counts down.  If the timer is
running but the qtimer to reset it hasn't fired off yet, there is a chance
the regster read can return an invalid result.

Signed-off-by: Chris Rauer <crauer@google.com>
Message-id: 20230922181411.2697135-1-crauer@google.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/timer/npcm7xx_timer.c

index 32f5e021f85709122d32587929b76daeabb21bfc..a8bd93aeb2cfd761c200b16c21a3428291a8d81f 100644 (file)
@@ -138,6 +138,9 @@ static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count)
 /* Convert a time interval in nanoseconds to a timer cycle count. */
 static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns)
 {
+    if (ns < 0) {
+        return 0;
+    }
     return clock_ns_to_ticks(t->ctrl->clock, ns) /
         npcm7xx_tcsr_prescaler(t->tcsr);
 }