qdev: Detect duplicate device properties
v6 cover qdev: Detect duplicate device properties
Detect and abort on duplicate properties in a qdev Property array.
This patchset actually dates back to October last year (and got reviewed then, hence Anthony's r-b tags) but it didn't get applied (maybe we were in codefreeze) and I forgot about it. Anyway, I've rebased it so here we are again.
Peter Maydell (2):
qom: Detect attempts to add a property that already exists hw/qdev: Abort rather than ignoring errors adding device properties
hw/qdev.c | 10 +++++++--- qom/object.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v6 1/2 qom: Detect attempts to add a property that already exists
Detect attempts to add a property to an object if one of that name already exists, and report them as errors.
--- qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
qom/object.c +12 -1
@@ -629,7 +629,18 @@ void object_property_add(Object *obj, const char *name, const char *type, ObjectPropertyRelease *release, void *opaque, Error **errp) { -ObjectProperty *prop =g_malloc0 (sizeof (*prop)); +ObjectProperty *prop; + + QTAILQ_FOREACH(prop, &obj->properties, node) { +if (strcmp (prop->name, name) ==0 ) { +error_setg (errp,"attempt to add duplicate property '%s'" +" to object (type '%s')\n" , name, +object_get_typename (obj)); +return ; + } + } + + prop =g_malloc0 (sizeof (*prop)); prop->name =g_strdup (name); prop->type =g_strdup (type);
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v6 1/2] qom: Detect attempts to add a property that already exists
Am 16.03.2013 17:39, schrieb Peter Maydell:
Quoted 14 lines
Detect attempts to add a property to an object if one of that name already exists, and report them as errors.
Signed-off-by Peter Maydell <[email protected]>Reviewed-by Anthony Liguori <[email protected]>--- qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)qom/object.c +0
-0
qom/object.c void object_property_add(Object *obj, const char *name, const char *type, · line 637
Quoted 10 lines
qom/object.c +6
-1@@ -629,7 +629,18 @@ void object_property_add(Object *obj, const char *name, const char *type, ObjectPropertyRelease *release, void *opaque, Error **errp) { -ObjectProperty *prop =g_malloc0 (sizeof (*prop)); +ObjectProperty *prop; + + QTAILQ_FOREACH(prop, &obj->properties, node) { +if (strcmp (prop->name, name) ==0 ) { + error_setg(errp, "attempt to add duplicate property '%s'" + " to object (type '%s')\n", name,
No \n in error_setg(), there was a recent cleanup series.
Andreas
Quoted 10 lines
qom/object.c +6
-0+ object_get_typename(obj)); +return ; + } + } + + prop =g_malloc0 (sizeof (*prop)); prop->name =g_strdup (name); prop->type =g_strdup (type);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH v6 2/2 hw/qdev: Abort rather than ignoring errors adding device properties
In reply to Peter MaydellInstead of ignoring any errors that occur when adding properties to a new device in device_initfn(), check for them and abort if any occur. The most likely cause is accidentally adding a duplicate property, which is a programming error by the device author.
--- hw/qdev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
hw/qdev.c +7 -3
@@ -711,6 +711,7 @@ static void device_initfn(Object *obj)DeviceState *dev =DEVICE (obj);ObjectClass *class;Property *prop; +Error *err =NULL ;if (qdev_hotplug) { dev->hotplugged =1 ;
@@ -726,15 +727,18 @@ static void device_initfn(Object *obj) class =object_get_class (OBJECT (dev));do {for (prop =DEVICE_CLASS (class)->props; prop && prop->name; prop++) { -qdev_property_add_legacy (dev, prop,NULL ); -qdev_property_add_static (dev, prop,NULL ); +qdev_property_add_legacy (dev, prop, &err); +assert_no_error (err); +qdev_property_add_static (dev, prop, &err); +assert_no_error (err); } 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 , - (Object **)&dev->parent_bus,NULL ); + (Object **)&dev->parent_bus, &err); +assert_no_error (err); }/* Unlink device from bus and free the structure. */
Signature · 1 line
1.7.9.5
Il 16/03/2013 17:39, Peter Maydell ha scritto:
Quoted 7 lines
Detect and abort on duplicate properties in a qdev Property array.
This patchset actually dates back to October last year (and got reviewed then, hence Anthony's r-b tags) but it didn't get applied (maybe we were in codefreeze) and I forgot about it. Anyway, I've rebased it so here we are again.
Quoted 8 lines
Peter Maydell (2):
qom: Detect attempts to add a property that already exists hw/qdev: Abort rather than ignoring errors adding device propertieshw/qdev.c | 10 +++++++--- qom/object.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-)
Paolo