diff mbox series

[v5,04/19] hw/intc/loongson_ipi: Extract loongson_ipi_common_finalize()

Message ID 20240718133312.10324-5-philmd@linaro.org
State New
Headers show
Series Reconstruct loongson ipi driver | expand

Commit Message

Philippe Mathieu-Daudé July 18, 2024, 1:32 p.m. UTC
From: Bibo Mao <maobibo@loongson.cn>

In preparation to extract common IPI code in few commits,
extract loongson_ipi_common_finalize().

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
[PMD: Extracted from bigger commit, added commit description]
Co-Developed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Tested-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Song Gao <gaosong@loongson.cn>
---
 hw/intc/loongson_ipi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé July 23, 2024, 8:41 a.m. UTC | #1
On 18/7/24 15:32, Philippe Mathieu-Daudé wrote:
> From: Bibo Mao <maobibo@loongson.cn>
> 
> In preparation to extract common IPI code in few commits,
> extract loongson_ipi_common_finalize().
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> [PMD: Extracted from bigger commit, added commit description]
> Co-Developed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
> Tested-by: Bibo Mao <maobibo@loongson.cn>
> Acked-by: Song Gao <gaosong@loongson.cn>
> ---
>   hw/intc/loongson_ipi.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
> index d870af39c1..960d1e604f 100644
> --- a/hw/intc/loongson_ipi.c
> +++ b/hw/intc/loongson_ipi.c
> @@ -357,13 +357,18 @@ static void loongson_ipi_class_init(ObjectClass *klass, void *data)
>       dc->vmsd = &vmstate_loongson_ipi;
>   }
>   
> -static void loongson_ipi_finalize(Object *obj)
> +static void loongson_ipi_common_finalize(Object *obj)
>   {
>       LoongsonIPIState *s = LOONGSON_IPI(obj);
>   
>       g_free(s->cpu);

Unfortunately the current code is bogus, @cpu is allocated in
loongson_ipi_realize(), a DeviceRealize handler, so must be
de-allocated in a DeviceUnrealize equivalent. Not at the instance
finalize cleanup which is too late because we could leak after
UNREALIZE -> REALIZE sequences.

>   }
>   
> +static void loongson_ipi_finalize(Object *obj)
> +{
> +    loongson_ipi_common_finalize(obj);
> +}
> +
>   static const TypeInfo loongson_ipi_types[] = {
>       {
>           .name               = TYPE_LOONGSON_IPI,
Song Gao July 23, 2024, 10 a.m. UTC | #2
在 2024/7/23 下午4:41, Philippe Mathieu-Daudé 写道:
> On 18/7/24 15:32, Philippe Mathieu-Daudé wrote:
>> From: Bibo Mao <maobibo@loongson.cn>
>>
>> In preparation to extract common IPI code in few commits,
>> extract loongson_ipi_common_finalize().
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> [PMD: Extracted from bigger commit, added commit description]
>> Co-Developed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
>> Tested-by: Bibo Mao <maobibo@loongson.cn>
>> Acked-by: Song Gao <gaosong@loongson.cn>
>> ---
>>   hw/intc/loongson_ipi.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
>> index d870af39c1..960d1e604f 100644
>> --- a/hw/intc/loongson_ipi.c
>> +++ b/hw/intc/loongson_ipi.c
>> @@ -357,13 +357,18 @@ static void loongson_ipi_class_init(ObjectClass 
>> *klass, void *data)
>>       dc->vmsd = &vmstate_loongson_ipi;
>>   }
>>   -static void loongson_ipi_finalize(Object *obj)
>> +static void loongson_ipi_common_finalize(Object *obj)
>>   {
>>       LoongsonIPIState *s = LOONGSON_IPI(obj);
>>         g_free(s->cpu);
>
> Unfortunately the current code is bogus, @cpu is allocated in
> loongson_ipi_realize(), a DeviceRealize handler, so must be
> de-allocated in a DeviceUnrealize equivalent. Not at the instance
> finalize cleanup which is too late because we could leak after
> UNREALIZE -> REALIZE sequences.
>
Yes,  we should use  DeviecUnrealize to free s->cpu.

I will send a patch to correct it.

Thanks.
Song Gao
>>   }
>>   +static void loongson_ipi_finalize(Object *obj)
>> +{
>> +    loongson_ipi_common_finalize(obj);
>> +}
>> +
>>   static const TypeInfo loongson_ipi_types[] = {
>>       {
>>           .name               = TYPE_LOONGSON_IPI,
Philippe Mathieu-Daudé July 23, 2024, 10:17 a.m. UTC | #3
On 23/7/24 12:00, gaosong wrote:
> 在 2024/7/23 下午4:41, Philippe Mathieu-Daudé 写道:
>> On 18/7/24 15:32, Philippe Mathieu-Daudé wrote:
>>> From: Bibo Mao <maobibo@loongson.cn>
>>>
>>> In preparation to extract common IPI code in few commits,
>>> extract loongson_ipi_common_finalize().
>>>
>>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>>> [PMD: Extracted from bigger commit, added commit description]
>>> Co-Developed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
>>> Tested-by: Bibo Mao <maobibo@loongson.cn>
>>> Acked-by: Song Gao <gaosong@loongson.cn>
>>> ---
>>>   hw/intc/loongson_ipi.c | 7 ++++++-
>>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
>>> index d870af39c1..960d1e604f 100644
>>> --- a/hw/intc/loongson_ipi.c
>>> +++ b/hw/intc/loongson_ipi.c
>>> @@ -357,13 +357,18 @@ static void loongson_ipi_class_init(ObjectClass 
>>> *klass, void *data)
>>>       dc->vmsd = &vmstate_loongson_ipi;
>>>   }
>>>   -static void loongson_ipi_finalize(Object *obj)
>>> +static void loongson_ipi_common_finalize(Object *obj)
>>>   {
>>>       LoongsonIPIState *s = LOONGSON_IPI(obj);
>>>         g_free(s->cpu);
>>
>> Unfortunately the current code is bogus, @cpu is allocated in
>> loongson_ipi_realize(), a DeviceRealize handler, so must be
>> de-allocated in a DeviceUnrealize equivalent. Not at the instance
>> finalize cleanup which is too late because we could leak after
>> UNREALIZE -> REALIZE sequences.
>>
> Yes,  we should use  DeviecUnrealize to free s->cpu.
> 
> I will send a patch to correct it.

No need, I already wrote it, currently testing various build
configs before posting v6.
diff mbox series

Patch

diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
index d870af39c1..960d1e604f 100644
--- a/hw/intc/loongson_ipi.c
+++ b/hw/intc/loongson_ipi.c
@@ -357,13 +357,18 @@  static void loongson_ipi_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_loongson_ipi;
 }
 
-static void loongson_ipi_finalize(Object *obj)
+static void loongson_ipi_common_finalize(Object *obj)
 {
     LoongsonIPIState *s = LOONGSON_IPI(obj);
 
     g_free(s->cpu);
 }
 
+static void loongson_ipi_finalize(Object *obj)
+{
+    loongson_ipi_common_finalize(obj);
+}
+
 static const TypeInfo loongson_ipi_types[] = {
     {
         .name               = TYPE_LOONGSON_IPI,