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/qdev-properties.h | 10 ++++++++++ hw/core/qdev-properties.c | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index f064992ba3..bf90cac810 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -241,6 +241,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 7d1a443266..ede173d57b 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1108,10 +1108,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) { @@ -1188,7 +1187,7 @@ void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n) const Property *prop = &props[i]; assert(prop->name); qdev_class_add_legacy_property(dc, prop); - qdev_class_add_property(dc, prop->name, prop); + object_class_add_property(OBJECT_CLASS(dc), prop); } } -- 2.50.1
