diff mbox series

[11/23] hw/i2c/mpc_i2c: Prefer DEFINE_TYPES() macro

Message ID 20240923093016.66437-12-shentey@gmail.com (mailing list archive)
State New, archived
Headers show
Series E500 Cleanup | expand

Commit Message

Bernhard Beschow Sept. 23, 2024, 9:30 a.m. UTC
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 hw/i2c/mpc_i2c.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

BALATON Zoltan Sept. 23, 2024, 10:49 a.m. UTC | #1
On Mon, 23 Sep 2024, Bernhard Beschow wrote:
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
> hw/i2c/mpc_i2c.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/hw/i2c/mpc_i2c.c b/hw/i2c/mpc_i2c.c
> index 3d79c15653..16f4309ea9 100644
> --- a/hw/i2c/mpc_i2c.c
> +++ b/hw/i2c/mpc_i2c.c
> @@ -20,7 +20,6 @@
> #include "qemu/osdep.h"
> #include "hw/i2c/i2c.h"
> #include "hw/irq.h"
> -#include "qemu/module.h"
> #include "hw/sysbus.h"
> #include "migration/vmstate.h"
> #include "qom/object.h"
> @@ -345,16 +344,13 @@ static void mpc_i2c_class_init(ObjectClass *klass, void *data)
>     dc->desc = "MPC I2C Controller";
> }
>
> -static const TypeInfo mpc_i2c_type_info = {
> -    .name          = TYPE_MPC_I2C,
> -    .parent        = TYPE_SYS_BUS_DEVICE,
> -    .instance_size = sizeof(MPCI2CState),
> -    .class_init    = mpc_i2c_class_init,
> +static const TypeInfo types[] = {
> +    {
> +        .name          = TYPE_MPC_I2C,
> +        .parent        = TYPE_SYS_BUS_DEVICE,
> +        .instance_size = sizeof(MPCI2CState),
> +        .class_init    = mpc_i2c_class_init,
> +    },
> };
>
> -static void mpc_i2c_register_types(void)
> -{
> -    type_register_static(&mpc_i2c_type_info);
> -}
> -
> -type_init(mpc_i2c_register_types)
> +DEFINE_TYPES(types)

What's the advantage of this when we have a single device? For these 
devices this looks like just code churn to me.

Regards,
BALATON Zoltan
Bernhard Beschow Sept. 23, 2024, 10:01 p.m. UTC | #2
Am 23. September 2024 10:49:53 UTC schrieb BALATON Zoltan <balaton@eik.bme.hu>:
>On Mon, 23 Sep 2024, Bernhard Beschow wrote:
>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>> ---
>> hw/i2c/mpc_i2c.c | 20 ++++++++------------
>> 1 file changed, 8 insertions(+), 12 deletions(-)
>> 
>> diff --git a/hw/i2c/mpc_i2c.c b/hw/i2c/mpc_i2c.c
>> index 3d79c15653..16f4309ea9 100644
>> --- a/hw/i2c/mpc_i2c.c
>> +++ b/hw/i2c/mpc_i2c.c
>> @@ -20,7 +20,6 @@
>> #include "qemu/osdep.h"
>> #include "hw/i2c/i2c.h"
>> #include "hw/irq.h"
>> -#include "qemu/module.h"
>> #include "hw/sysbus.h"
>> #include "migration/vmstate.h"
>> #include "qom/object.h"
>> @@ -345,16 +344,13 @@ static void mpc_i2c_class_init(ObjectClass *klass, void *data)
>>     dc->desc = "MPC I2C Controller";
>> }
>> 
>> -static const TypeInfo mpc_i2c_type_info = {
>> -    .name          = TYPE_MPC_I2C,
>> -    .parent        = TYPE_SYS_BUS_DEVICE,
>> -    .instance_size = sizeof(MPCI2CState),
>> -    .class_init    = mpc_i2c_class_init,
>> +static const TypeInfo types[] = {
>> +    {
>> +        .name          = TYPE_MPC_I2C,
>> +        .parent        = TYPE_SYS_BUS_DEVICE,
>> +        .instance_size = sizeof(MPCI2CState),
>> +        .class_init    = mpc_i2c_class_init,
>> +    },
>> };
>> 
>> -static void mpc_i2c_register_types(void)
>> -{
>> -    type_register_static(&mpc_i2c_type_info);
>> -}
>> -
>> -type_init(mpc_i2c_register_types)
>> +DEFINE_TYPES(types)
>
>What's the advantage of this when we have a single device? For these devices this looks like just code churn to me.

It is still shorter and also more modern style. As a nice side effect it also helps in my experimental branch (which may never ship).

Best regards,
Bernhard

>
>Regards,
>BALATON Zoltan
BALATON Zoltan Sept. 24, 2024, 10:12 a.m. UTC | #3
On Mon, 23 Sep 2024, Bernhard Beschow wrote:
> Am 23. September 2024 10:49:53 UTC schrieb BALATON Zoltan <balaton@eik.bme.hu>:
>> On Mon, 23 Sep 2024, Bernhard Beschow wrote:
>>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>>> ---
>>> hw/i2c/mpc_i2c.c | 20 ++++++++------------
>>> 1 file changed, 8 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/hw/i2c/mpc_i2c.c b/hw/i2c/mpc_i2c.c
>>> index 3d79c15653..16f4309ea9 100644
>>> --- a/hw/i2c/mpc_i2c.c
>>> +++ b/hw/i2c/mpc_i2c.c
>>> @@ -20,7 +20,6 @@
>>> #include "qemu/osdep.h"
>>> #include "hw/i2c/i2c.h"
>>> #include "hw/irq.h"
>>> -#include "qemu/module.h"
>>> #include "hw/sysbus.h"
>>> #include "migration/vmstate.h"
>>> #include "qom/object.h"
>>> @@ -345,16 +344,13 @@ static void mpc_i2c_class_init(ObjectClass *klass, void *data)
>>>     dc->desc = "MPC I2C Controller";
>>> }
>>>
>>> -static const TypeInfo mpc_i2c_type_info = {
>>> -    .name          = TYPE_MPC_I2C,
>>> -    .parent        = TYPE_SYS_BUS_DEVICE,
>>> -    .instance_size = sizeof(MPCI2CState),
>>> -    .class_init    = mpc_i2c_class_init,
>>> +static const TypeInfo types[] = {
>>> +    {
>>> +        .name          = TYPE_MPC_I2C,
>>> +        .parent        = TYPE_SYS_BUS_DEVICE,
>>> +        .instance_size = sizeof(MPCI2CState),
>>> +        .class_init    = mpc_i2c_class_init,
>>> +    },
>>> };
>>>
>>> -static void mpc_i2c_register_types(void)
>>> -{
>>> -    type_register_static(&mpc_i2c_type_info);
>>> -}
>>> -
>>> -type_init(mpc_i2c_register_types)
>>> +DEFINE_TYPES(types)
>>
>> What's the advantage of this when we have a single device? For these devices this looks like just code churn to me.
>
> It is still shorter and also more modern style. As a nice side effect it also helps in my experimental branch (which may never ship).

I don't mind changing this but I see no real advantage either. It removes 
a one line function but adds a one element array instead which is about 
the same level of boilerplate and not less confusing for new people so it 
does not seem to help much.

Regards,
BALATON Zoltan
Cédric Le Goater Sept. 25, 2024, 3:40 p.m. UTC | #4
On 9/23/24 11:30, Bernhard Beschow wrote:
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/i2c/mpc_i2c.c | 20 ++++++++------------
>   1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/i2c/mpc_i2c.c b/hw/i2c/mpc_i2c.c
> index 3d79c15653..16f4309ea9 100644
> --- a/hw/i2c/mpc_i2c.c
> +++ b/hw/i2c/mpc_i2c.c
> @@ -20,7 +20,6 @@
>   #include "qemu/osdep.h"
>   #include "hw/i2c/i2c.h"
>   #include "hw/irq.h"
> -#include "qemu/module.h"
>   #include "hw/sysbus.h"
>   #include "migration/vmstate.h"
>   #include "qom/object.h"
> @@ -345,16 +344,13 @@ static void mpc_i2c_class_init(ObjectClass *klass, void *data)
>       dc->desc = "MPC I2C Controller";
>   }
>   
> -static const TypeInfo mpc_i2c_type_info = {
> -    .name          = TYPE_MPC_I2C,
> -    .parent        = TYPE_SYS_BUS_DEVICE,
> -    .instance_size = sizeof(MPCI2CState),
> -    .class_init    = mpc_i2c_class_init,
> +static const TypeInfo types[] = {
> +    {
> +        .name          = TYPE_MPC_I2C,
> +        .parent        = TYPE_SYS_BUS_DEVICE,
> +        .instance_size = sizeof(MPCI2CState),
> +        .class_init    = mpc_i2c_class_init,
> +    },
>   };
>   
> -static void mpc_i2c_register_types(void)
> -{
> -    type_register_static(&mpc_i2c_type_info);
> -}
> -
> -type_init(mpc_i2c_register_types)
> +DEFINE_TYPES(types)
diff mbox series

Patch

diff --git a/hw/i2c/mpc_i2c.c b/hw/i2c/mpc_i2c.c
index 3d79c15653..16f4309ea9 100644
--- a/hw/i2c/mpc_i2c.c
+++ b/hw/i2c/mpc_i2c.c
@@ -20,7 +20,6 @@ 
 #include "qemu/osdep.h"
 #include "hw/i2c/i2c.h"
 #include "hw/irq.h"
-#include "qemu/module.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 #include "qom/object.h"
@@ -345,16 +344,13 @@  static void mpc_i2c_class_init(ObjectClass *klass, void *data)
     dc->desc = "MPC I2C Controller";
 }
 
-static const TypeInfo mpc_i2c_type_info = {
-    .name          = TYPE_MPC_I2C,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(MPCI2CState),
-    .class_init    = mpc_i2c_class_init,
+static const TypeInfo types[] = {
+    {
+        .name          = TYPE_MPC_I2C,
+        .parent        = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(MPCI2CState),
+        .class_init    = mpc_i2c_class_init,
+    },
 };
 
-static void mpc_i2c_register_types(void)
-{
-    type_register_static(&mpc_i2c_type_info);
-}
-
-type_init(mpc_i2c_register_types)
+DEFINE_TYPES(types)