diff mbox series

[11/12] hw/sysbus: Ensure device is not realized before adding MMIO region

Message ID 20231018141151.87466-12-philmd@linaro.org
State New
Headers show
Series hw: Strengthen SysBus & QBus API | expand

Commit Message

Philippe Mathieu-Daudé Oct. 18, 2023, 2:11 p.m. UTC
sysbus_init_mmio() should not be called on realized device.

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

Comments

Thomas Huth Oct. 18, 2023, 4:10 p.m. UTC | #1
On 18/10/2023 16.11, Philippe Mathieu-Daudé wrote:
> sysbus_init_mmio() should not be called on realized device.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/core/sysbus.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
> index 35f902b582..ce54e2c416 100644
> --- a/hw/core/sysbus.c
> +++ b/hw/core/sysbus.c
> @@ -192,6 +192,11 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory)
>       int n;
>   
>       assert(dev->num_mmio < QDEV_MAX_MMIO);
> +    if (DEVICE(dev)->realized) {
> +        error_report("sysbus_init_mmio(type:%s) but object is realized",
> +                     object_get_typename(OBJECT(dev)));
> +        abort();
> +    }
>       n = dev->num_mmio++;
>       dev->mmio[n].addr = -1;
>       dev->mmio[n].memory = memory;

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

Patch

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 35f902b582..ce54e2c416 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -192,6 +192,11 @@  void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory)
     int n;
 
     assert(dev->num_mmio < QDEV_MAX_MMIO);
+    if (DEVICE(dev)->realized) {
+        error_report("sysbus_init_mmio(type:%s) but object is realized",
+                     object_get_typename(OBJECT(dev)));
+        abort();
+    }
     n = dev->num_mmio++;
     dev->mmio[n].addr = -1;
     dev->mmio[n].memory = memory;