Skip to content

Commit 63450f3

Browse files
xzpeterphilmd
authored andcommitted
qdev: Make qdev_get_machine() not use container_get()
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 <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Richard Henderson <[email protected]>
1 parent 558ee1e commit 63450f3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

hw/core/qdev.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,12 @@ Object *qdev_get_machine(void)
817817
static Object *dev;
818818

819819
if (dev == NULL) {
820-
dev = container_get(object_get_root(), "/machine");
820+
dev = object_resolve_path_component(object_get_root(), "machine");
821+
/*
822+
* Any call to this function before machine is created is treated
823+
* as a programming error as of now.
824+
*/
825+
assert(dev);
821826
}
822827

823828
return dev;

0 commit comments

Comments
 (0)