diff mbox series

[v4,1/6] hw/misc/edu: Convert type_init() -> DEFINE_TYPES()

Message ID 20250424194905.82506-2-philmd@linaro.org
State New
Headers show
Series qom: Constify class_data | expand

Commit Message

Philippe Mathieu-Daudé April 24, 2025, 7:49 p.m. UTC
Prefer DEFINE_TYPES() macro over type_init() to register
QOM types.

Initialize the .interfaces struct field as compound literal
casted to InterfaceInfo type like the rest of our code base.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/misc/edu.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Comments

Richard Henderson April 24, 2025, 9:16 p.m. UTC | #1
On 4/24/25 12:49, Philippe Mathieu-Daudé wrote:
> Prefer DEFINE_TYPES() macro over type_init() to register
> QOM types.
> 
> Initialize the .interfaces struct field as compound literal
> casted to InterfaceInfo type like the rest of our code base.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/misc/edu.c | 21 +++++++++------------
>   1 file changed, 9 insertions(+), 12 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

> 
> diff --git a/hw/misc/edu.c b/hw/misc/edu.c
> index 504178b4a22..5723ef0ed13 100644
> --- a/hw/misc/edu.c
> +++ b/hw/misc/edu.c
> @@ -429,21 +429,18 @@ static void edu_class_init(ObjectClass *class, void *data)
>       set_bit(DEVICE_CATEGORY_MISC, dc->categories);
>   }
>   
> -static void pci_edu_register_types(void)
> -{
> -    static InterfaceInfo interfaces[] = {
> -        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> -        { },
> -    };
> -    static const TypeInfo edu_info = {
> +static const TypeInfo edu_types[] = {
> +    {
>           .name          = TYPE_PCI_EDU_DEVICE,
>           .parent        = TYPE_PCI_DEVICE,
>           .instance_size = sizeof(EduState),
>           .instance_init = edu_instance_init,
>           .class_init    = edu_class_init,
> -        .interfaces = interfaces,
> -    };
> +        .interfaces    = (InterfaceInfo[]) {
> +            { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> +            { },
> +        },
> +    }
> +};
>   
> -    type_register_static(&edu_info);
> -}
> -type_init(pci_edu_register_types)
> +DEFINE_TYPES(edu_types)
diff mbox series

Patch

diff --git a/hw/misc/edu.c b/hw/misc/edu.c
index 504178b4a22..5723ef0ed13 100644
--- a/hw/misc/edu.c
+++ b/hw/misc/edu.c
@@ -429,21 +429,18 @@  static void edu_class_init(ObjectClass *class, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 }
 
-static void pci_edu_register_types(void)
-{
-    static InterfaceInfo interfaces[] = {
-        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
-        { },
-    };
-    static const TypeInfo edu_info = {
+static const TypeInfo edu_types[] = {
+    {
         .name          = TYPE_PCI_EDU_DEVICE,
         .parent        = TYPE_PCI_DEVICE,
         .instance_size = sizeof(EduState),
         .instance_init = edu_instance_init,
         .class_init    = edu_class_init,
-        .interfaces = interfaces,
-    };
+        .interfaces    = (InterfaceInfo[]) {
+            { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+            { },
+        },
+    }
+};
 
-    type_register_static(&edu_info);
-}
-type_init(pci_edu_register_types)
+DEFINE_TYPES(edu_types)