On Tue, 28 Oct 2025, Philippe Mathieu-Daudé wrote:
On 27/10/25 20:47, BALATON Zoltan wrote:
On Mon, 27 Oct 2025, Philippe Mathieu-Daudé wrote:
On 25/10/25 01:31, BALATON Zoltan wrote:
These memory windows are a result of the address decoding in the
Articia S north bridge so better model it there and not in board code.

Suggested-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: BALATON Zoltan <[email protected]>
---
  hw/pci-host/articia.c | 15 ++++++++++++++-
  hw/ppc/amigaone.c     | 28 +++++-----------------------
  hw/ppc/pegasos2.c     | 13 -------------
  3 files changed, 19 insertions(+), 37 deletions(-)


@@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **errp)
  {
      ArticiaState *s = ARTICIA(dev);
      PCIHostState *h = PCI_HOST_BRIDGE(dev);
+    MemoryRegion *mr;
      PCIDevice *pdev;
        bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus"));
@@ -180,6 +186,14 @@ static void articia_realize(DeviceState *dev, Error **errp)
      memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s,
                            TYPE_ARTICIA, 0x1000000);
      memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1);
+    mr = g_new(MemoryRegion, 1);

Won't Coverity or other analysis tools complain about the leak?
(this is why we usually keep a reference in the device state, here
ArticiaState). Otherwise:

According to https://www.qemu.org/docs/master/devel/memory.html#region- lifecycle there should be no leak and keeping a reference should not be necessary as the lifetime is managed by attaching it to the owner object so no need to keep a reference when it's not needed otherwise. Not littering the state struct with unneded references makes it easier to comprehend so I'd only keep things there that are necessary.

IIUC this doc is about what happens within the allocated MemoryRegion,
regardless of where it is allocated.

That doc explicitely says:

"Destruction of a memory region happens automatically when the owner object dies. When there are multiple memory regions under the same owner object, the memory API will guarantee all memory regions will be properly detached and finalized one by one. The order in which memory regions will be finalized is not guaranteed."

(and these pci-host objects are created once at machine init and never die so the question seems quite theoretical). I'd like to keep object state simple and not keep around references in it that nothing uses and should be managed automatically. I'd only add fields to the state struct that other methods need.

Regards,
BALATON Zoltan

Reply via email to