diff mbox series

[for-6.2,02/12] qom: Use DEVICE_*CLASS instead of OBJECT_*CLASS

Message ID 20210806211127.646908-3-ehabkost@redhat.com
State New
Headers show
Series qom: Get rid of all manual usage of OBJECT_CHECK & friends | expand

Commit Message

Eduardo Habkost Aug. 6, 2021, 9:11 p.m. UTC
There are multiple functions where OBJECT_GET_CLASS or
OBJECT_CLASS_CHECK are being used directly for
DeviceClass/TYPE_DEVICE, instead of the DEVICE_GET_CLASS or
DEVICE_CLASS wrappers.  There's no reason to not use the
wrappers, so use them.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 hw/pci/pci.c           | 3 +--
 hw/usb/hcd-ehci-pci.c  | 2 +-
 migration/savevm.c     | 3 +--
 monitor/misc.c         | 3 +--
 softmmu/qdev-monitor.c | 3 +--
 5 files changed, 5 insertions(+), 9 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 7, 2021, 8:17 a.m. UTC | #1
On 8/6/21 11:11 PM, Eduardo Habkost wrote:
> There are multiple functions where OBJECT_GET_CLASS or
> OBJECT_CLASS_CHECK are being used directly for
> DeviceClass/TYPE_DEVICE, instead of the DEVICE_GET_CLASS or
> DEVICE_CLASS wrappers.  There's no reason to not use the
> wrappers, so use them.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Juan Quintela <quintela@redhat.com>
> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Daniel P. Berrangé" <berrange@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  hw/pci/pci.c           | 3 +--
>  hw/usb/hcd-ehci-pci.c  | 2 +-
>  migration/savevm.c     | 3 +--
>  monitor/misc.c         | 3 +--
>  softmmu/qdev-monitor.c | 3 +--
>  5 files changed, 5 insertions(+), 9 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Juan Quintela Aug. 10, 2021, 11:56 a.m. UTC | #2
Eduardo Habkost <ehabkost@redhat.com> wrote:
> There are multiple functions where OBJECT_GET_CLASS or
> OBJECT_CLASS_CHECK are being used directly for
> DeviceClass/TYPE_DEVICE, instead of the DEVICE_GET_CLASS or
> DEVICE_CLASS wrappers.  There's no reason to not use the
> wrappers, so use them.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>



> -        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, list->data,
> -                                             TYPE_DEVICE);
> +        DeviceClass *dc = DEVICE_CLASS(list->data);

Finding where DEVICE_CLASS is defined is .... interesting.
Eduardo Habkost Aug. 10, 2021, 2:22 p.m. UTC | #3
On Tue, Aug 10, 2021 at 01:56:25PM +0200, Juan Quintela wrote:
> > -        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, list->data,
> > -                                             TYPE_DEVICE);
> > +        DeviceClass *dc = DEVICE_CLASS(list->data);
> 
> Finding where DEVICE_CLASS is defined is .... interesting.

That's a valid concern, but I wonder what we can do to address
this.  The existing practice of defining all macros manually
leads to a high number of mistakes and inconsistencies[1].

Now, once all QOM types are converted to the new macros (which is
work in progress), maybe we could replace:

  DEVICE_CLASS(oc)
  DEVICE_GET_CLASS(dev)

with more grep-friendly expressions like:

  CLASS(DEVICE, oc)
  GET_CLASS(DEVICE, dev)

The type of those expressions would still be (DeviceClass*).

---

[1] These are some of the fixes for bugs or inconsistencies that were
already merged to qemu.git:

6a567fbcf0b8 nubus: Delete unused NUBUS_BRIDGE macro
98b49b2bea15 spapr: Remove unnecessary DRC type-checker macros
08e14bb7e060 platform-bus: Delete macros for non-existing typedef
5c8b0f2cc799 can_emu: Delete macros for non-existing typedef
f58b770fbbd9 virtio-ccw: Fix definition of VIRTIO_CCW_BUS_GET_CLASS

These are fixes for broken QOM macros I submitted recently:

[PATCH for-6.2 1/6] acpi: Delete broken ACPI_GED_X86 macro
[PATCH for-6.2 2/6] sbsa_gwdt: Delete broken SBSA_*CLASS macros

And these are some other inconsistencies that are still in the
current tree, that need to be addressed:

