qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] qdev: Fix qdev_try_create() semantics


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] qdev: Fix qdev_try_create() semantics
Date: Fri, 17 Feb 2012 12:16:10 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15

On 02/16/2012 08:00 PM, Andreas Färber wrote:
Am 17.02.2012 02:47, schrieb Andreas Färber:
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<address@hidden>
Cc: Anthony Liguori<address@hidden>

Er, it's late here... ;)

As one can guess I've managed to convert x86. Still need to cleanup but
I pushed my work branch for the curious (and as backup!):

http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/qom-cpu

Applied.  Thanks.

Regards,

Anthony Liguori


Andreas

---
  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 char 
*name)
  {
      DeviceState *dev;

+    if (object_class_by_name(name) == NULL) {
+        return NULL;
+    }
      dev = DEVICE(object_new(name));
      if (!dev) {
          return NULL;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]