Firstly, qdev_class_add_property() function almost has nothing to do with DeviceClass, it's a bridge between Property and object properties.
Change the 1st parameter of it, so that it can be used without DeviceClass context at all. When at it, remove the "name" field because it's always prop->name. Export it for non-qdev use cases. Signed-off-by: Peter Xu <[email protected]> --- include/hw/core/qdev-properties.h | 10 ++++++++++ hw/core/qdev-properties.c | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h index 779acb31b6..fec2aaac4d 100644 --- a/include/hw/core/qdev-properties.h +++ b/include/hw/core/qdev-properties.h @@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, */ void qdev_property_add_static(DeviceState *dev, const Property *prop); +/** + * object_class_add_property: + * @oc: Object class to operate on. + * @prop: The qdev property definition. + * + * Add a Property to @oc. This is the bridge to convert a Property into + * an object class property (as in ObjectClass.properties). + */ +void object_class_add_property(ObjectClass *oc, const Property *prop); + /** * qdev_alias_all_properties: Create aliases on source for all target properties * @target: Device which has properties to be aliased diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index a91c2ad101..ab828bb612 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1188,10 +1188,9 @@ void qdev_property_add_static(DeviceState *dev, const Property *prop) } } -static void qdev_class_add_property(DeviceClass *klass, const char *name, - const Property *prop) +void object_class_add_property(ObjectClass *oc, const Property *prop) { - ObjectClass *oc = OBJECT_CLASS(klass); + const char *name = prop->name; ObjectProperty *op; if (prop->info->create) { @@ -1222,7 +1221,7 @@ void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n) for (size_t i = 0; i < n; ++i) { const Property *prop = &props[i]; assert(prop->name); - qdev_class_add_property(dc, prop->name, prop); + object_class_add_property(OBJECT_CLASS(dc), prop); } } -- 2.53.0
