]> git.proxmox.com Git - qemu.git/commitdiff
qom: Detect attempts to add a property that already exists
authorPeter Maydell <peter.maydell@linaro.org>
Mon, 25 Mar 2013 13:15:13 +0000 (13:15 +0000)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 26 Mar 2013 14:27:02 +0000 (09:27 -0500)
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 <peter.maydell@linaro.org>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1364217314-7400-2-git-send-email-peter.maydell@linaro.org
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qom/object.c

index 3d638ff273e80464ab7d06b890d92dee7a91a3c8..3f779685603941116f835b5d5c9a88769453fbf9 100644 (file)
@@ -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')", name,
+                       object_get_typename(obj));
+            return;
+        }
+    }
+
+    prop = g_malloc0(sizeof(*prop));
 
     prop->name = g_strdup(name);
     prop->type = g_strdup(type);