hw/i386/kvm/i8254.c:45:1: type name mismatch: TYPE_KVM_I8254 vs KVM_PIT
hw/net/e1000.c:158:1: type name mismatch: TYPE_E1000_BASE vs E1000
hw/rtc/m48t59-isa.c:38:1: mismatching class type for M48TXX_ISA (M48txxISADeviceClass)
hw/rtc/m48t59-isa.c:131:1: class type declared here (None)
hw/rtc/m48t59.c:47:1: mismatching class type for M48TXX_SYS_BUS (M48txxSysBusDeviceClass)
hw/rtc/m48t59.c:654:1: class type declared here (None)
hw/s390x/virtio-ccw.h:63:1: typedef name mismatch: VirtioCcwBusState is defined as struct VirtioBusState
hw/s390x/virtio-ccw.h:59:1: typedef is here
hw/scsi/megasas.c:137:1: type name mismatch: TYPE_MEGASAS_BASE vs MEGASAS
hw/virtio/virtio-pci.h:29:1: typedef name mismatch: VirtioPCIBusState is defined as struct VirtioBusState
hw/virtio/virtio-pci.h:25:1: typedef is here
include/exec/memory.h:48:1: mismatching instance type for RAM_DISCARD_MANAGER (RamDiscardManager)
softmmu/memory.c:3418:1: instance type declared here (None)
include/hw/isa/superio.h:20:1: mismatching instance type for ISA_SUPERIO (ISASuperIODevice)
hw/isa/isa-superio.c:180:1: instance type declared here (None)
include/hw/s390x/event-facility.h:197:1: type name mismatch: TYPE_SCLP_EVENT_FACILITY vs EVENT_FACILITY
include/hw/s390x/s390-ccw.h:22:1: type name mismatch: TYPE_S390_CCW vs S390_CCW_DEVICE
include/hw/vfio/vfio-amd-xgbe.h:43:1: type name mismatch: TYPE_VFIO_AMD_XGBE vs VFIO_AMD_XGBE_DEVICE
include/hw/vfio/vfio-calxeda-xgmac.h:40:1: type name mismatch: TYPE_VFIO_CALXEDA_XGMAC vs VFIO_CALXEDA_XGMAC_DEVICE
include/hw/vfio/vfio-platform.h:73:1: type name mismatch: TYPE_VFIO_PLATFORM vs VFIO_PLATFORM_DEVICE
include/hw/watchdog/wdt_diag288.h:10:1: type name mismatch: TYPE_WDT_DIAG288 vs DIAG288
migration/migration.h:141:1: type name mismatch: TYPE_MIGRATION vs MIGRATION_OBJ
target/ppc/cpu.h:1253:1: mismatching instance type for PPC_VIRTUAL_HYPERVISOR (PPCVirtualHypervisor)
target/ppc/cpu_init.c:9090:1: instance type declared here (None)
diff mbox series

Patch

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 23d2ae2ab23..9af32ef4cb8 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1915,8 +1915,7 @@  PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
     list = object_class_get_list_sorted(TYPE_PCI_DEVICE, false);
     pci_nic_models = g_ptr_array_new();
     while (list) {
-        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, list->data,
-                                             TYPE_DEVICE);
+        DeviceClass *dc = DEVICE_CLASS(list->data);
         GSList *next;
         if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
             dc->user_creatable) {
diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 4c37c8e2271..345444a5739 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -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;
 
diff --git a/migration/savevm.c b/migration/savevm.c
index 7b7b64bd13e..23cc55b8533 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -663,8 +663,7 @@  void dump_vmstate_json_to_file(FILE *out_file)
     first = true;
     list = object_class_get_list(TYPE_DEVICE, true);
     for (elt = list; elt; elt = elt->next) {
-        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
-                                             TYPE_DEVICE);
+        DeviceClass *dc = DEVICE_CLASS(elt->data);
         const char *name;
         int indent = 2;
 
diff --git a/monitor/misc.c b/monitor/misc.c
index ffe79668706..98202d12e7f 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -1549,8 +1549,7 @@  void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
     list = elt = object_class_get_list(TYPE_DEVICE, false);
     while (elt) {
         const char *name;
-        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
-                                             TYPE_DEVICE);
+        DeviceClass *dc = DEVICE_CLASS(elt->data);
         name = object_class_get_name(OBJECT_CLASS(dc));
 
         if (dc->user_creatable
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 721dec2d820..82d164c6539 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -165,8 +165,7 @@  static void qdev_print_devinfos(bool show_no_user)
     for (i = 0; i <= DEVICE_CATEGORY_MAX; i++) {
         cat_printed = false;
         for (elt = list; elt; elt = elt->next) {
-            DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
-                                                 TYPE_DEVICE);
+            DeviceClass *dc = DEVICE_CLASS(elt->data);
             if ((i < DEVICE_CATEGORY_MAX
                  ? !test_bit(i, dc->categories)
                  : !bitmap_empty(dc->categories, DEVICE_CATEGORY_MAX))