mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
hw/core: Introduce device_class_set_props_n
Record the size of the array in DeviceClass.props_count_. Iterate with known count in qdev_prop_walk. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Tested-by: Lei Yang <leiyang@redhat.com> Link: https://lore.kernel.org/r/20241218134251.4724-14-richard.henderson@linaro.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
588611972f
commit
cb9f4b28ee
4 changed files with 55 additions and 18 deletions
|
@ -752,19 +752,18 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
|
|||
|
||||
#define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
|
||||
|
||||
static void qdev_print_props(Monitor *mon, DeviceState *dev, const Property *props,
|
||||
static void qdev_print_props(Monitor *mon, DeviceState *dev, DeviceClass *dc,
|
||||
int indent)
|
||||
{
|
||||
if (!props)
|
||||
return;
|
||||
for (; props->name; props++) {
|
||||
for (int i = 0, n = dc->props_count_; i < n; ++i) {
|
||||
const Property *prop = &dc->props_[i];
|
||||
char *value;
|
||||
char *legacy_name = g_strdup_printf("legacy-%s", props->name);
|
||||
char *legacy_name = g_strdup_printf("legacy-%s", prop->name);
|
||||
|
||||
if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
|
||||
value = object_property_get_str(OBJECT(dev), legacy_name, NULL);
|
||||
} else {
|
||||
value = object_property_print(OBJECT(dev), props->name, true,
|
||||
value = object_property_print(OBJECT(dev), prop->name, true,
|
||||
NULL);
|
||||
}
|
||||
g_free(legacy_name);
|
||||
|
@ -772,7 +771,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, const Property *pro
|
|||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
qdev_printf("%s = %s\n", props->name,
|
||||
qdev_printf("%s = %s\n", prop->name,
|
||||
*value ? value : "<null>");
|
||||
g_free(value);
|
||||
}
|
||||
|
@ -812,7 +811,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
|
|||
}
|
||||
class = object_get_class(OBJECT(dev));
|
||||
do {
|
||||
qdev_print_props(mon, dev, DEVICE_CLASS(class)->props_, indent);
|
||||
qdev_print_props(mon, dev, DEVICE_CLASS(class), indent);
|
||||
class = object_class_get_parent(class);
|
||||
} while (class != object_class_by_name(TYPE_DEVICE));
|
||||
bus_print_dev(dev->parent_bus, mon, dev, indent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue