ptimer_get_count() returns incorrect value for the disabled timer after reloading the counter with a small value, because corrected limit value is used instead of the original.
For instance: 1) ptimer_stop(t) 2) ptimer_set_period(t, 1) 3) ptimer_set_limit(t, 0, 1) 4) ptimer_get_count(t) <-- would return 10000 instead of 0 Signed-off-by: Dmitry Osipenko <dig...@gmail.com> --- hw/core/ptimer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 8437bd6..abc3a20 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -180,6 +180,8 @@ void ptimer_set_freq(ptimer_state *s, uint32_t freq) count = limit. */ void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload) { + uint64_t count = limit; + /* * Artificially limit timeout rate to something * achievable under QEMU. Otherwise, QEMU spends all @@ -195,7 +197,7 @@ void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload) s->limit = limit; if (reload) - s->delta = limit; + s->delta = count; if (s->enabled && reload) { s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); ptimer_reload(s); -- 2.6.0