[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 08/13] qdev: Make qdev_get_machine() not use container_get()
From: |
Peter Xu |
Subject: |
[PATCH v2 08/13] qdev: Make qdev_get_machine() not use container_get() |
Date: |
Thu, 21 Nov 2024 14:21:57 -0500 |
Currently, qdev_get_machine() has a slight misuse on container_get(), as
the helper says "get a container" but in reality the goal is to get the
machine object. It is still a "container" but not strictly.
Note that it _may_ get a container (at "/machine") in our current unit test
of test-qdev-global-props.c before all these changes, but it's probably
unexpected and worked by accident.
Switch to an explicit object_resolve_path_component(), with a side benefit
that qdev_get_machine() can happen a lot, and we don't need to split the
string ("/machine") every time. This also paves way for making the helper
container_get() never try to return a non-container at all.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
hw/core/qdev.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 5f13111b77..b622be15ee 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -817,7 +817,12 @@ Object *qdev_get_machine(void)
static Object *dev;
if (dev == NULL) {
- dev = container_get(object_get_root(), "/machine");
+ dev = object_resolve_path_component(object_get_root(), "machine");
+ /*
+ * Any call to this function before machine is created is treated
+ * as a programming error as of now.
+ */
+ assert(dev);
}
return dev;
--
2.45.0
- [PATCH v2 00/13] QOM: container_get() removal, Peter Xu, 2024/11/21
- [PATCH v2 01/13] qom: Add TYPE_CONTAINER macro, Peter Xu, 2024/11/21
- [PATCH v2 03/13] tests: Fix test-qdev-global-props on anonymous qdev realize(), Peter Xu, 2024/11/21
- [PATCH v2 02/13] qom: New object_property_add_new_container(), Peter Xu, 2024/11/21
- [PATCH v2 04/13] tests: Explicitly create containers in test_qom_partial_path(), Peter Xu, 2024/11/21
- [PATCH v2 07/13] qom: Create system containers explicitly, Peter Xu, 2024/11/21
- [PATCH v2 08/13] qdev: Make qdev_get_machine() not use container_get(),
Peter Xu <=
- [PATCH v2 05/13] ppc/e500: Avoid abuse of container_get(), Peter Xu, 2024/11/21
- [PATCH v2 06/13] hw/ppc: Explicitly create the drc container, Peter Xu, 2024/11/21
- [PATCH v2 10/13] qom: Use machine_get_container(), Peter Xu, 2024/11/21
- [PATCH v2 09/13] qdev: Add machine_get_container(), Peter Xu, 2024/11/21
- [PATCH v2 11/13] qom: Add object_get_container(), Peter Xu, 2024/11/21
- [PATCH v2 12/13] qom: Use object_get_container(), Peter Xu, 2024/11/21