Received: from eggs.gnu.org ([140.186.70.92]:41927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RyCvO-0002ge-4B for qemu-devel@nongnu.org; Thu, 16 Feb 2012 20:47:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RyCvM-0000Nx-Py for qemu-devel@nongnu.org; Thu, 16 Feb 2012 20:47:50 -0500 Received: from cantor2.suse.de ([195.135.220.15]:58353 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RyCvM-0000Nl-FU for qemu-devel@nongnu.org; Thu, 16 Feb 2012 20:47:48 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 17 Feb 2012 02:47:44 +0100 Message-Id: <1329443264-13819-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] qdev: Fix qdev_try_create() semantics List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= Since QOM'ification, qdev_try_create() uses object_new() internally, which asserts "type !=3D 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=C3=A4rber Cc: Anthony Liguori --- hw/qdev.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index f0eb3a7..ee21d90 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -117,6 +117,9 @@ DeviceState *qdev_try_create(BusState *bus, const cha= r *name) { DeviceState *dev; =20 + if (object_class_by_name(name) =3D=3D NULL) { + return NULL; + } dev =3D DEVICE(object_new(name)); if (!dev) { return NULL; --=20 1.7.7