Skip to contentSkip to conversation

hw: Minor simplifications using proper QOM getter macros

PATCH Applied Philippe Mathieu-Daudé 5 participants 13 messages May 23, 2023 – Jun 23, 2023

lore
Share & tools
lore
#0 lore raw

cover hw: Minor simplifications using proper QOM getter macros

Enforce QOM style. Besides, using the proper QOM macros slightly simplifies the code.

Philippe Mathieu-Daudé (4):
hw/core/cpu: Simplify realize() using MACHINE_GET_CLASS() macro hw/i386/microvm: Simplify using object_dynamic_cast() hw/pci/pci: Simplify pci_bar_address() using MACHINE_GET_CLASS() macro hw/usb/hcd-ehci-pci: Simplify using DEVICE_GET_CLASS() macro

 hw/core/cpu-common.c  | 3 +--
 hw/i386/microvm.c     | 3 +--
 hw/pci/pci.c          | 4 +---
 hw/usb/hcd-ehci-pci.c | 2 +-
 4 files changed, 4 insertions(+), 8 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/4 hw/core/cpu: Simplify realize() using MACHINE_GET_CLASS() macro

---
 hw/core/cpu-common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/core/cpu-common.c +1 -2
index 5ccc3837b6..620312e9a5 100644
@@ -196,8 +196,7 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
      * no need to check the ignore_memory_transaction_failures board flag.
      */
     if (object_dynamic_cast(machine, TYPE_MACHINE)) {
-        ObjectClass *oc = object_get_class(machine);
-        MachineClass *mc = MACHINE_CLASS(oc);
+        MachineClass *mc = MACHINE_GET_CLASS(machine);
 
         if (mc) {
             cpu->ignore_memory_transaction_failures =
Signature · 1 line
2.38.1
#3 lore raw

PATCH 2/4 hw/i386/microvm: Simplify using object_dynamic_cast()

In reply to Philippe Mathieu-Daudé

Use object_dynamic_cast() to determine if 'dev' is a TYPE_VIRTIO_MMIO.

---
 hw/i386/microvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/i386/microvm.c +1 -2
index 3d606a20b4..7227a2156c 100644
@@ -389,9 +389,8 @@ static void microvm_fix_kernel_cmdline(MachineState *machine)
     bus = sysbus_get_default();
     QTAILQ_FOREACH(kid, &bus->children, sibling) {
         DeviceState *dev = kid->child;
-        ObjectClass *class = object_get_class(OBJECT(dev));
 
-        if (class == object_class_by_name(TYPE_VIRTIO_MMIO)) {
+        if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MMIO)) {
             VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev));
             VirtioBusState *mmio_virtio_bus = &mmio->bus;
             BusState *mmio_bus = &mmio_virtio_bus->parent_obj;
Signature · 1 line
2.38.1
#6 lore raw

PATCH 3/4 hw/pci/pci: Simplify pci_bar_address() using MACHINE_GET_CLASS() macro

In reply to Philippe Mathieu-Daudé

Remove unnecessary intermediate variables.

---
 hw/pci/pci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/pci/pci.c +1 -3
index 1cc7c89036..a2cb6071cb 100644
@@ -1444,9 +1444,7 @@ pcibus_t pci_bar_address(PCIDevice *d,
 {
     pcibus_t new_addr, last_addr;
     uint16_t cmd = pci_get_word(d->config + PCI_COMMAND);
-    Object *machine = qdev_get_machine();
-    ObjectClass *oc = object_get_class(machine);
-    MachineClass *mc = MACHINE_CLASS(oc);
+    MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
     bool allow_0_address = mc->pci_allow_0_address;
 
     if (type & PCI_BASE_ADDRESS_SPACE_IO) {
Signature · 1 line
2.38.1
#8 lore raw

PATCH 4/4 hw/usb/hcd-ehci-pci: Simplify using DEVICE_GET_CLASS() macro

In reply to Philippe Mathieu-Daudé
---
 hw/usb/hcd-ehci-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/hcd-ehci-pci.c +1 -1
index 4c37c8e227..345444a573 100644
@@ -74,7 +74,7 @@ static void usb_ehci_pci_realize(PCIDevice *dev, Error **errp)
 
 static void usb_ehci_pci_init(Object *obj)
 {
-    DeviceClass *dc = OBJECT_GET_CLASS(DeviceClass, obj, TYPE_DEVICE);
+    DeviceClass *dc = DEVICE_GET_CLASS(obj);
     EHCIPCIState *i = PCI_EHCI(obj);
     EHCIState *s = &i->ehci;
 
Signature · 1 line
2.38.1
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 2 lines · Philippe Mathieu-Daudé

Enforce QOM style. Besides, using the proper QOM macros slightly simplifies the code.

Applied to my trivial-patches branch (Maybe it's time to resurrect it).

Thanks,

/mjt

Reviewed-by
#11 lore raw
Quoted 9 lines · Michael Tokarev
Quoted 2 lines · Philippe Mathieu-Daudé

Enforce QOM style. Besides, using the proper QOM macros slightly simplifies the code.

Applied to my trivial-patches branch (Maybe it's time to resurrect it).

Thanks,

/mjt

pci things:

#12 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 1 line · Michael Tokarev

Applied to my trivial-patches branch (Maybe it's time to resurrect it).

pci things:

It's been merged to master on Jun-11 already. But thank you for the review anyway! :)

/mjt