[PATCH] hw/intc/loongarch_extioi: Move unrealize function to common code

Bibo Mao posted 1 patch 5 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250523095144.2273861-1-maobibo@loongson.cn
Maintainers: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>
hw/intc/loongarch_extioi.c                | 9 ---------
hw/intc/loongarch_extioi_common.c         | 9 +++++++++
include/hw/intc/loongarch_extioi.h        | 1 -
include/hw/intc/loongarch_extioi_common.h | 1 +
4 files changed, 10 insertions(+), 10 deletions(-)
[PATCH] hw/intc/loongarch_extioi: Move unrealize function to common code
Posted by Bibo Mao 5 months, 3 weeks ago
Memory about LoongArchExtIOICommonState::cpu is allocated in common
code, it had better be freed in common code also.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 hw/intc/loongarch_extioi.c                | 9 ---------
 hw/intc/loongarch_extioi_common.c         | 9 +++++++++
 include/hw/intc/loongarch_extioi.h        | 1 -
 include/hw/intc/loongarch_extioi_common.h | 1 +
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
index 7c38c4c9b7..4ec0b2bcff 100644
--- a/hw/intc/loongarch_extioi.c
+++ b/hw/intc/loongarch_extioi.c
@@ -370,13 +370,6 @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
     }
 }
 
-static void loongarch_extioi_unrealize(DeviceState *dev)
-{
-    LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(dev);
-
-    g_free(s->cpu);
-}
-
 static void loongarch_extioi_reset_hold(Object *obj, ResetType type)
 {
     LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_GET_CLASS(obj);
@@ -412,8 +405,6 @@ static void loongarch_extioi_class_init(ObjectClass *klass, const void *data)
 
     device_class_set_parent_realize(dc, loongarch_extioi_realize,
                                     &lec->parent_realize);
-    device_class_set_parent_unrealize(dc, loongarch_extioi_unrealize,
-                                      &lec->parent_unrealize);
     resettable_class_set_parent_phases(rc, NULL, loongarch_extioi_reset_hold,
                                        NULL, &lec->parent_phases);
     lecc->post_load = vmstate_extioi_post_load;
diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_common.c
index 4a904b3bc1..ba03383ed1 100644
--- a/hw/intc/loongarch_extioi_common.c
+++ b/hw/intc/loongarch_extioi_common.c
@@ -108,6 +108,13 @@ static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
     }
 }
 
