1835
}
1836
}
1837
1838
-/*
1839
- * object_resolve_link:
1840
- *
1841
- * Lookup an object and ensure its type matches the link property type. This
1842
- * is similar to object_resolve_path() except type verification against the
1843
- * link property is performed.
1844
- *
1845
- * Returns: The matched object or NULL on path lookup failures.
1846
- */
1847
-static Object *object_resolve_link(Object *obj, const char *name,
1848
- const char *path, Error **errp)
1838
+Object *object_resolve_and_typecheck(const char *path, const char *name,
1839
+ const char *target_type, Error **errp)
1840
{
1850
- const char *type;
1851
- char *target_type;
1841
bool ambiguous = false;
1842
Object *target;
1843
1855
- /* Go from link<FOO> to FOO. */
1856
- type = object_property_get_type(obj, name, NULL);
1857
- target_type = g_strndup(&type[5], strlen(type) - 6);
1844
target = object_resolve_path_type(path, target_type, &ambiguous);
1845
1846
if (ambiguous) {
1857
}
1858
target = NULL;
1859
}
1874
- g_free(target_type);
1875
-
1860
return target;
1861
}
1862
1863
+/*
1864
+ * object_resolve_link:
1865
+ *
1866
+ * Lookup an object and ensure its type matches the link property type. This
1867
+ * is similar to object_resolve_path() except type verification against the
1868
+ * link property is performed.
1869
+ *
1870
+ * Returns: The matched object or NULL on path lookup failures.
1871
+ */
1872
+static Object *object_resolve_link(Object *obj, const char *name,
1873
+ const char *path, Error **errp)
1874
+{
1875
+ const char *type;
1876
+ g_autofree char *target_type = NULL;
1877
+
1878
+ /* Go from link<FOO> to FOO. */
1879
+ type = object_property_get_type(obj, name, NULL);
1880
+ target_type = g_strndup(&type[5], strlen(type) - 6);
1881
+ return object_resolve_and_typecheck(path, name, target_type, errp);
1882
+}
1883
+
1884
static void object_set_link_property(Object *obj, Visitor *v,
1885
const char *name, void *opaque,
1886
Error **errp)