From fdae245f56f97387bb33b2db03aa015f206c24b2 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 2 Apr 2012 22:40:26 +0200 Subject: [PATCH] qdev: Remove qdev_prop_set_defaults MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Instead, qdev_property_add_static can set the default. Signed-off-by: Paolo Bonzini Reviewed-by: Anthony Liguori Signed-off-by: Andreas Färber --- hw/qdev-properties.c | 22 ---------------------- hw/qdev.c | 26 +++++++++++++++++++++++--- hw/qdev.h | 1 - 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 04e8326108..f4b9a0e2c8 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -1106,28 +1106,6 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) *ptr = value; } -void qdev_prop_set_defaults(DeviceState *dev, Property *props) -{ - Object *obj = OBJECT(dev); - if (!props) - return; - for (; props->name; props++) { - Error *errp = NULL; - if (props->qtype == QTYPE_NONE) { - continue; - } - if (props->qtype == QTYPE_QBOOL) { - object_property_set_bool(obj, props->defval, props->name, &errp); - } else if (props->info->enum_table) { - object_property_set_str(obj, props->info->enum_table[props->defval], - props->name, &errp); - } else if (props->qtype == QTYPE_QINT) { - object_property_set_int(obj, props->defval, props->name, &errp); - } - assert_no_error(errp); - } -} - static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props); static void qdev_prop_register_global(GlobalProperty *prop) diff --git a/hw/qdev.c b/hw/qdev.c index 483f2e619d..7f18590594 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -579,6 +579,9 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop, void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp) { + Error *local_err = NULL; + Object *obj = OBJECT(dev); + /* * TODO qdev_prop_ptr does not have getters or setters. It must * go now that it can be replaced with links. The test should be @@ -588,10 +591,28 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, return; } - object_property_add(OBJECT(dev), prop->name, prop->info->name, + object_property_add(obj, prop->name, prop->info->name, prop->info->get, prop->info->set, prop->info->release, - prop, errp); + prop, &local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } + if (prop->qtype == QTYPE_NONE) { + return; + } + + if (prop->qtype == QTYPE_QBOOL) { + object_property_set_bool(obj, prop->defval, prop->name, &local_err); + } else if (prop->info->enum_table) { + object_property_set_str(obj, prop->info->enum_table[prop->defval], + prop->name, &local_err); + } else if (prop->qtype == QTYPE_QINT) { + object_property_set_int(obj, prop->defval, prop->name, &local_err); + } + assert_no_error(local_err); } static void device_initfn(Object *obj) @@ -614,7 +635,6 @@ static void device_initfn(Object *obj) qdev_property_add_legacy(dev, prop, NULL); qdev_property_add_static(dev, prop, NULL); } - qdev_prop_set_defaults(dev, DEVICE_CLASS(class)->props); class = object_class_get_parent(class); } while (class != object_class_by_name(TYPE_DEVICE)); qdev_prop_set_globals(dev); diff --git a/hw/qdev.h b/hw/qdev.h index 5f62f80d35..1af5382cad 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -309,7 +309,6 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); -void qdev_prop_set_defaults(DeviceState *dev, Property *props); void qdev_prop_register_global_list(GlobalProperty *props); void qdev_prop_set_globals(DeviceState *dev); -- 2.11.4.GIT