From patchwork Tue Dec 31 08:06:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 305847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F31DB2C00A3 for ; Tue, 31 Dec 2013 19:07:45 +1100 (EST) Received: from localhost ([::1]:60926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxuMZ-00089w-2W for incoming@patchwork.ozlabs.org; Tue, 31 Dec 2013 03:07:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxuMF-00088p-6s for qemu-devel@nongnu.org; Tue, 31 Dec 2013 03:07:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VxuM9-0007yD-84 for qemu-devel@nongnu.org; Tue, 31 Dec 2013 03:07:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxuM9-0007y7-04 for qemu-devel@nongnu.org; Tue, 31 Dec 2013 03:07:17 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBV87EQX031386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 31 Dec 2013 03:07:14 -0500 Received: from amosk.info.com (vpn1-112-199.nay.redhat.com [10.66.112.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBV878w3004160; Tue, 31 Dec 2013 03:07:11 -0500 From: Amos Kong To: qemu-devel@nongnu.org Date: Tue, 31 Dec 2013 16:06:57 +0800 Message-Id: <1388477217-23491-1-git-send-email-akong@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, afaerber@suse.de, aliguori@amazon.com Subject: [Qemu-devel] [PATCH] qdev: unparent device when fails to set properties 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 Test steps: (qemu) device_add e1000,addr=adsf Property 'e1000.addr' doesn't take value 'adsf' (qemu) info qtree Then qemu crashed. When it fails to set properties, qdev's parent is already set, but the object hasn't been added to parent object, object_unparent() won't unparent the device. This patch unparents device in the mediacy. Signed-off-by: Amos Kong --- qdev-monitor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qdev-monitor.c b/qdev-monitor.c index dc37a43..3d8b4f4 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -527,7 +527,9 @@ DeviceState *qdev_device_add(QemuOpts *opts) dev->id = id; } if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) { - object_unparent(OBJECT(dev)); + if (OBJECT(dev)->class->unparent) { + (OBJECT(dev)->class->unparent)(OBJECT(dev)); + } object_unref(OBJECT(dev)); return NULL; }