From patchwork Thu Oct 25 15:22:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 12524 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 7562323F9B for ; Thu, 25 Oct 2012 15:22:36 +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 35A64A1888F for ; Thu, 25 Oct 2012 15:22:36 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id f6so1337904iag.11 for ; Thu, 25 Oct 2012 08:22:35 -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=gA9IZWXcdv5f4Gi0B6DkrtYf4/eFkwSgIopspzY3MFM=; b=Bwcd9pjCV5pBzNhDQkxIu/dQ9iFZ2ScpjCuD3b2SY0dunz/HWY2Y2do6lHP4sndRcP kn14w84mtfaL9Fyz9+PTLWQfCcZWpvj1Wr5nufFe9aFhe8OX9Ag0SXxdppeGY0YTDhGg anvS2kdmPaAFFWAXNuPydwrtzbS6X5M4qDgfsNFkVOJ4csi+EivpZ0xXECKD6bw9PvNW U9s/AR5AvztJXkzGiqSZgkYAz8cOkuh6kKNsOQ3eRTIyrupYpCyxF/ETjdxWKGbbZ95m j5TbuYgIU7+DNGdfj1IKNqBs/8SSfTxPDHzauaT1LcdiXfONZOVfJIHAZmg/XBPlGBXf dfoQ== Received: by 10.50.46.226 with SMTP id y2mr6168400igm.62.1351178555648; Thu, 25 Oct 2012 08:22:35 -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 n20csp68155igt; Thu, 25 Oct 2012 08:22:34 -0700 (PDT) Received: by 10.180.87.230 with SMTP id bb6mr11226478wib.6.1351178553345; Thu, 25 Oct 2012 08:22:33 -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 d8si4633909wix.14.2012.10.25.08.22.32 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Oct 2012 08:22:33 -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 1TRPGP-0001UO-M0; Thu, 25 Oct 2012 16:22:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori , Paolo Bonzini Subject: [PATCH v4 1/2] qom: Detect attempts to add a property that already exists Date: Thu, 25 Oct 2012 16:22:28 +0100 Message-Id: <1351178549-5699-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1351178549-5699-1-git-send-email-peter.maydell@linaro.org> References: <1351178549-5699-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQl3zcK23sUgpAwVLiZKlnQKHI5qh9j4Jzb4jBDxUVcJhTsBBPak9YX9gD33n5Gx2IYQU3Xk 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 Reviewed-by: Anthony Liguori --- qom/object.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index e3e9242..a9dfc8c 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(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);