qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qdev: Fix qdev_try_create() for bus-less devices
@ 2014-02-05 14:09 Andreas Färber
  2014-02-05 16:38 ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Färber @ 2014-02-05 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Peter Crosthwaite, Andreas Färber

Commit 7426aa72c36c908a7d0eae3e38568bb0a70de479 (nand: Don't inherit
from Sysbus) made NAND a device rather than SysBus device. This led to all
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 assumptions
about a NULL BusState being the SysBus. Fix that.

A longer-term solution will be to stop using qdev_create().

Reported-by: Markus Armbruster <armbru@redhat.com>
Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 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;
 
-    if (object_class_by_name(type) == NULL) {
+    oc = object_class_by_name(type);
+    if (oc == NULL) {
         return NULL;
     }
+    dc = DEVICE_CLASS(oc);
     dev = DEVICE(object_new(type));
     if (!dev) {
         return NULL;
     }
 
-    if (!bus) {
+    if (!bus && dc->bus_type && strcmp(dc->bus_type, "System") == 0) {
         bus = sysbus_get_default();
     }
 
-    qdev_set_parent_bus(dev, bus);
-    object_unref(OBJECT(dev));
+    if (bus != NULL) {
+        qdev_set_parent_bus(dev, bus);
+        object_unref(OBJECT(dev));
+    }
     return dev;
 }
 
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-05 23:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-05 14:09 [Qemu-devel] [PATCH] qdev: Fix qdev_try_create() for bus-less devices Andreas Färber
2014-02-05 16:38 ` Paolo Bonzini
2014-02-05 16:46   ` Andreas Färber
2014-02-05 17:20     ` Andreas Färber
2014-02-05 23:16     ` Peter Crosthwaite

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).