From: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Link: https://lore.kernel.org/r/20241216035109.3486070-13-richard.henderson@linaro.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/hw/qdev-core.h | 8 ++++++++
hw/core/qdev-properties.c | 2 +-
migration/migration.c | 2 +-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 5be9844412f..b2859d1e39e 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -943,6 +943,14 @@ char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
*/
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) \
+ do { \
+ QEMU_BUILD_BUG_ON(sizeof(PROPS) != sizeof(const Property *) && \
+ sizeof(PROPS) < 2 * sizeof(Property)); \
+ (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 315196bd85a..de618a964a9 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 8c5bd0a75c8..6b3b85d31e5 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.47.1