[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 18/24] hw/core: Remove device_class_set_props function
From: |
Richard Henderson |
Subject: |
[PATCH v2 18/24] hw/core: Remove device_class_set_props function |
Date: |
Wed, 18 Dec 2024 07:42:45 -0600 |
All uses of device_class_set_props() are now using arrays.
Validate this compile-time in the device_class_set_props macro and
call device_class_set_props_n using the known size of the array.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/hw/qdev-core.h | 16 ++++++----------
hw/core/qdev-properties.c | 16 ----------------
2 files changed, 6 insertions(+), 26 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index e9b4891f55..fc13623d43 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -948,22 +948,18 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState
*bus, DeviceState *dev);
* 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 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);
-
#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(); \
- } \
+ QEMU_BUILD_BUG_ON(sizeof(props) == 0); \
+ size_t props_count_ = ARRAY_SIZE(props) - 1; \
+ if ((props)[props_count_].name != NULL) { \
+ qemu_build_not_reached(); \
} \
- (device_class_set_props)((dc), (props)); \
+ 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 31e3072b55..a3d49e2020 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.43.0
- [PATCH v2 19/24] target/riscv: Do not abuse DEFINE_PROP_END_OF_LIST, (continued)
- [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, 2024/12/18
- [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 <=
- [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
- Re: [PATCH v2 00/24] More Property cleanups, Lei Yang, 2024/12/18