Re: [PATCH net] net: phy: leds: fix memory leak

From: Maxime Chevallier
Date: Thu Apr 17 2025 - 03:38:53 EST


On Thu, 17 Apr 2025 11:25:56 +0800
Qingfang Deng <dqfext@xxxxxxxxx> wrote:

> From: Qingfang Deng <qingfang.deng@xxxxxxxxxxxxxxx>
>
> A network restart test on a router led to an out-of-memory condition,
> which was traced to a memory leak in the PHY LED trigger code.
>
> The root cause is misuse of the devm API. The registration function
> (phy_led_triggers_register) is called from phy_attach_direct, not
> phy_probe, and the unregister function (phy_led_triggers_unregister)
> is called from phy_detach, not phy_remove. This means the register and
> unregister functions can be called multiple times for the same PHY
> device, but devm-allocated memory is not freed until the driver is
> unbound.

Are there historical reasons for the triggers not to be registered at
probe time ? I agree with your analysis otherwise.

Maxime