aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rauer <crauer@google.com>2023-09-22 18:14:11 +0000
committerPeter Maydell <peter.maydell@linaro.org>2023-10-19 14:32:13 +0100
commit9ef2629712680e70cbf39d8b6cb1ec0e0e2e72fa (patch)
tree5ff22d3462fc16295e127422f8d6b419b23e0295
parent3a45f4f5376cad9489e1608f2e4960fd34805546 (diff)
hw/timer/npcm7xx_timer: Prevent timer from counting down past zero
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>
-rw-r--r--hw/timer/npcm7xx_timer.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
index 32f5e021f8..a8bd93aeb2 100644
--- a/hw/timer/npcm7xx_timer.c
+++ b/hw/timer/npcm7xx_timer.c
@@ -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);
}