[RFC PATCH v2 079/137] hw/audio: Give -audio model= devices a QOM parent

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
audio_model_devices_init() is the '-audio model=' command-line path,
so parent the created device under /machine/peripheral-anon like
-device without id= would.

The intel-hda .init helper for '-audio model=hda' additionally
creates an hda-duplex codec on the controller's HDA bus; the codec
is a natural child of the controller device it just spawned.

Both sites drop the extra unref: the child<> property now holds the
reference.

AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/audio/intel-hda.c | 4 ++--
 hw/audio/model.c     | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index cd4743a405..f51c98511a 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -1313,9 +1313,9 @@ static void intel_hda_and_codec_init(const char *audiodev)
     intel_hda = qdev_device_add_from_qdict(props, false, &error_fatal);
     hdabus = QLIST_FIRST(&intel_hda->child_bus);
 
-    codec = qdev_new_orphan("hda-duplex");
+    codec = qdev_new(OBJECT(intel_hda), "codec", "hda-duplex");
     qdev_prop_set_string(codec, "audiodev", audiodev);
-    qdev_realize_and_unref(codec, hdabus, &error_fatal);
+    qdev_realize(codec, hdabus, &error_fatal);
     object_unref(intel_hda);
 }
 
diff --git a/hw/audio/model.c b/hw/audio/model.c
index bd8ca35153..308b899459 100644
--- a/hw/audio/model.c
+++ b/hw/audio/model.c
@@ -110,10 +110,11 @@ void audio_model_init(void)
     }
 
     if (c->typename) {
-        DeviceState *dev = qdev_new_orphan(c->typename);
+        DeviceState *dev = qdev_new(machine_get_container("peripheral-anon"),
+                                    "audio[*]", c->typename);
         BusState *bus = qdev_find_default_bus(DEVICE_GET_CLASS(dev), &error_fatal);
         qdev_prop_set_string(dev, "audiodev", audiodev_id);
-        qdev_realize_and_unref(dev, bus, &error_fatal);
+        qdev_realize(dev, bus, &error_fatal);
     } else {
         c->init(audiodev_id);
     }
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.