[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 12/24] include/hw/qdev-core: Detect most empty Property lists
From: |
Richard Henderson |
Subject: |
[PATCH v2 12/24] include/hw/qdev-core: Detect most empty Property lists at compile time |
Date: |
Wed, 18 Dec 2024 07:42:39 -0600 |
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>
---
include/hw/qdev-core.h | 17 +++++++++++++++++
hw/core/qdev-properties.c | 2 +-
migration/migration.c | 2 +-
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 5be9844412..cbce3cf0b4 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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
* you attempt to add an existing property defined by a parent class.
* 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);
+#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
* @dc: The device class
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 315196bd85..de618a964a 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1061,7 +1061,7 @@ static void qdev_class_add_legacy_property(DeviceClass
*dc, const 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;
diff --git a/migration/migration.c b/migration/migration.c
index 8c5bd0a75c..6b3b85d31e 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3822,7 +3822,7 @@ static void migration_class_init(ObjectClass *klass, void
*data)
DeviceClass *dc = DEVICE_CLASS(klass);
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)
--
2.43.0
- [PATCH v2 08/24] hw/s390x: Remove empty Property lists, (continued)
- [PATCH v2 08/24] hw/s390x: Remove empty Property lists, Richard Henderson, 2024/12/18
- [PATCH v2 14/24] migration: Use device_class_set_props_n, Richard Henderson, 2024/12/18
- [PATCH v2 17/24] rust/qemu-api: Use device_class_set_props_n, Richard Henderson, 2024/12/18
- [PATCH v2 19/24] target/riscv: Do not abuse DEFINE_PROP_END_OF_LIST, Richard Henderson, 2024/12/18
- [PATCH v2 22/24] hw/core/qdev-properties: Constify Property argument to object_field_prop_ptr, Richard Henderson, 2024/12/18
- [PATCH v2 09/24] hw/xen: Remove empty Property lists, Richard Henderson, 2024/12/18
- [PATCH v2 12/24] include/hw/qdev-core: Detect most empty Property lists at compile time,
Richard Henderson <=
- [PATCH v2 13/24] hw/core: Introduce device_class_set_props_n, Richard Henderson, 2024/12/18
- [PATCH v2 15/24] hw/scsi/megasas: Use device_class_set_props_n, Richard Henderson, 2024/12/18
- [PATCH v2 16/24] hw/arm/armsse: Use device_class_set_props_n, Richard Henderson, 2024/12/18
- [PATCH v2 18/24] hw/core: Remove device_class_set_props function, Richard Henderson, 2024/12/18
- [PATCH v2 24/24] Constify all opaque Property pointers, Richard Henderson, 2024/12/18
- [PATCH v2 21/24] include/hw/qdev-properties: Shrink struct Property, Richard Henderson, 2024/12/18
- [PATCH v2 23/24] hw/core/qdev-properties: Constify Property argument to PropertyInfo.print, Richard Henderson, 2024/12/18
- [PATCH v2 20/24] include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST, Richard Henderson, 2024/12/18