Skip to contentSkip to conversation

hw/core/qdev: Increase qdev_realize() kindness

PATCH Applied Philippe Mathieu-Daudé 3 participants 5 messages Jul 7, 2020 – Jul 28, 2020

v3 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hw/core/qdev: Increase qdev_realize() kindness

Since commit 510ef98dca5, qdev_realize() aborts if bus-less device is realized on a bus. While commits 514db7710b..007d1dbf72 took care of converting all mainstream uses, QEMU forks weren't. These forks are usually maintained by hobbyist with interest in following mainstream development, but with limited time, so usually rebase from time to time. To avoid them to spend time on debugging and reading git-log history, display a kind hint about what is wrong.

---
Since v2:
- scratch __func__ (armbru)
- reword to justify this is not an impossible case (armbru)

---
 hw/core/qdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/core/qdev.c +5 -2
index 2131c7f951..a16f1270f1 100644
@@ -392,8 +392,11 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 
     if (bus) {
         qdev_set_parent_bus(dev, bus);
-    } else {
-        assert(!DEVICE_GET_CLASS(dev)->bus_type);
+    } else if (DEVICE_GET_CLASS(dev)->bus_type) {
+        error_setg(errp, "Unexpected bus '%s' for bus-less device '%s'",
+                   DEVICE_GET_CLASS(dev)->bus_type,
+                   object_get_typename(OBJECT(dev)));
+        return false;
     }
 
     object_property_set_bool(OBJECT(dev), true, "realized", &err);
Signature · 1 line
2.21.3
#1 lore raw
Quoted 3 lines · Philippe Mathieu-Daudé

Since commit 510ef98dca5, qdev_realize() aborts if bus-less device is realized on a bus. While commits 514db7710b..007d1dbf72 took care of converting all mainstream uses, QEMU forks weren't. These

I guess I missed "weren't [converted]".

Quoted 33 lines

forks are usually maintained by hobbyist with interest in following mainstream development, but with limited time, so usually rebase from time to time. To avoid them to spend time on debugging and reading git-log history, display a kind hint about what is wrong.

---
Since v2:
- scratch __func__ (armbru)
- reword to justify this is not an impossible case (armbru)

---
 hw/core/qdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/core/qdev.c +5 -2
index 2131c7f951..a16f1270f1 100644
@@ -392,8 +392,11 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 
     if (bus) {
         qdev_set_parent_bus(dev, bus);
-    } else {
-        assert(!DEVICE_GET_CLASS(dev)->bus_type);
+    } else if (DEVICE_GET_CLASS(dev)->bus_type) {
+        error_setg(errp, "Unexpected bus '%s' for bus-less device '%s'",
+                   DEVICE_GET_CLASS(dev)->bus_type,
+                   object_get_typename(OBJECT(dev)));
+        return false;
     }
 
     object_property_set_bool(OBJECT(dev), true, "realized", &err);
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 26 lines · Philippe Mathieu-Daudé

Since commit 510ef98dca5, qdev_realize() aborts if bus-less device is realized on a bus. While commits 514db7710b..007d1dbf72 took care of converting all mainstream uses, QEMU forks weren't. These forks are usually maintained by hobbyist with interest in following mainstream development, but with limited time, so usually rebase from time to time. To avoid them to spend time on debugging and reading git-log history, display a kind hint about what is wrong.

---
Since v2:
- scratch __func__ (armbru)
- reword to justify this is not an impossible case (armbru)

---
 hw/core/qdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/core/qdev.c +0 -0
index 2131c7f951..a16f1270f1 100644
@@ -392,8 +392,11 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 
     if (bus) {
         qdev_set_parent_bus(dev, bus);

hw/core/qdev.c bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) · line 402

Quoted 10 lines
hw/core/qdev.c +5 -2
-    } else {
-        assert(!DEVICE_GET_CLASS(dev)->bus_type);
+    } else if (DEVICE_GET_CLASS(dev)->bus_type) {
+        error_setg(errp, "Unexpected bus '%s' for bus-less device '%s'",
+                   DEVICE_GET_CLASS(dev)->bus_type,
+                   object_get_typename(OBJECT(dev)));
+        return false;
     }
 
     object_property_set_bool(OBJECT(dev), true, "realized", &err);

Queued, thanks.

Paolo

#3 lore raw
Quoted 35 lines · Paolo Bonzini
Quoted 34 lines · Philippe Mathieu-Daudé

Since commit 510ef98dca5, qdev_realize() aborts if bus-less device is realized on a bus. While commits 514db7710b..007d1dbf72 took care of converting all mainstream uses, QEMU forks weren't. These forks are usually maintained by hobbyist with interest in following mainstream development, but with limited time, so usually rebase from time to time. To avoid them to spend time on debugging and reading git-log history, display a kind hint about what is wrong.

---
Since v2:
- scratch __func__ (armbru)
- reword to justify this is not an impossible case (armbru)

---
 hw/core/qdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/core/qdev.c +5 -2
index 2131c7f951..a16f1270f1 100644
@@ -392,8 +392,11 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 
     if (bus) {
         qdev_set_parent_bus(dev, bus);
-    } else {
-        assert(!DEVICE_GET_CLASS(dev)->bus_type);
+    } else if (DEVICE_GET_CLASS(dev)->bus_type) {
+        error_setg(errp, "Unexpected bus '%s' for bus-less device '%s'",
+                   DEVICE_GET_CLASS(dev)->bus_type,
+                   object_get_typename(OBJECT(dev)));
+        return false;
     }
 
Quoted 4 lines

hw/core/qdev.c bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) · line 402

Quoted 2 lines
hw/core/qdev.c +0 -0
     object_property_set_bool(OBJECT(dev), true, "realized", &err);

Queued, thanks.

Thanks! I haven't see that and sent a v4 with example included & typo fixed, if possible can you take it instead?
https://patchew.org/QEMU/[email protected]/

Quoted 4 lines

Paolo

#4 lore raw
Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 35 lines · Paolo Bonzini
Quoted 34 lines · Philippe Mathieu-Daudé

Since commit 510ef98dca5, qdev_realize() aborts if bus-less device is realized on a bus. While commits 514db7710b..007d1dbf72 took care of converting all mainstream uses, QEMU forks weren't. These forks are usually maintained by hobbyist with interest in following mainstream development, but with limited time, so usually rebase from time to time. To avoid them to spend time on debugging and reading git-log history, display a kind hint about what is wrong.

---
Since v2:
- scratch __func__ (armbru)
- reword to justify this is not an impossible case (armbru)

---
 hw/core/qdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/core/qdev.c +5 -2
index 2131c7f951..a16f1270f1 100644
@@ -392,8 +392,11 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 
     if (bus) {
         qdev_set_parent_bus(dev, bus);
-    } else {
-        assert(!DEVICE_GET_CLASS(dev)->bus_type);
+    } else if (DEVICE_GET_CLASS(dev)->bus_type) {
+        error_setg(errp, "Unexpected bus '%s' for bus-less device '%s'",
+                   DEVICE_GET_CLASS(dev)->bus_type,
+                   object_get_typename(OBJECT(dev)));
+        return false;
     }
 
Quoted 8 lines
Quoted 4 lines

hw/core/qdev.c bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) · line 402

Quoted 2 lines
hw/core/qdev.c +0 -0
     object_property_set_bool(OBJECT(dev), true, "realized", &err);

Queued, thanks.

Thanks! I haven't see that and sent a v4 with example included & typo fixed, if possible can you take it instead?
https://patchew.org/QEMU/[email protected]/

Please also consider my objection in reply to v4.