Skip to content

Commit d8d9581

Browse files
committed
memory: convert memory_region_destroy to object_unparent
Explicitly call object_unparent in the few places where we will re-create the memory region. If the memory region is simply being destroyed as part of device teardown, let QOM handle it. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e3fb0ad commit d8d9581

File tree

9 files changed

+18
-14
lines changed

9 files changed

+18
-14
lines changed

docs/memory.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,16 @@ Region lifecycle
7474
----------------
7575

7676
A region is created by one of the constructor functions (memory_region_init*())
77-
and destroyed by the destructor (memory_region_destroy()). In between,
78-
a region can be added to an address space by using memory_region_add_subregion()
79-
and removed using memory_region_del_subregion(). Region attributes may be
80-
changed at any point; they take effect once the region becomes exposed to the
81-
guest.
77+
and attached to an object. It is then destroyed by object_unparent() or simply
78+
when the parent object dies.
79+
80+
In between, a region can be added to an address space
81+
by using memory_region_add_subregion() and removed using
82+
memory_region_del_subregion(). Destroying the region implicitly
83+
removes the region from the address space.
84+
85+
Region attributes may be changed at any point; they take effect once
86+
the region becomes exposed to the guest.
8287

8388
Overlapping regions and priority
8489
--------------------------------

hw/display/vga.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void vga_update_memory_access(VGACommonState *s)
176176

177177
if (s->has_chain4_alias) {
178178
memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
179-
memory_region_destroy(&s->chain4_alias);
179+
object_unparent(OBJECT(&s->chain4_alias));
180180
s->has_chain4_alias = false;
181181
s->plane_updated = 0xf;
182182
}

hw/i386/kvmvapic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static int vapic_map_rom_writable(VAPICROMState *s)
584584

585585
if (s->rom_mapped_writable) {
586586
memory_region_del_subregion(as, &s->rom);
587-
memory_region_destroy(&s->rom);
587+
object_unparent(OBJECT(&s->rom));
588588
}
589589

590590
/* grab RAM memory region (region @rom_paddr may still be pc.rom) */

hw/mips/gt64xxx_pci.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static void gt64120_pci_mapping(GT64120State *s)
297297
if (s->PCI0IO_length)
298298
{
299299
memory_region_del_subregion(get_system_memory(), &s->PCI0IO_mem);
300-
memory_region_destroy(&s->PCI0IO_mem);
300+
object_unparent(OBJECT(&s->PCI0IO_mem));
301301
}
302302
/* Map new IO address */
303303
s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;

hw/misc/omap_gpmc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static void omap_gpmc_cs_unmap(struct omap_gpmc_s *s, int cs)
436436
}
437437
memory_region_del_subregion(get_system_memory(), &f->container);
438438
memory_region_del_subregion(&f->container, omap_gpmc_cs_memregion(s, cs));
439-
memory_region_destroy(&f->container);
439+
object_unparent(OBJECT(&f->container));
440440
}
441441

442442
void omap_gpmc_reset(struct omap_gpmc_s *s)

hw/misc/vfio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ static void vfio_vga_quirk_teardown(VFIODevice *vdev)
22662266
while (!QLIST_EMPTY(&vdev->vga.region[i].quirks)) {
22672267
VFIOQuirk *quirk = QLIST_FIRST(&vdev->vga.region[i].quirks);
22682268
memory_region_del_subregion(&vdev->vga.region[i].mem, &quirk->mem);
2269-
memory_region_destroy(&quirk->mem);
2269+
object_unparent(OBJECT(&quirk->mem));
22702270
QLIST_REMOVE(quirk, next);
22712271
g_free(quirk);
22722272
}
@@ -2290,7 +2290,7 @@ static void vfio_bar_quirk_teardown(VFIODevice *vdev, int nr)
22902290
while (!QLIST_EMPTY(&bar->quirks)) {
22912291
VFIOQuirk *quirk = QLIST_FIRST(&bar->quirks);
22922292
memory_region_del_subregion(&bar->mem, &quirk->mem);
2293-
memory_region_destroy(&quirk->mem);
2293+
object_unparent(OBJECT(&quirk->mem));
22942294
QLIST_REMOVE(quirk, next);
22952295
g_free(quirk);
22962296
}

hw/ppc/ppc4xx_devs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static void sdram_set_bcr(ppc4xx_sdram_t *sdram,
422422
&sdram->containers[n]);
423423
memory_region_del_subregion(&sdram->containers[n],
424424
&sdram->ram_memories[n]);
425-
memory_region_destroy(&sdram->containers[n]);
425+
object_unparent(OBJECT(&sdram->containers[n]));
426426
}
427427
*bcrp = bcr & 0xFFDEE001;
428428
if (enabled && (bcr & 0x00000001)) {

ioport.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void portio_list_destroy(PortioList *piolist)
154154

155155
for (i = 0; i < piolist->nr; ++i) {
156156
mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
157-
memory_region_destroy(&mrpio->mr);
157+
object_unparent(OBJECT(&mrpio->mr));
158158
g_free(mrpio);
159159
}
160160
g_free(piolist->regions);

memory.c

-1
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,6 @@ static void memory_region_finalize(Object *obj)
12661266

12671267
void memory_region_destroy(MemoryRegion *mr)
12681268
{
1269-
object_unparent(OBJECT(mr));
12701269
}
12711270

12721271

0 commit comments

Comments
 (0)