mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-21 00:53:27 -06:00
include/hw/qdev-core: Detect most empty Property lists at compile time
Add a macro expansion of device_class_set_props which can check on the type and size of PROPS before calling the function. Avoid the macro in migration.c because migration_properties is defined externally with indeterminate size. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Tested-by: Lei Yang <leiyang@redhat.com> Link: https://lore.kernel.org/r/20241218134251.4724-13-richard.henderson@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
2885bf891a
commit
588611972f
3 changed files with 19 additions and 2 deletions
|
@ -1061,7 +1061,7 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, const Property *prop
|
||||||
NULL, NULL, (Property *)prop);
|
NULL, NULL, (Property *)prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_class_set_props(DeviceClass *dc, const Property *props)
|
void (device_class_set_props)(DeviceClass *dc, const Property *props)
|
||||||
{
|
{
|
||||||
const Property *prop;
|
const Property *prop;
|
||||||
|
|
||||||
|
|
|
@ -940,9 +940,26 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
|
||||||
* This will add a set of properties to the object. It will fault if
|
* 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.
|
* you attempt to add an existing property defined by a parent class.
|
||||||
* To modify an inherited property you need to use????
|
* To modify an inherited property you need to use????
|
||||||
|
*
|
||||||
|
* Validate that @props has at least one Property plus the terminator.
|
||||||
|
* Validate that the array is terminated at compile-time (with -O2),
|
||||||
|
* which requires the array to be const.
|
||||||
*/
|
*/
|
||||||
void device_class_set_props(DeviceClass *dc, const Property *props);
|
void device_class_set_props(DeviceClass *dc, const Property *props);
|
||||||
|
|
||||||
|
#define device_class_set_props(dc, props) \
|
||||||
|
do { \
|
||||||
|
QEMU_BUILD_BUG_ON(sizeof(props) != sizeof(const Property *) && \
|
||||||
|
sizeof(props) < 2 * sizeof(Property)); \
|
||||||
|
if (sizeof(props) != sizeof(const Property *)) { \
|
||||||
|
size_t props_count_ = sizeof(props) / sizeof(Property) - 1; \
|
||||||
|
if ((props)[props_count_].name != NULL) { \
|
||||||
|
qemu_build_not_reached(); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
(device_class_set_props)((dc), (props)); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* device_class_set_parent_realize() - set up for chaining realize fns
|
* device_class_set_parent_realize() - set up for chaining realize fns
|
||||||
* @dc: The device class
|
* @dc: The device class
|
||||||
|
|
|
@ -3822,7 +3822,7 @@ static void migration_class_init(ObjectClass *klass, void *data)
|
||||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||||
|
|
||||||
dc->user_creatable = false;
|
dc->user_creatable = false;
|
||||||
device_class_set_props(dc, migration_properties);
|
(device_class_set_props)(dc, migration_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void migration_instance_finalize(Object *obj)
|
static void migration_instance_finalize(Object *obj)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue