@samitouri / QOSamiQemu / commits / 248e17e47a

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

Calling qdev_get_machine() from fsl_imx8mm_init() can trigger an assertion failure because the machine may not be created yet. Reproducer: ./qemu-system-aarch64 -S -display none \ -M virt -device fsl-imx8mm,help This hits: ../hw/core/qdev.c:844: Object *qdev_get_machine(void): Assertion `dev' failed. Move the CPU initialization into realize(), where accessing the machine state is safe. (This is the same issue we fixed in the fsl-imx8mp machine in commit b67d0bcdd41c; we apply the same fix here.) Signed-off-by: Vineet Agarwal <agarwal.vineet2006@gmail.com> Message-id: 20260511115918.32765-1-agarwal.vineet2006@gmail.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Vineet Agarwal committed May 15, 2026 at 08:41 UTC 248e17e47ae13308d00cad09ff4661789afef076
1 file changed +8 -7
hw/arm/fsl-imx8mm.c
+8 -7
@@ -157,16 +157,9 @@ static const struct {
157
158 static void fsl_imx8mm_init(Object *obj)
159 {
160 - MachineState *ms = MACHINE(qdev_get_machine());
160 FslImx8mmState *s = FSL_IMX8MM(obj);
162 - const char *cpu_type = ms->cpu_type ?: ARM_CPU_TYPE_NAME("cortex-a53");
161 int i;
162
165 - for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MM_NUM_CPUS); i++) {
166 - g_autofree char *name = g_strdup_printf("cpu%d", i);
167 - object_initialize_child(obj, name, &s->cpu[i], cpu_type);
168 - }
169 -
163 object_initialize_child(obj, "gic", &s->gic, gicv3_class_name());
164
165 object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX8MP_CCM);
@@ -229,6 +222,8 @@ static void fsl_imx8mm_realize(DeviceState *dev, Error **errp)
222 MachineState *ms = MACHINE(qdev_get_machine());
223 FslImx8mmState *s = FSL_IMX8MM(dev);
224 DeviceState *gicdev = DEVICE(&s->gic);
225 + const char *cpu_type =
226 + ms->cpu_type ?: ARM_CPU_TYPE_NAME("cortex-a53");
227 int i;
228
229 if (ms->smp.cpus > FSL_IMX8MM_NUM_CPUS) {
@@ -237,6 +232,12 @@ static void fsl_imx8mm_realize(DeviceState *dev, Error **errp)
232 return;
233 }
234
235 + for (i = 0; i < ms->smp.cpus; i++) {
236 + g_autofree char *name = g_strdup_printf("cpu%d", i);
237 + object_initialize_child(OBJECT(dev), name,
238 + &s->cpu[i], cpu_type);
239 + }
240 +
241 /* CPUs */
242 for (i = 0; i < ms->smp.cpus; i++) {
243 /* On uniprocessor, the CBAR is set to 0 */