From patchwork Fri Jan 4 17:34:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 209499 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 641712C0086 for ; Sat, 5 Jan 2013 04:35:10 +1100 (EST) Received: from localhost ([::1]:52669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrBAi-0001pw-Ht for incoming@patchwork.ozlabs.org; Fri, 04 Jan 2013 12:35:08 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrBAY-0001pE-Jq for qemu-devel@nongnu.org; Fri, 04 Jan 2013 12:35:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TrBAW-0007Ut-Vq for qemu-devel@nongnu.org; Fri, 04 Jan 2013 12:34:58 -0500 Received: from cantor2.suse.de ([195.135.220.15]:50318 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrBAW-0007TK-My for qemu-devel@nongnu.org; Fri, 04 Jan 2013 12:34:56 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id B9F89A3A78; Fri, 4 Jan 2013 18:34:55 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Fri, 4 Jan 2013 18:34:40 +0100 Message-Id: <1357320880-10782-1-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: imammedo@redhat.com, Paolo Bonzini , ehabkost@redhat.com, anthony@codemonkey.ws, =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH v2] qdev: Don't assume existence of parent bus on unparenting 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 Commit 667d22d1ae59da46b4c1fbd094ca61145f19b8c3 (qdev: move bus removal to object_unparent) made the assumption that at unparenting time parent_bus is not NULL. This assumption is unjustified since object_unparent() may well be called directly after object_initialize(), without any qdev_set_parent_bus(). This did not cause any issues yet because qdev_[try_]create() does call qdev_set_parent_bus(), falling back to SysBus if unsupplied. While at it, ensure that this new function uses the device_ prefix and make the name more neutral in light of this semantic change. Reported-by: Eduardo Habkost Signed-off-by: Andreas Färber Cc: Paolo Bonzini Tested-By: Igor Mammedov --- Planning to insert this before the final CPU-as-a-device patch on qom-cpu, to avoid a regression for, e.g., -cpu Haswell,enforce if unsupported by host. This supersedes my cosmetic patch in the "QOM realize, device-only" series: v1 -> v2: * Make bus removal conditional on parent bus * Rename function further hw/qdev.c | 8 +++++--- 1 Datei geändert, 5 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-) diff --git a/hw/qdev.c b/hw/qdev.c index f2c2484..e2a5c57 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -698,16 +698,18 @@ static void device_class_base_init(ObjectClass *class, void *data) klass->props = NULL; } -static void qdev_remove_from_bus(Object *obj) +static void device_unparent(Object *obj) { DeviceState *dev = DEVICE(obj); - bus_remove_child(dev->parent_bus, dev); + if (dev->parent_bus != NULL) { + bus_remove_child(dev->parent_bus, dev); + } } static void device_class_init(ObjectClass *class, void *data) { - class->unparent = qdev_remove_from_bus; + class->unparent = device_unparent; } void device_reset(DeviceState *dev)