hw/core: Introduce device_class_set_props_n

Record the size of the array in DeviceClass.props_count_.
Iterate with known count in qdev_prop_walk.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Lei Yang <leiyang@redhat.com>
Link: https://lore.kernel.org/r/20241218134251.4724-14-richard.henderson@linaro.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Richard Henderson 2024-12-18 07:42:40 -06:00 committed by Paolo Bonzini
parent 588611972f
commit cb9f4b28ee
4 changed files with 55 additions and 18 deletions

View file

@ -138,6 +138,12 @@ struct DeviceClass {
*/
const Property *props_;
/**
* @props_count_: number of elements in @props_; should only be
* assigned by using device_class_set_props().
*/
uint16_t props_count_;
/**
* @user_creatable: Can user instantiate with -device / device_add?
*
@ -960,6 +966,18 @@ void device_class_set_props(DeviceClass *dc, const Property *props);
(device_class_set_props)((dc), (props)); \
} while (0)
/**
* device_class_set_props_n(): add a set of properties to an device
* @dc: the parent DeviceClass all devices inherit
* @props: an array of properties, not terminated by DEFINE_PROP_END_OF_LIST.
* @n: ARRAY_SIZE(@props)
*
* This will add a set of properties to the object. It will fault if
* you attempt to add an existing property defined by a parent class.
* To modify an inherited property you need to use????
*/
void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n);
/**
* device_class_set_parent_realize() - set up for chaining realize fns
* @dc: The device class