qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 2/3] hw/arm: Connect STM32L4x5 GPIO to STM32L4x5 SoC


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2 2/3] hw/arm: Connect STM32L4x5 GPIO to STM32L4x5 SoC
Date: Tue, 23 Jan 2024 09:09:31 +0100
User-agent: Mozilla Thunderbird

Hi Inès,

On 22/1/24 22:02, Inès Varhol wrote:
Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
---
  hw/arm/Kconfig                 |  3 +-
  hw/arm/stm32l4x5_soc.c         | 79 ++++++++++++++++++++++++++++------
  include/hw/arm/stm32l4x5_soc.h |  2 +
  3 files changed, 69 insertions(+), 15 deletions(-)


  static void stm32l4x5_soc_initfn(Object *obj)
  {
      Stm32l4x5SocState *s = STM32L4X5_SOC(obj);
+    g_autofree char *name = NULL;

       [1]
object_initialize_child(obj, "exti", &s->exti, TYPE_STM32L4X5_EXTI);
      object_initialize_child(obj, "syscfg", &s->syscfg, TYPE_STM32L4X5_SYSCFG);
      object_initialize_child(obj, "rcc", &s->rcc, TYPE_STM32L4X5_RCC);
+
+    for (unsigned i = 0; i < NUM_GPIOS; i++) {
+        name = g_strdup_printf("gpio%c", 'a' + i);

          [2] // alloc

+        object_initialize_child(obj, name, &s->gpio[i], TYPE_STM32L4X5_GPIO);

          [3] // expected free

+    }

      [4] // current autofree

  }
If you declare the variable to be automatically free'd in the
main body scope [1], it will be free'd when the scope is leaved,
so in [4], meaning only the *last* allocation ("GPIOH") from [2]
will be free'd, all other are leaked. We want to release in [3].

Similar comment applies to stm32l4x5_soc_realize() in this
patch.

See https://docs.gtk.org/glib/auto-cleanup.html for context.

Regards,

Phil.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]