Now that every named memory region in the tree passes an explicit
owner, replace the /machine/unattached fallback in
memory_region_do_init() and portio_list_add_1() with an assertion.

Anonymous (name==NULL) regions such as subpages and io_mem_unassigned
are never QOM-parented and continue to accept a NULL owner.

Assisted-by: Kiro
Signed-off-by: Alexander Graf <[email protected]>
---
 system/ioport.c | 7 ++-----
 system/memory.c | 7 +++----
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/system/ioport.c b/system/ioport.c
index 0a1b80f299..0415b3cd60 100644
--- a/system/ioport.c
+++ b/system/ioport.c
@@ -248,11 +248,8 @@ static void portio_list_add_1(PortioList *piolist,
     /* Reparent the MemoryRegion to the piolist owner */
     object_ref(&mrpio->mr);
     object_unparent(OBJECT(&mrpio->mr));
-    if (!piolist->owner) {
-        owner = machine_get_container("unattached");
-    } else {
-        owner = piolist->owner;
-    }
+    g_assert(piolist->owner);
+    owner = piolist->owner;
     name = g_strdup_printf("%s[*]", piolist->name);
     object_property_add_child(owner, name, OBJECT(&mrpio->mr));
     g_free(name);
diff --git a/system/memory.c b/system/memory.c
index e3ee0416cc..f3a77197df 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1230,14 +1230,13 @@ static void memory_region_do_init(MemoryRegion *mr,
     mr->dev = (DeviceState *) object_dynamic_cast(mr->owner, TYPE_DEVICE);
     mr->ram_block = NULL;
 
+    /* A named MemoryRegion is a QOM child of @owner */
+    g_assert(!name || owner);
+
     if (name) {
         char *escaped_name = memory_region_escape_name(name);
         char *name_array = g_strdup_printf("%s[*]", escaped_name);
 
-        if (!owner) {
-            owner = machine_get_container("unattached");
-        }
-
         object_property_add_child(owner, name_array, OBJECT(mr));
         object_unref(OBJECT(mr));
         g_free(name_array);
-- 
2.47.1


Reply via email to