Re: [PATCH net] net: dsa: realtek: fix memory leak in rtl8366rb_setup_led()
From: David Yang
Date: Thu Jun 18 2026 - 16:53:24 EST
On Fri, Jun 19, 2026 at 4:12 AM Luiz Angelo Daros de Luca
<luizluca@xxxxxxxxx> wrote:
> Indeed, it will leak. init_data is local and init_data.devicename is
> read by led_compose_name, not stored. However, stack is a limited
> space for allocation.
I've checked the buffer is long enough to hold the name string while
relatively small (only 64B), so it should be safe for the stack.
> You can alternatively solve the leak using devm_kasprintf() (my
> choice) or adding a kfree() before leaving the function.
devm_kasprintf() still makes the memory unused (later in the driver)
and unusable (since normally you won't unload the switch driver until
shutdown), IMO.