[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/41] hw/core: Replace device_class_set_props with a macro
From: |
Paolo Bonzini |
Subject: |
[PULL 18/41] hw/core: Replace device_class_set_props with a macro |
Date: |
Thu, 19 Dec 2024 09:32:05 +0100 |
From: Richard Henderson <richard.henderson@linaro.org>
Use ARRAY_SIZE to implement as device_class_set_props_n.
Remove any DEFINE_PROP_END_OF_LIST terminator from the count.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Link:
20241216035109.3486070-19-richard.henderson@linaro.org">https://lore.kernel.org/r/20241216035109.3486070-19-richard.henderson@linaro.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/hw/qdev-core.h | 21 +++++++++++++--------
hw/core/qdev-properties.c | 16 ----------------
2 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index cd0ddf84ca5..5dc46402585 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -941,20 +941,25 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState
*bus, DeviceState *dev);
/**
* device_class_set_props(): add a set of properties to an device
* @dc: the parent DeviceClass all devices inherit
- * @props: an array of properties, terminate by DEFINE_PROP_END_OF_LIST()
+ * @props: an array of properties
*
* 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 @props is an array, not a pointer, via ARRAY_SIZE.
+ * 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);
-
-/* Validate at least one Property, plus the terminator. */
-#define device_class_set_props(DC, PROPS) \
+#define device_class_set_props(dc, props) \
do { \
- QEMU_BUILD_BUG_ON(sizeof(PROPS) != sizeof(const Property *) && \
- sizeof(PROPS) < 2 * sizeof(Property)); \
- (device_class_set_props)(DC, PROPS); \
+ QEMU_BUILD_BUG_ON(sizeof(props) < 2 * sizeof(Property)); \
+ size_t props_count_ = ARRAY_SIZE(props) - 1; \
+ if ((props)[props_count_].name != NULL) { \
+ qemu_build_not_reached(); \
+ } \
+ device_class_set_props_n((dc), (props), props_count_); \
} while (0)
/**
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 31e3072b559..a3d49e20202 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1058,22 +1058,6 @@ 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)
-{
- const Property *prop;
- size_t n;
-
- dc->props_ = props;
- for (prop = props, n = 0; prop && prop->name; prop++, n++) {
- qdev_class_add_legacy_property(dc, prop);
- qdev_class_add_property(dc, prop->name, prop);
- }
-
- /* We used a hole in DeviceClass because that's still a lot. */
- assert(n <= UINT16_MAX);
- dc->props_count_ = n;
-}
-
void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n)
{
/* We used a hole in DeviceClass because that's still a lot. */
--
2.47.1
- [PULL 09/41] hw/xen: Remove empty Property lists, (continued)
- [PULL 09/41] hw/xen: Remove empty Property lists, Paolo Bonzini, 2024/12/19
- [PULL 10/41] hw/sparc: Remove empty Property lists, Paolo Bonzini, 2024/12/19
- [PULL 11/41] hw/virtio: Remove empty Property lists, Paolo Bonzini, 2024/12/19
- [PULL 12/41] include/hw/qdev-core: Detect most empty Property lists at compile time, Paolo Bonzini, 2024/12/19
- [PULL 07/41] hw/tricore: Remove empty Property lists, Paolo Bonzini, 2024/12/19
- [PULL 13/41] hw/core: Introduce device_class_set_props_n, Paolo Bonzini, 2024/12/19
- [PULL 15/41] hw/scsi/megasas: Use device_class_set_props_n, Paolo Bonzini, 2024/12/19
- [PULL 14/41] migration: Use device_class_set_props_n, Paolo Bonzini, 2024/12/19
- [PULL 16/41] hw/arm/armsse: Use device_class_set_props_n, Paolo Bonzini, 2024/12/19
- [PULL 17/41] rust/qemu-api: Use device_class_set_props_n, Paolo Bonzini, 2024/12/19
- [PULL 18/41] hw/core: Replace device_class_set_props with a macro,
Paolo Bonzini <=
- [PULL 19/41] target/riscv: Do not abuse DEFINE_PROP_END_OF_LIST, Paolo Bonzini, 2024/12/19
- [PULL 22/41] hw/core/qdev-properties: Constify Property argument to object_field_prop_ptr, Paolo Bonzini, 2024/12/19
- [PULL 21/41] include/hw/qdev-properties: Shrink struct Property, Paolo Bonzini, 2024/12/19
- [PULL 23/41] hw/core/qdev-properties: Constify Property argument to PropertyInfo.print, Paolo Bonzini, 2024/12/19
- [PULL 24/41] Constify all opaque Property pointers, Paolo Bonzini, 2024/12/19
- [PULL 20/41] include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST, Paolo Bonzini, 2024/12/19
- [PULL 26/41] rust: qom: add possibility of overriding unparent, Paolo Bonzini, 2024/12/19
- [PULL 25/41] rust: qom: put class_init together from multiple ClassInitImpl<>, Paolo Bonzini, 2024/12/19
- [PULL 27/41] rust: rename qemu-api modules to follow C code a bit more, Paolo Bonzini, 2024/12/19
- [PULL 28/41] rust: re-export C types from qemu-api submodules, Paolo Bonzini, 2024/12/19