[PATCH 24/24] qdev: Assert onboard devices all get realized properly

Markus Armbruster posted 24 patches 5 years, 6 months ago
Maintainers: Sagar Karandikar <sagark@eecs.berkeley.edu>, Fabien Chouteau <chouteau@adacore.com>, Peter Maydell <peter.maydell@linaro.org>, Alistair Francis <Alistair.Francis@wdc.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Alistair Francis <alistair@alistair23.me>, Paolo Bonzini <pbonzini@redhat.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Andrzej Zaborowski <balrogg@gmail.com>, KONRAD Frederic <frederic.konrad@adacore.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Eduardo Habkost <ehabkost@redhat.com>, Laurent Vivier <laurent@vivier.eu>, David Gibson <david@gibson.dropbear.id.au>, Palmer Dabbelt <palmer@dabbelt.com>
There is a newer version of this series
[PATCH 24/24] qdev: Assert onboard devices all get realized properly
Posted by Markus Armbruster 5 years, 6 months ago
This would have caught some of the bugs I just fixed.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/core/qdev.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 0df995eb94..fe2dea8968 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -429,6 +429,19 @@ void qdev_init_nofail(DeviceState *dev)
     object_unref(OBJECT(dev));
 }
 
+static int qdev_assert_realized_properly(Object *obj, void *opaque)
+{
+    DeviceState *dev = DEVICE(object_dynamic_cast(obj, TYPE_DEVICE));
+    DeviceClass *dc;
+
+    if (dev) {
+        dc = DEVICE_GET_CLASS(dev);
+        assert(dev->realized);
+        assert(dev->parent_bus || !dc->bus_type);
+    }
+    return 0;
+}
+
 void qdev_machine_creation_done(void)
 {
     /*
@@ -436,6 +449,9 @@ void qdev_machine_creation_done(void)
      * only create hotpluggable devices
      */
     qdev_hotplug = true;
+
+    object_child_foreach_recursive(object_get_root(),
+                                   qdev_assert_realized_properly, NULL);
 }
 
 bool qdev_machine_modified(void)
-- 
2.21.1


Re: [PATCH 24/24] qdev: Assert onboard devices all get realized properly
Posted by Philippe Mathieu-Daudé 5 years, 6 months ago
On 5/18/20 7:04 AM, Markus Armbruster wrote:
> This would have caught some of the bugs I just fixed.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   hw/core/qdev.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 0df995eb94..fe2dea8968 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -429,6 +429,19 @@ void qdev_init_nofail(DeviceState *dev)
>       object_unref(OBJECT(dev));
>   }
>   
> +static int qdev_assert_realized_properly(Object *obj, void *opaque)
> +{
> +    DeviceState *dev = DEVICE(object_dynamic_cast(obj, TYPE_DEVICE));
> +    DeviceClass *dc;
> +
> +    if (dev) {
> +        dc = DEVICE_GET_CLASS(dev);
> +        assert(dev->realized);
> +        assert(dev->parent_bus || !dc->bus_type);

Nice :)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +    }
> +    return 0;
> +}
> +
>   void qdev_machine_creation_done(void)
>   {
>       /*
> @@ -436,6 +449,9 @@ void qdev_machine_creation_done(void)
>        * only create hotpluggable devices
>        */
>       qdev_hotplug = true;
> +
> +    object_child_foreach_recursive(object_get_root(),
> +                                   qdev_assert_realized_properly, NULL);
>   }
>   
>   bool qdev_machine_modified(void)
>