diff mbox series

[2/2] qdev: Ensure devices are fully realized when calling DeviceReset handler

Message ID 20230918101736.23905-3-philmd@linaro.org
State New
Headers show
Series qdev: Ensure devices are fully realized when calling DeviceReset handler | expand

Commit Message

Philippe Mathieu-Daudé Sept. 18, 2023, 10:17 a.m. UTC
We shouldn't call a DeviceReset() handler on unrealized device.
In order to enforce that, add an assertion.

CPU devices are a bit particular because we manually reset them
in various places, so corner case them out for now.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/qdev.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 43d863b0c5..c51b4c98de 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -252,6 +252,8 @@  void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
 
 void device_cold_reset(DeviceState *dev)
 {
+    /* TODO: Also cover CPUs once we removed manual calls to cpu_reset() */
+    assert(object_dynamic_cast(OBJECT(dev), TYPE_CPU) || dev->realized);
     resettable_reset(OBJECT(dev), RESET_TYPE_COLD);
 }
 
@@ -280,6 +282,7 @@  static void device_reset_child_foreach(Object *obj, ResettableChildCallback cb,
 bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 {
     assert(!dev->realized && !dev->parent_bus);
+    assert(!device_is_in_reset(dev));
 
     if (bus) {
         if (!qdev_set_parent_bus(dev, bus, errp)) {