Skip to contentSkip to conversation

qdev: Fix qdev_try_create() semantics

PATCH Applied Andreas Färber 2 participants 3 messages Feb 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 hw/qdev.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/qdev.c +3 -0
index f0eb3a7..ee21d90 100644
@@ -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;
Signature · 1 line
1.7.7
#1 lore raw

Am 17.02.2012 02:47, schrieb Andreas Färber:

Quoted 11 lines

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.

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

Andreas

Quoted 18 lines
---
 hw/qdev.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/qdev.c +3 -0
index f0eb3a7..ee21d90 100644
@@ -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;
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 13 lines · Andreas Färber

Am 17.02.2012 02:47, schrieb Andreas Färber:

Quoted 11 lines

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.

Quoted 6 lines

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

Quoted 22 lines

Andreas

Quoted 18 lines
---
  hw/qdev.c |    3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)
hw/qdev.c +3 -0
index f0eb3a7..ee21d90 100644
@@ -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;