diff mbox series

[2/2] qemu/timer: Sanity check timer_list in timer_init_full()

Message ID 20250125182425.59708-3-philmd@linaro.org
State New
Headers show
Series qemu/timer: Clarify QEMUTimer new/free API | expand

Commit Message

Philippe Mathieu-Daudé Jan. 25, 2025, 6:24 p.m. UTC
Ensure we are not re-initializing a QEMUTimer already added
to an active list. timer_init*() functions expect either
a recently created and zeroed QEMUTimer, or one previously
free'd with timer_free().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/timer.h | 2 +-
 util/qemu-timer.c    | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index abd2204f3be..4717693f950 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -407,7 +407,7 @@  int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg);
  * (or default timer list group, if NULL).
  * The caller is responsible for allocating the memory.
  *
- * You need not call an explicit deinit call. Simply make
+ * You need not call an explicit timer_deinit() call. Simply make
  * sure it is not on a list with timer_del.
  */
 void timer_init_full(QEMUTimer *ts,
diff --git a/util/qemu-timer.c b/util/qemu-timer.c
index 0e8a453eaa1..058cae6e487 100644
--- a/util/qemu-timer.c
+++ b/util/qemu-timer.c
@@ -354,6 +354,7 @@  void timer_init_full(QEMUTimer *ts,
     if (!timer_list_group) {
         timer_list_group = &main_loop_tlg;
     }
+    assert(ts->timer_list == NULL);
     ts->timer_list = timer_list_group->tl[type];
     ts->cb = cb;
     ts->opaque = opaque;