From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WB3AQ-0003av-AH for qemu-devel@nongnu.org; Wed, 05 Feb 2014 09:09:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WB3AK-00022V-8Z for qemu-devel@nongnu.org; Wed, 05 Feb 2014 09:09:30 -0500 Received: from cantor2.suse.de ([195.135.220.15]:34930 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WB3AK-000229-3E for qemu-devel@nongnu.org; Wed, 05 Feb 2014 09:09:24 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 5 Feb 2014 15:09:00 +0100 Message-Id: <1391609340-11023-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] qdev: Fix qdev_try_create() for bus-less devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Peter Crosthwaite , =?UTF-8?q?Andreas=20F=C3=A4rber?= Commit 7426aa72c36c908a7d0eae3e38568bb0a70de479 (nand: Don't inherit from Sysbus) made NAND a device rather than SysBus device. This led to al= l boards using the device (akita, borzoi, spitz, terrier, tosa, axis-dev88) crashing on "info qtree". The difference to the bus-less ARMCPU is that the device was still being created by qdev_create() rather than object_new(), which makes assumption= s about a NULL BusState being the SysBus. Fix that. A longer-term solution will be to stop using qdev_create(). Reported-by: Markus Armbruster Cc: Peter Crosthwaite Signed-off-by: Andreas F=C3=A4rber --- hw/core/qdev.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 82a9123..14c8765 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -131,21 +131,27 @@ DeviceState *qdev_create(BusState *bus, const char = *name) DeviceState *qdev_try_create(BusState *bus, const char *type) { DeviceState *dev; + ObjectClass *oc; + DeviceClass *dc; =20 - if (object_class_by_name(type) =3D=3D NULL) { + oc =3D object_class_by_name(type); + if (oc =3D=3D NULL) { return NULL; } + dc =3D DEVICE_CLASS(oc); dev =3D DEVICE(object_new(type)); if (!dev) { return NULL; } =20 - if (!bus) { + if (!bus && dc->bus_type && strcmp(dc->bus_type, "System") =3D=3D 0)= { bus =3D sysbus_get_default(); } =20 - qdev_set_parent_bus(dev, bus); - object_unref(OBJECT(dev)); + if (bus !=3D NULL) { + qdev_set_parent_bus(dev, bus); + object_unref(OBJECT(dev)); + } return dev; } =20 --=20 1.8.4.5