hw/net/can/flexcan: Wire clock control module via link property
When wiring struct FlexcanState to the clock control module, it is currently necessary to reach into its private data. Moreover, when forgetting to wire the clock control module, QEMU will crash after the guest has already started. Fix both by letting struct FlexcanState expose a link property whose sanity is checked at realize time. Suggested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Bernhard Beschow <shentey@gmail.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Acked-by: Pavel Pisa <pisa@fel.cvut.cz> Tested-by: Pavel Pisa <pisa@fel.cvut.cz> Message-ID: <20260702184038.178196-2-shentey@gmail.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Bernhard Beschow committed
Jul 2, 2026 at 20:40 UTC
2afca7a59268e956f826dfc21486d219c1446798
2 files changed
+10
-3
hw/arm/fsl-imx6.c
+2
-1
@@ -391,7 +391,8 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
391
{ FSL_IMX6_CAN2_ADDR, FSL_IMX6_FLEXCAN2_IRQ },
392
};
393
394
- s->flexcan[i].ccm = IMX_CCM(&s->ccm);
394
+ object_property_set_link(OBJECT(&s->flexcan[i]), "clock-control-module",
395
+ OBJECT(&s->ccm), &error_abort);
396
object_property_set_link(OBJECT(&s->flexcan[i]), "canbus",
397
OBJECT(s->canbus[i]), &error_abort);
398
hw/net/can/flexcan.c
+8
-2
@@ -333,8 +333,6 @@ static uint32_t flexcan_get_bitrate(FlexcanState *s)
333
334
uint32_t pe_freq, s_freq, bitrate;
335
336
- assert(s->ccm);
337
-
336
/* s_freq: CAN clock from CCM divided by the prescaler */
337
pe_freq = imx_ccm_get_clock_frequency(s->ccm, CLK_CAN);
338
s_freq = pe_freq / (1 + conf_presdiv);
@@ -1346,6 +1344,12 @@ static void flexcan_realize(DeviceState *dev, Error **errp)
1344
}
1345
}
1346
1347
+ if (!s->ccm) {
1348
+ error_setg(errp, "%s 'clock-control-module' link property not set",
1349
+ dev->canonical_path);
1350
+ return;
1351
+ }
1352
+
1353
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
1354
sysbus_init_irq(SYS_BUS_DEVICE(SYS_BUS_DEVICE(dev)), &s->irq);
1355
}
@@ -1366,6 +1370,8 @@ static const VMStateDescription vmstate_can = {
1370
static const Property flexcan_properties[] = {
1371
DEFINE_PROP_LINK("canbus", FlexcanState, canbus, TYPE_CAN_BUS,
1372
CanBusState *),
1373
+ DEFINE_PROP_LINK("clock-control-module", FlexcanState, ccm, TYPE_IMX_CCM,
1374
+ IMXCCMState *),
1375
};
1376
1377
static void flexcan_class_init(ObjectClass *klass, const void *data)