helpers to iterate over device static properties to allow to simplify code a little.
Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- hw/qdev-properties.h | 9 +++++++++ qom/qdev-core.c | 10 ++++------ qom/qdev-properties.c | 29 +++++++---------------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/hw/qdev-properties.h b/hw/qdev-properties.h index 41358fa..19b55c0 100644 --- a/hw/qdev-properties.h +++ b/hw/qdev-properties.h @@ -135,4 +135,13 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp); const Property *qdev_prop_find(const DeviceClass *dc, const char *name); +#define QDEV_PROP_FOREACH(_var, _class) \ + for ((_var) = DEVICE_CLASS((_class))->props; \ + (_var) && (_var)->name; \ + (_var)++) + +#define QDEV_CLASS_FOREACH(_var, _class) \ + for ((_var) = (_class); \ + (_var) != DEVICE_CLASS(object_class_by_name(TYPE_DEVICE)); \ + (_var) = DEVICE_CLASS(object_class_get_parent(OBJECT_CLASS((_var))))) #endif diff --git a/qom/qdev-core.c b/qom/qdev-core.c index fbb7cb5..a062dbb 100644 --- a/qom/qdev-core.c +++ b/qom/qdev-core.c @@ -592,7 +592,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, static void device_initfn(Object *obj) { DeviceState *dev = DEVICE(obj); - ObjectClass *class; + DeviceClass *dc = DEVICE_CLASS(object_get_class(OBJECT(dev))); Property *prop; if (qdev_hotplug) { @@ -603,14 +603,12 @@ static void device_initfn(Object *obj) dev->instance_id_alias = -1; dev->state = DEV_STATE_CREATED; - class = object_get_class(OBJECT(dev)); - do { - for (prop = DEVICE_CLASS(class)->props; prop && prop->name; prop++) { + QDEV_CLASS_FOREACH(dc, dc) { + QDEV_PROP_FOREACH(prop, dc) { qdev_property_add_legacy(dev, prop, NULL); qdev_property_add_static(dev, prop, NULL); } - class = object_class_get_parent(class); - } while (class != object_class_by_name(TYPE_DEVICE)); + } qdev_prop_set_globals(dev); object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS, diff --git a/qom/qdev-properties.c b/qom/qdev-properties.c index cc37479..3d3eefa 100644 --- a/qom/qdev-properties.c +++ b/qom/qdev-properties.c @@ -772,33 +772,18 @@ PropertyInfo qdev_prop_pci_host_devaddr = { /* --- public helpers --- */ -static Property *qdev_prop_walk(Property *props, const char *name) -{ - if (!props) - return NULL; - while (props->name) { - if (strcmp(props->name, name) == 0) - return props; - props++; - } - return NULL; -} - const Property *qdev_prop_find(const DeviceClass *dc, const char *name) { - ObjectClass *class; - Property *prop; + const Property *prop; /* device properties */ - class = OBJECT_CLASS(dc); - do { - prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name); - if (prop) { - return prop; + QDEV_CLASS_FOREACH(dc, dc) { + QDEV_PROP_FOREACH(prop, dc) { + if (strcmp(prop->name, name) == 0) { + return prop; + } } - class = object_class_get_parent(class); - } while (class != object_class_by_name(TYPE_DEVICE)); - + } return NULL; } -- 1.7.11.7