hw/core: Remove device_class_set_props function

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>
Tested-by: Lei Yang <leiyang@redhat.com>
Link: https://lore.kernel.org/r/20241218134251.4724-19-richard.henderson@linaro.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Richard Henderson 2024-12-18 07:42:45 -06:00 committed by Paolo Bonzini
parent 5f99764869
commit 1088d41795
2 changed files with 6 additions and 26 deletions

View File

@ -1058,22 +1058,6 @@ 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)
{
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) 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. */ /* We used a hole in DeviceClass because that's still a lot. */

View File

@ -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???? * To modify an inherited property you need to use????
* *
* Validate that @props has at least one Property plus the terminator. * 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), * Validate that the array is terminated at compile-time (with -O2),
* which requires the array to be const. * which requires the array to be const.
*/ */
void device_class_set_props(DeviceClass *dc, const Property *props);
#define device_class_set_props(dc, props) \ #define device_class_set_props(dc, props) \
do { \ do { \
QEMU_BUILD_BUG_ON(sizeof(props) != sizeof(const Property *) && \ QEMU_BUILD_BUG_ON(sizeof(props) == 0); \
sizeof(props) < 2 * sizeof(Property)); \ size_t props_count_ = ARRAY_SIZE(props) - 1; \
if (sizeof(props) != sizeof(const Property *)) { \
size_t props_count_ = sizeof(props) / sizeof(Property) - 1; \
if ((props)[props_count_].name != NULL) { \ if ((props)[props_count_].name != NULL) { \
qemu_build_not_reached(); \ qemu_build_not_reached(); \
} \ } \
} \ device_class_set_props_n((dc), (props), props_count_); \
(device_class_set_props)((dc), (props)); \
} while (0) } while (0)
/** /**