From 4ed658ca925249021789d6a51fd6f99f68213f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 17 Feb 2012 02:47:44 +0100 Subject: qdev: Fix qdev_try_create() semantics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Anthony Liguori Signed-off-by: Anthony Liguori --- hw/qdev.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'hw') diff --git a/hw/qdev.c b/hw/qdev.c index f0eb3a738..ee21d90e8 100644 --- 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; -- cgit v1.2.3