diff mbox series

[v3,04/14] hw/char/serial-pci-multi: Factor multi_serial_class_initfn() out

Message ID 20230213184338.46712-5-philmd@linaro.org
State New
Headers show
Series hw: Use QOM macros and remove DO_UPCAST() uses | expand

Commit Message

Philippe Mathieu-Daudé Feb. 13, 2023, 6:43 p.m. UTC
Extract code common to multi_2x_serial_pci_class_initfn() and
multi_4x_serial_pci_class_initfn() to multi_serial_class_initfn().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/char/serial-pci-multi.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

Comments

Bernhard Beschow Feb. 14, 2023, 4:07 p.m. UTC | #1
On Mon, Feb 13, 2023 at 7:46 PM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> Extract code common to multi_2x_serial_pci_class_initfn() and
> multi_4x_serial_pci_class_initfn() to multi_serial_class_initfn().
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/char/serial-pci-multi.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
> index e56c0bc841..704be5c294 100644
> --- a/hw/char/serial-pci-multi.c
> +++ b/hw/char/serial-pci-multi.c
> @@ -155,14 +155,14 @@ static Property multi_4x_serial_pci_properties[] = {
>      DEFINE_PROP_END_OF_LIST(),
>  };
>
> -static void multi_2x_serial_pci_class_initfn(ObjectClass *klass, void
> *data)
> +static void multi_serial_class_initfn(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
> +
>      pc->realize = multi_serial_pci_realize;
>      pc->exit = multi_serial_pci_exit;
>      pc->vendor_id = PCI_VENDOR_ID_REDHAT;
> -    pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL2;
>      pc->revision = 1;
>      pc->class_id = PCI_CLASS_COMMUNICATION_SERIAL;
>      dc->vmsd = &vmstate_pci_multi_serial;
> @@ -170,19 +170,22 @@ static void
> multi_2x_serial_pci_class_initfn(ObjectClass *klass, void *data)
>      set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
>  }
>
> +static void multi_2x_serial_pci_class_initfn(ObjectClass *klass, void
> *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +    PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
> +
> +    pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL2;
> +    device_class_set_props(dc, multi_2x_serial_pci_properties);
> +}
> +
>  static void multi_4x_serial_pci_class_initfn(ObjectClass *klass, void
> *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
> -    pc->realize = multi_serial_pci_realize;
> -    pc->exit = multi_serial_pci_exit;
> -    pc->vendor_id = PCI_VENDOR_ID_REDHAT;
> +
>      pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL4;
> -    pc->revision = 1;
> -    pc->class_id = PCI_CLASS_COMMUNICATION_SERIAL;
> -    dc->vmsd = &vmstate_pci_multi_serial;
>      device_class_set_props(dc, multi_4x_serial_pci_properties);
> -    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
>  }
>
>  static void multi_serial_init(Object *o)
> @@ -202,6 +205,7 @@ static const TypeInfo multi_serial_pci_types[] = {
>          .parent         = TYPE_PCI_DEVICE,
>          .instance_size  = sizeof(PCIMultiSerialState),
>          .instance_init  = multi_serial_init,
> +        .class_init     = multi_serial_class_initfn,
>          .abstract       = true,
>          .interfaces     = (InterfaceInfo[]) {
>              { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> --
> 2.38.1
>
>
>
This patch hits an assert for me:

    qemu-system-x86_64: ../src/qom/object.c:1279:
object_class_property_add: Assertion `!object_class_property_find(klass,
name)' failed.

with the following backtrace:

Thread 1 "qemu-system-x86" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6,
no_tid=no_tid@entry=0) at pthread_kill.c:44
44            return INTERNAL_SYSCALL_ERROR_P (ret) ?
INTERNAL_SYSCALL_ERRNO (ret) : 0;
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>,
signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff6c91953 in __pthread_kill_internal (signo=6,
threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007ffff6c42ea8 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#3  0x00007ffff6c2c53d in __GI_abort () at abort.c:79
#4  0x00007ffff6c2c45c in __assert_fail_base
    (fmt=0x7ffff6da5d68 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=0x5555560b9998 "!object_class_property_find(klass, name)",
file=0x5555560b94be "../src/qom/object.c", line=1279, function=<optimized
out>) at assert.c:92
#5  0x00007ffff6c3b9f6 in __assert_fail
    (assertion=assertion@entry=0x5555560b9998
"!object_class_property_find(klass, name)", file=file@entry=0x5555560b94be
"../src/qom/object.c", line=line@entry=1279,
function=function@entry=0x5555560b9d00
<__PRETTY_FUNCTION__.21> "object_class_property_add") at assert.c:101
#6  0x0000555555dbb690 in object_class_property_add
    (klass=klass@entry=0x5555569af820, name=name@entry=0x555555fbe04b
"chardev1", type=0x5555561230dd "str", get=0x555555db2ad0 <field_prop_get>,
set=0x555555db36d0 <field_prop_set>, release=0x5555559f8f90 <release_chr>,
opaque=0x5555563cc900 <multi_4x_serial_pci_properties>) at
../src/qom/object.c:1279
#7  0x0000555555db3e6d in qdev_class_add_property (prop=0x5555563cc900
<multi_4x_serial_pci_properties>, name=0x555555fbe04b "chardev1",
klass=0x5555569af820)
    at ../src/hw/core/qdev-properties.c:889
#8  device_class_set_props (dc=0x5555569af820, props=<optimized out>) at
../src/hw/core/qdev-properties.c:955
#9  0x0000555555dba590 in type_initialize (ti=0x5555567f4840) at
../src/qom/object.c:1094
#10 object_class_foreach_tramp (key=<optimized out>, value=0x5555567f4840,
opaque=0x7fffffffe260) at ../src/qom/object.c:1081
#11 0x00007ffff70bcda8 in g_hash_table_foreach (hash_table=0x5555567b92a0 =
{...}, func=0x555555dba530 <object_class_foreach_tramp>,
user_data=0x7fffffffe260)
    at ../glib/glib/ghash.c:2098
#12 0x0000555555dbaac6 in object_class_foreach (opaque=0x7fffffffe258,
include_abstract=false, implements_type=<optimized out>, fn=0x555555db8a70
<object_class_get_list_tramp>)
    at ../src/qom/object.c:87
#13 object_class_get_list (implements_type=implements_type@entry=0x55555603bb98
"machine", include_abstract=include_abstract@entry=false) at
../src/qom/object.c:1160
#14 0x0000555555b68df7 in select_machine (errp=<optimized out>,
qdict=0x55555684a4e0) at ../src/softmmu/vl.c:1580
#15 qemu_create_machine (qdict=0x55555684a4e0) at ../src/softmmu/vl.c:2015
#16 qemu_init (argc=<optimized out>, argv=0x7fffffffe548) at
../src/softmmu/vl.c:3542
#17 0x000055555596f07e in main (argc=<optimized out>, argv=<optimized out>)
at ../src/softmmu/main.c:47
diff mbox series

Patch

diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
index e56c0bc841..704be5c294 100644
--- a/hw/char/serial-pci-multi.c
+++ b/hw/char/serial-pci-multi.c
@@ -155,14 +155,14 @@  static Property multi_4x_serial_pci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void multi_2x_serial_pci_class_initfn(ObjectClass *klass, void *data)
+static void multi_serial_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
+
     pc->realize = multi_serial_pci_realize;
     pc->exit = multi_serial_pci_exit;
     pc->vendor_id = PCI_VENDOR_ID_REDHAT;
-    pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL2;
     pc->revision = 1;
     pc->class_id = PCI_CLASS_COMMUNICATION_SERIAL;
     dc->vmsd = &vmstate_pci_multi_serial;
@@ -170,19 +170,22 @@  static void multi_2x_serial_pci_class_initfn(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
 }
 
+static void multi_2x_serial_pci_class_initfn(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
+
+    pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL2;
+    device_class_set_props(dc, multi_2x_serial_pci_properties);
+}
+
 static void multi_4x_serial_pci_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
-    pc->realize = multi_serial_pci_realize;
-    pc->exit = multi_serial_pci_exit;
-    pc->vendor_id = PCI_VENDOR_ID_REDHAT;
+
     pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL4;
-    pc->revision = 1;
-    pc->class_id = PCI_CLASS_COMMUNICATION_SERIAL;
-    dc->vmsd = &vmstate_pci_multi_serial;
     device_class_set_props(dc, multi_4x_serial_pci_properties);
-    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
 }
 
 static void multi_serial_init(Object *o)
@@ -202,6 +205,7 @@  static const TypeInfo multi_serial_pci_types[] = {
         .parent         = TYPE_PCI_DEVICE,
         .instance_size  = sizeof(PCIMultiSerialState),
         .instance_init  = multi_serial_init,
+        .class_init     = multi_serial_class_initfn,
         .abstract       = true,
         .interfaces     = (InterfaceInfo[]) {
             { INTERFACE_CONVENTIONAL_PCI_DEVICE },