Skip to contentSkip to conversation

qdev: relax bus type check in qdev_device_add() (v2)

PATCH In review Anthony Liguori 3 participants 3 messages Nov 29, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qdev: relax bus type check in qdev_device_add() (v2)

We are currently checking for an exact type match. Use QOM dynamic_cast to check for a compatible type instead.

Cc Konrad Frederic <[email protected]>
Cc Peter Maydell <[email protected]>

---
v1 -> v2:
- also add cast to qbus_find_recursive (Peter)
- simplify by doing object_dynamic_cast instead of messing with classes

---
 hw/qdev-monitor.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/qdev-monitor.c +2 -3
index 479eecd..a1b4d6a 100644
@@ -289,8 +289,7 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
     if (name && (strcmp(bus->name, name) != 0)) {
         match = 0;
     }
-    if (bus_typename &&
-        (strcmp(object_get_typename(OBJECT(bus)), bus_typename) != 0)) {
+    if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
         match = 0;
     }
     if (match) {
@@ -435,7 +434,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         if (!bus) {
             return NULL;
         }
-        if (strcmp(object_get_typename(OBJECT(bus)), k->bus_type) != 0) {
+        if (!object_dynamic_cast(OBJECT(bus), k->bus_type)) {
             qerror_report(QERR_BAD_BUS_FOR_DEVICE,
                           driver, object_get_typename(OBJECT(bus)));
             return NULL;
Signature · 1 line
1.8.0
#1 lore raw
Quoted 29 lines · Anthony Liguori

We are currently checking for an exact type match. Use QOM dynamic_cast to check for a compatible type instead.

Cc Konrad Frederic<[email protected]>
Cc Peter Maydell<[email protected]>

---
v1 -> v2:
- also add cast to qbus_find_recursive (Peter)
- simplify by doing object_dynamic_cast instead of messing with classes

---
  hw/qdev-monitor.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
hw/qdev-monitor.c +1 -2
index 479eecd..a1b4d6a 100644
@@ -289,8 +289,7 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
      if (name&&  (strcmp(bus->name, name) != 0)) {
          match = 0;
      }
-    if (bus_typename&&
-        (strcmp(object_get_typename(OBJECT(bus)), bus_typename) != 0)) {
+    if (bus_typename&&  !object_dynamic_cast(OBJECT(bus), bus_typename)) {
          match = 0;
      }
      if (match) {

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 440

Quoted 8 lines
hw/qdev-monitor.c +1 -1
@@ -435,7 +434,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
          if (!bus) {
              return NULL;
          }
-        if (strcmp(object_get_typename(OBJECT(bus)), k->bus_type) != 0) {
+        if (!object_dynamic_cast(OBJECT(bus), k->bus_type)) {
              qerror_report(QERR_BAD_BUS_FOR_DEVICE,
                            driver, object_get_typename(OBJECT(bus)));
              return NULL;

That seems to work.

Thanks,

Fred.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Anthony Liguori

Am 29.11.2012 16:12, schrieb Anthony Liguori:

Quoted 6 lines

We are currently checking for an exact type match. Use QOM dynamic_cast to check for a compatible type instead.

Cc Konrad Frederic <[email protected]>
Cc Peter Maydell <[email protected]>

Andreas

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