Commit b7f0ee9
net: phy: leds: fix memory leak
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.
This also prevents kmemleak from detecting the leak, as the devm API
internally stores the allocated pointer.
Fix this by replacing devm_kzalloc/devm_kcalloc with standard
kzalloc/kcalloc, and add the corresponding kfree calls in the unregister
path.
Fixes: 3928ee6 ("net: phy: leds: Add support for "link" trigger")
Fixes: 2e0bc45 ("net: phy: leds: add support for led triggers on phy link state change")
Signed-off-by: Hao Guan <hao.guan@siflower.com.cn>
Signed-off-by: Qingfang Deng <qingfang.deng@siflower.com.cn>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20250417032557.2929427-1-dqfext@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>1 parent ce68155 commit b7f0ee9
1 file changed
+13
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 96 | + | |
| 97 | + | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| |||
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
112 | 110 | | |
113 | 111 | | |
114 | 112 | | |
| |||
129 | 127 | | |
130 | 128 | | |
131 | 129 | | |
132 | | - | |
| 130 | + | |
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
136 | | - | |
| 134 | + | |
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
| |||
147 | 145 | | |
148 | 146 | | |
149 | 147 | | |
| 148 | + | |
| 149 | + | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
153 | 156 | | |
154 | 157 | | |
0 commit comments