[PATCH 10/12] hw/qdev: Ensure parent device is not realized before adding bus

Philippe Mathieu-Daudé posted 12 patches 1 year, 1 month ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Richard Henderson <richard.henderson@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Peter Xu <peterx@redhat.com>, Jason Wang <jasowang@redhat.com>, Sergio Lopez <slp@redhat.com>, Song Gao <gaosong@loongson.cn>, Beniamino Galvani <b.galvani@gmail.com>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, Huacai Chen <chenhuacai@kernel.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>
There is a newer version of this series
[PATCH 10/12] hw/qdev: Ensure parent device is not realized before adding bus
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
qbus_new() should not be called on realized device.

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

diff --git a/hw/core/bus.c b/hw/core/bus.c
index c7831b5293..c92d07667b 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -21,6 +21,7 @@
 #include "hw/qdev-properties.h"
 #include "qemu/ctype.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "qapi/error.h"
 
 void qbus_set_hotplug_handler(BusState *bus, Object *handler)
@@ -163,6 +164,12 @@ BusState *qbus_new(const char *typename, DeviceState *parent, const char *name)
 {
     BusState *bus;
 
+    if (parent->realized) {
+        error_report("qbus_new(type:%s parent:%s, name:%s) but parent realized",
+                     typename, object_get_typename(OBJECT(parent)), name);
+        abort();
+    }
+
     bus = BUS(object_new(typename));
     qbus_init_internal(bus, parent, name);
 
-- 
2.41.0


Re: [PATCH 10/12] hw/qdev: Ensure parent device is not realized before adding bus
Posted by Thomas Huth 1 year, 1 month ago
On 18/10/2023 16.11, Philippe Mathieu-Daudé wrote:
> qbus_new() should not be called on realized device.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/core/bus.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/hw/core/bus.c b/hw/core/bus.c
> index c7831b5293..c92d07667b 100644
> --- a/hw/core/bus.c
> +++ b/hw/core/bus.c
> @@ -21,6 +21,7 @@
>   #include "hw/qdev-properties.h"
>   #include "qemu/ctype.h"
>   #include "qemu/module.h"
> +#include "qemu/error-report.h"
>   #include "qapi/error.h"
>   
>   void qbus_set_hotplug_handler(BusState *bus, Object *handler)
> @@ -163,6 +164,12 @@ BusState *qbus_new(const char *typename, DeviceState *parent, const char *name)
>   {
>       BusState *bus;
>   
> +    if (parent->realized) {
> +        error_report("qbus_new(type:%s parent:%s, name:%s) but parent realized",
> +                     typename, object_get_typename(OBJECT(parent)), name);
> +        abort();
> +    }
> +
>       bus = BUS(object_new(typename));
>       qbus_init_internal(bus, parent, name);
>   

Sounds like a good idea!

Reviewed-by: Thomas Huth <thuth@redhat.com>