diff mbox series

[RFC,6/7] hw/intc/mips_gic: Initialize IRQ array once device is realized

Message ID 20240209123226.32576-7-philmd@linaro.org
State New
Headers show
Series hw/qdev: Split 'wiring' phase from 'realize' | expand

Commit Message

Philippe Mathieu-Daudé Feb. 9, 2024, 12:32 p.m. UTC
We shouldn't call qdev_get_gpio_in() on unrealized devices.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/intc/mips_gic.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/hw/intc/mips_gic.c b/hw/intc/mips_gic.c
index 77ba7348a3..05c8b8f4c4 100644
--- a/hw/intc/mips_gic.c
+++ b/hw/intc/mips_gic.c
@@ -419,7 +419,6 @@  static void mips_gic_realize(DeviceState *dev, Error **errp)
         return;
     }
     s->vps = g_new(MIPSGICVPState, s->num_vps);
-    s->irq_state = g_new(MIPSGICIRQState, s->num_irq);
     /* Register the env for all VPs with the GIC */
     for (i = 0; i < s->num_vps; i++) {
         if (cs != NULL) {
@@ -433,7 +432,14 @@  static void mips_gic_realize(DeviceState *dev, Error **errp)
     }
     s->gic_timer = mips_gictimer_init(s, s->num_vps, gic_timer_expire_cb);
     qdev_init_gpio_in(dev, gic_set_irq, s->num_irq);
-    for (i = 0; i < s->num_irq; i++) {
+}
+
+static void mips_gic_wire(DeviceState *dev)
+{
+    MIPSGICState *s = MIPS_GIC(dev);
+
+    s->irq_state = g_new(MIPSGICIRQState, s->num_irq);
+    for (unsigned i = 0; i < s->num_irq; i++) {
         s->irq_state[i].irq = qdev_get_gpio_in(dev, i);
     }
 }
@@ -450,6 +456,7 @@  static void mips_gic_class_init(ObjectClass *klass, void *data)
 
     device_class_set_props(dc, mips_gic_properties);
     dc->realize = mips_gic_realize;
+    dc->wire = mips_gic_wire;
 }
 
 static const TypeInfo mips_gic_info = {