+static void loongarch_extioi_common_unrealize(DeviceState *dev)
+{
+    LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(dev);
+
+    g_free(s->cpu);
+}
+
 static void loongarch_extioi_common_reset_hold(Object *obj, ResetType type)
 {
     LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_GET_CLASS(obj);
@@ -221,6 +228,8 @@ static void loongarch_extioi_common_class_init(ObjectClass *klass,
 
     device_class_set_parent_realize(dc, loongarch_extioi_common_realize,
                                     &lecc->parent_realize);
+    device_class_set_parent_unrealize(dc, loongarch_extioi_common_unrealize,
+                                      &lecc->parent_unrealize);
     resettable_class_set_parent_phases(rc, NULL,
                                        loongarch_extioi_common_reset_hold,
                                        NULL, &lecc->parent_phases);
diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
index 4a6ae903e9..7744e1bf07 100644
--- a/include/hw/intc/loongarch_extioi.h
+++ b/include/hw/intc/loongarch_extioi.h
@@ -21,7 +21,6 @@ struct LoongArchExtIOIClass {
     LoongArchExtIOICommonClass parent_class;
 
     DeviceRealize parent_realize;
-    DeviceUnrealize parent_unrealize;
     ResettablePhases parent_phases;
 };
 
diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h
index 735bfee80a..74d5dc87df 100644
--- a/include/hw/intc/loongarch_extioi_common.h
+++ b/include/hw/intc/loongarch_extioi_common.h
@@ -94,6 +94,7 @@ struct LoongArchExtIOICommonClass {
     SysBusDeviceClass parent_class;
 
     DeviceRealize parent_realize;
+    DeviceUnrealize parent_unrealize;
     ResettablePhases parent_phases;
     int (*pre_save)(void *s);
     int (*post_load)(void *s, int version_id);

base-commit: 2af4a82ab2cce3412ffc92cd4c96bd870e33bc8e
-- 
2.39.3
Re: [PATCH] hw/intc/loongarch_extioi: Move unrealize function to common code
Posted by gaosong 5 months, 3 weeks ago
在 2025/5/23 下午5:51, Bibo Mao 写道:
> Memory about LoongArchExtIOICommonState::cpu is allocated in common
> code, it had better be freed in common code also.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   hw/intc/loongarch_extioi.c                | 9 ---------
>   hw/intc/loongarch_extioi_common.c         | 9 +++++++++
>   include/hw/intc/loongarch_extioi.h        | 1 -
>   include/hw/intc/loongarch_extioi_common.h | 1 +
>   4 files changed, 10 insertions(+), 10 deletions(-)
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
> index 7c38c4c9b7..4ec0b2bcff 100644
> --- a/hw/intc/loongarch_extioi.c
> +++ b/hw/intc/loongarch_extioi.c
> @@ -370,13 +370,6 @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
>       }
>   }
>   
> -static void loongarch_extioi_unrealize(DeviceState *dev)
> -{
> -    LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(dev);
> -
> -    g_free(s->cpu);
> -}
> -
>   static void loongarch_extioi_reset_hold(Object *obj, ResetType type)
>   {
>       LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_GET_CLASS(obj);
> @@ -412,8 +405,6 @@ static void loongarch_extioi_class_init(ObjectClass *klass, const void *data)
>   
>       device_class_set_parent_realize(dc, loongarch_extioi_realize,
>                                       &lec->parent_realize);
> -    device_class_set_parent_unrealize(dc, loongarch_extioi_unrealize,
> -                                      &lec->parent_unrealize);
>       resettable_class_set_parent_phases(rc, NULL, loongarch_extioi_reset_hold,
>                                          NULL, &lec->parent_phases);
>       lecc->post_load = vmstate_extioi_post_load;
> diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_common.c
> index 4a904b3bc1..ba03383ed1 100644
> --- a/hw/intc/loongarch_extioi_common.c
> +++ b/hw/intc/loongarch_extioi_common.c
> @@ -108,6 +108,13 @@ static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
>       }
>   }
>   
> +static void loongarch_extioi_common_unrealize(DeviceState *dev)
> +{
> +    LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(dev);
> +
> +    g_free(s->cpu);
> +}
> +
>   static void loongarch_extioi_common_reset_hold(Object *obj, ResetType type)
>   {
>       LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_GET_CLASS(obj);
> @@ -221,6 +228,8 @@ static void loongarch_extioi_common_class_init(ObjectClass *klass,
>   
>       device_class_set_parent_realize(dc, loongarch_extioi_common_realize,
>                                       &lecc->parent_realize);
> +    device_class_set_parent_unrealize(dc, loongarch_extioi_common_unrealize,
> +                                      &lecc->parent_unrealize);
>       resettable_class_set_parent_phases(rc, NULL,
>                                          loongarch_extioi_common_reset_hold,
>                                          NULL, &lecc->parent_phases);
> diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
> index 4a6ae903e9..7744e1bf07 100644
> --- a/include/hw/intc/loongarch_extioi.h
> +++ b/include/hw/intc/loongarch_extioi.h
> @@ -21,7 +21,6 @@ struct LoongArchExtIOIClass {
>       LoongArchExtIOICommonClass parent_class;
>   
>       DeviceRealize parent_realize;
> -    DeviceUnrealize parent_unrealize;
>       ResettablePhases parent_phases;
>   };
>   
> diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h
> index 735bfee80a..74d5dc87df 100644
> --- a/include/hw/intc/loongarch_extioi_common.h
> +++ b/include/hw/intc/loongarch_extioi_common.h
> @@ -94,6 +94,7 @@ struct LoongArchExtIOICommonClass {
>       SysBusDeviceClass parent_class;
>   
>       DeviceRealize parent_realize;
> +    DeviceUnrealize parent_unrealize;
>       ResettablePhases parent_phases;
>       int (*pre_save)(void *s);
>       int (*post_load)(void *s, int version_id);
>
> base-commit: 2af4a82ab2cce3412ffc92cd4c96bd870e33bc8e