From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afvZU-0003r5-VG for qemu-devel@nongnu.org; Tue, 15 Mar 2016 16:28:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afvZT-0005PE-UB for qemu-devel@nongnu.org; Tue, 15 Mar 2016 16:28:04 -0400 Received: from mail-ob0-x22a.google.com ([2607:f8b0:4003:c01::22a]:35256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afvZT-0005Om-PL for qemu-devel@nongnu.org; Tue, 15 Mar 2016 16:28:03 -0400 Received: by mail-ob0-x22a.google.com with SMTP id fp4so30014281obb.2 for ; Tue, 15 Mar 2016 13:28:02 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1458061009-7733-1-git-send-email-peter.maydell@linaro.org> References: <1458061009-7733-1-git-send-email-peter.maydell@linaro.org> Date: Tue, 15 Mar 2016 14:28:02 -0600 Message-ID: From: Thomas Hanson Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [Qemu-arm] [PATCH] sd: Fix "info qtree" on boards with SD cards List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: patches@linaro.org, hitmoon , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Paolo Bonzini , =?UTF-8?Q?Andreas_F=C3=A4rber?= The patch looks good. Would it also be good to update bus_add_child() so that it NULL-checks its "bus" parameter before dereferencing it? -Tom On 15 March 2016 at 10:56, Peter Maydell wrote: > 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: hitmoon > Signed-off-by: Peter Maydell > --- > I assume that using qdev_create() for non-SysBus devices is > OK if we are passing in a specific bus pointer, because we do > this already for various things including PCI devices. The > various "properly QOMified" uses of TYPE_SD_CARD do that; only > this sd_init() function for the legacy uses doesn't. > --- > 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; > -- > 1.9.1 > >