]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qdev: Fix qdev_try_create() semantics
authorAndreas Färber <afaerber@suse.de>
Fri, 17 Feb 2012 01:47:44 +0000 (02:47 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 17 Feb 2012 15:58:21 +0000 (09:58 -0600)
Since QOM'ification, qdev_try_create() uses object_new() internally,
which asserts "type != NULL" when the type is not registered.
This was revealed by the combination of kvmclock's kvm_enabled() check
and early QOM type registration.

Check whether the class exists before calling object_new(), so that
the caller (e.g., qdev_create) can fail gracefully, telling us which
device could not be created.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <aliguori@codemonkey.ws>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/qdev.c

index f0eb3a7384a1026ebfae3b36a249b232c561e04e..ee21d90e80128aa3b39a838f9f34b8c9468b17d1 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -117,6 +117,9 @@ DeviceState *qdev_try_create(BusState *bus, const char *name)
 {
     DeviceState *dev;
 
+    if (object_class_by_name(name) == NULL) {
+        return NULL;
+    }
     dev = DEVICE(object_new(name));
     if (!dev) {
         return NULL;