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: 194237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6FC582C00B1 for ; Fri, 26 Oct 2012 02:27:05 +1100 (EST) Received: from localhost ([::1]:56894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRPKp-0000mD-Gs for incoming@patchwork.ozlabs.org; Thu, 25 Oct 2012 11:27:03 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRPKa-0000Z3-6t for qemu-devel@nongnu.org; Thu, 25 Oct 2012 11:26:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRPKR-0008F0-KG for qemu-devel@nongnu.org; Thu, 25 Oct 2012 11:26:48 -0400 Received: from 38.0.169.217.in-addr.arpa ([217.169.0.38]:49629 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRPKR-0008EN-DS for qemu-devel@nongnu.org; Thu, 25 Oct 2012 11:26:39 -0400 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 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-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 217.169.0.38 Cc: Paolo Bonzini , Anthony Liguori , patches@linaro.org Subject: [Qemu-devel] [PATCH v4 1/2] qom: Detect attempts to add a property that already exists X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);