@samitouri / QOSamiQemu / commits / 2a13e31073

hw/display/tcx: Init memory regions in realize

Thomas reported test failure: $ export QTEST_QEMU_BINARY=./qemu-system-sparc $ tests/qtest/device-introspect-test -m thorough ... # Testing device 'sun-tcx' RAMBlock "tcx.prom" already registered, abort! Broken pipe ../../devel/qemu/tests/qtest/libqtest.c:210: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped) Aborted (core dumped) Issue is the qom introspect test will create yet another sun-tcx device causing double register of the memory region. Fix it by removing the init method and move memory region creation in realize. Reported-by: Thomas Huth <thuth@redhat.com> Link: https://lore.kernel.org/r/3b87e6d9-a027-4dcd-a995-857e16c8b2e6@redhat.com Fixes: 653c4fa5b0 hw/display/{cg3.tcx}: Do not use memory_region_init_rom_nomigrate Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Link: https://lore.kernel.org/r/20260316130651.5C8735968DE@zero.eik.bme.hu [peterx: amend commit message, fix tag, add link] Signed-off-by: Peter Xu <peterx@redhat.com>

BALATON Zoltan committed Mar 16, 2026 at 14:06 UTC 2a13e310732154f75a02be54e2b32524cc869417
1 file changed +9 -15
hw/display/tcx.c
+9 -15
@@ -751,10 +751,15 @@ static const GraphicHwOps tcx24_ops = {
751 .gfx_update = tcx24_update_display,
752 };
753
754 -static void tcx_initfn(Object *obj)
754 +static void tcx_realize(DeviceState *dev, Error **errp)
755 {
756 - SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
757 - TCXState *s = TCX(obj);
756 + SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
757 + TCXState *s = TCX(dev);
758 + Object *obj = OBJECT(dev);
759 + ram_addr_t vram_offset = 0;
760 + int size, ret;
761 + uint8_t *vram_base;
762 + char *fcode_filename;
763
764 memory_region_init_rom(&s->rom, obj, "tcx.prom", FCODE_MAX_ROM_SIZE,
765 &error_fatal);
@@ -804,16 +809,6 @@ static void tcx_initfn(Object *obj)
809 memory_region_init_io(&s->alt, obj, &tcx_dummy_ops, s, "tcx.alt",
810 TCX_ALT_NREGS);
811 sysbus_init_mmio(sbd, &s->alt);
807 -}
808 -
809 -static void tcx_realizefn(DeviceState *dev, Error **errp)
810 -{
811 - SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
812 - TCXState *s = TCX(dev);
813 - ram_addr_t vram_offset = 0;
814 - int size, ret;
815 - uint8_t *vram_base;
816 - char *fcode_filename;
812
813 memory_region_init_ram(&s->vram_mem, OBJECT(s), "tcx.vram",
814 s->vram_size * (1 + 4 + 4), &error_fatal);
@@ -887,7 +882,7 @@ static void tcx_class_init(ObjectClass *klass, const void *data)
882 {
883 DeviceClass *dc = DEVICE_CLASS(klass);
884
890 - dc->realize = tcx_realizefn;
885 + dc->realize = tcx_realize;
886 device_class_set_legacy_reset(dc, tcx_reset);
887 dc->vmsd = &vmstate_tcx;
888 device_class_set_props(dc, tcx_properties);
@@ -897,7 +892,6 @@ static const TypeInfo tcx_info = {
892 .name = TYPE_TCX,
893 .parent = TYPE_SYS_BUS_DEVICE,
894 .instance_size = sizeof(TCXState),
900 - .instance_init = tcx_initfn,
895 .class_init = tcx_class_init,
896 };
897