@samitouri / QOSamiQemu / commits / 99757d5574

hw/arm: fsl-imx7: Don't call qdev_get_machine in soc init

Calling qdev_get_machine() in the soc_init function would result in the following assert ../hw/core/qdev.c:858: qdev_get_machine: Assertion `dev' failed. when trying to run ./qemu-system-aarch64 -S -display none -M virt -device fsl-imx7,help as the machine wasn't created yet. We call qdev_get_machine() to obtain the number of CPUs in the machine. So instead of initialising the CPUs in the SoC init let's instead do it in the realise where the machine will exist. Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Tested-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20260312043158.4191378-5-alistair.francis@wdc.com> Signed-off-by: Thomas Huth <thuth@redhat.com>

Alistair Francis committed Mar 12, 2026 at 14:31 UTC 99757d557437dbcf57a3d43fe7427fe89f248ef3
1 file changed +9 -10
hw/arm/fsl-imx7.c
+9 -10
@@ -32,20 +32,10 @@
32
33 static void fsl_imx7_init(Object *obj)
34 {
35 - MachineState *ms = MACHINE(qdev_get_machine());
35 FslIMX7State *s = FSL_IMX7(obj);
36 char name[NAME_SIZE];
37 int i;
38
40 - /*
41 - * CPUs
42 - */
43 - for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX7_NUM_CPUS); i++) {
44 - snprintf(name, NAME_SIZE, "cpu%d", i);
45 - object_initialize_child(obj, name, &s->cpu[i],
46 - ARM_CPU_TYPE_NAME("cortex-a7"));
47 - }
48 -
39 /*
40 * A7MPCORE
41 */
@@ -179,6 +169,15 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
169 return;
170 }
171
172 + /*
173 + * CPUs
174 + */
175 + for (i = 0; i < smp_cpus; i++) {
176 + snprintf(name, NAME_SIZE, "cpu%d", i);
177 + object_initialize_child(OBJECT(dev), name, &s->cpu[i],
178 + ARM_CPU_TYPE_NAME("cortex-a7"));
179 + }
180 +
181 /*
182 * CPUs
183 */