From patchwork Wed Mar 16 17:18:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 8602961 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 917599F758 for ; Wed, 16 Mar 2016 17:23:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0F3420166 for ; Wed, 16 Mar 2016 17:23:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4298D202AE for ; Wed, 16 Mar 2016 17:23:26 +0000 (UTC) Received: from localhost ([::1]:57687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agFAL-00052z-Iz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 13:23:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agF5u-0002Hx-QK for qemu-devel@nongnu.org; Wed, 16 Mar 2016 13:18:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agF5t-0001KS-Bd for qemu-devel@nongnu.org; Wed, 16 Mar 2016 13:18:50 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:56207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agF5t-0001KA-2A for qemu-devel@nongnu.org; Wed, 16 Mar 2016 13:18:49 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1agF5s-000125-LH for qemu-devel@nongnu.org; Wed, 16 Mar 2016 17:18:48 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Wed, 16 Mar 2016 17:18:35 +0000 Message-Id: <1458148715-16864-22-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458148715-16864-1-git-send-email-peter.maydell@linaro.org> References: <1458148715-16864-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 21/21] sd: Fix "info qtree" on boards with SD cards 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SD card object is not a SysBusDevice, so don't create it with qdev_create() if we're not assigning it to a specific bus; use object_new() instead. This was causing 'info qtree' to segfault on boards with SD cards, because qdev_create(NULL, TYPE_FOO) puts the created object on the system bus, and then we may try to run functions like sysbus_dev_print() on it, which fail when casting the object to SysBusDevice. (This is the same mistake that we made with the NAND device and fixed in commit 6749695eaaf346c1.) Reported-by: xiaoqiang.zhao Signed-off-by: Peter Maydell Reviewed-by: xiaoqiang.zhao Message-id: 1458061009-7733-1-git-send-email-peter.maydell@linaro.org --- hw/sd/sd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 00c320d..1568057 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -563,17 +563,19 @@ static const VMStateDescription sd_vmstate = { /* Legacy initialization function for use by non-qdevified callers */ SDState *sd_init(BlockBackend *blk, bool is_spi) { + Object *obj; DeviceState *dev; Error *err = NULL; - dev = qdev_create(NULL, TYPE_SD_CARD); + obj = object_new(TYPE_SD_CARD); + dev = DEVICE(obj); qdev_prop_set_drive(dev, "drive", blk, &err); if (err) { error_report("sd_init failed: %s", error_get_pretty(err)); return NULL; } qdev_prop_set_bit(dev, "spi", is_spi); - object_property_set_bool(OBJECT(dev), true, "realized", &err); + object_property_set_bool(obj, true, "realized", &err); if (err) { error_report("sd_init failed: %s", error_get_pretty(err)); return NULL;