Patchwork [2/3] hw/qdev: Don't crash if qdev_create(NULL, ...) fails

login
register
mail settings
Submitter Stefan Hajnoczi
Date Aug. 12, 2011, 12:12 p.m.
Message ID <1313151141-8541-3-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/109832/
State New
Headers show

Comments

Stefan Hajnoczi - Aug. 12, 2011, 12:12 p.m.
From: Peter Maydell <peter.maydell@linaro.org>

If an attempt to create a qdev device on the default sysbus (by passing
NULL as the bus to qdev_create) fails, print a useful error message
rather than crashing trying to dereference a NULL pointer.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 hw/qdev.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 6819537..d8114c6 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -111,7 +111,12 @@  DeviceState *qdev_create(BusState *bus, const char *name)
 
     dev = qdev_try_create(bus, name);
     if (!dev) {
-        hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
+        if (bus) {
+            hw_error("Unknown device '%s' for bus '%s'\n", name,
+                     bus->info->name);
+        } else {
+            hw_error("Unknown device '%s' for default sysbus\n", name);
+        }
     }
 
     return dev;