From patchwork Fri Oct 19 17:19:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 12380 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D16A823F9B for ; Fri, 19 Oct 2012 17:19:14 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 710E6A180FD for ; Fri, 19 Oct 2012 17:19:14 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id f6so446809iag.11 for ; Fri, 19 Oct 2012 10:19:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=U/tK+5UxPiqJ/tiZ+TmPj23JGibpEq1LBv2e+sjPnPk=; b=TauBtNPxjk8HjE3Fd/z1Tmcya3Bpd5+un/I6GqSx8HtkFJ6QoIxZQc54tPEXMe+Ey/ GkJOa3fIr/VfLWgHLP0O38maRNEHN26JBAOV2kUxe8t67NQPyTFwDPN02efAeCObbgRx W835f3aXwYk4NOzelg0nAL76BJcjCX321JArpF/pJcW0JBe/meowj8LkhRc/zsOK2Q4+ ok5JdqlLP1gueDcA/TXCNs3k/sQOLWD6CsJquqvd3gX15D6nPSa9u/Ab/keWOvQNsLEZ iW7udUbfTzHBwsYvD1OrAEUSnm4H+71I86EOi5OOzy2JFiaiRp8P8qzBzvdTlIJJ2ngl yIYg== Received: by 10.50.194.169 with SMTP id hx9mr2127746igc.70.1350667153795; Fri, 19 Oct 2012 10:19:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp124728igt; Fri, 19 Oct 2012 10:19:12 -0700 (PDT) Received: by 10.204.128.89 with SMTP id j25mr697057bks.23.1350667151528; Fri, 19 Oct 2012 10:19:11 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id hw12si3684076bkc.21.2012.10.19.10.19.10 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 19 Oct 2012 10:19:11 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TPGDz-0006qG-16; Fri, 19 Oct 2012 18:19:07 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori , Paolo Bonzini Subject: [PATCH 2/2] qom: Detect attempts to add a property that already exists Date: Fri, 19 Oct 2012 18:19:06 +0100 Message-Id: <1350667146-26273-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1350667146-26273-1-git-send-email-peter.maydell@linaro.org> References: <1350667146-26273-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQkYgMWXGg20YfJ0rWbULaXITPrVCL2imQA0v8qHHcMTf5/blCFVfNSMHxSPvo5RkiB7aaNs Detect attempts to add a property to an object if one of that name already exists, and report them as critical errors. In particular, for static properties (eg qdev Property arrays) this will manifest as an abort() with a useful error message. Signed-off-by: Peter Maydell --- qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index e3e9242..228ca92 100644 --- a/qom/object.c +++ b/qom/object.c @@ -620,7 +620,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_critical(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);