提交 4ed658ca 编写于 作者: A Andreas Färber 提交者: Anthony Liguori

qdev: Fix qdev_try_create() semantics

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: NAndreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <aliguori@codemonkey.ws>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 438e1c79
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册