* [PATCH] rocker: fix memory leak in rocker_world_port_post_fini()
@ 2026-01-23 21:10 Kery Qi
2026-01-26 15:30 ` Simon Horman
2026-01-27 3:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Kery Qi @ 2026-01-23 21:10 UTC (permalink / raw)
To: jiri, andrew+netdev, davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Kery Qi
In rocker_world_port_pre_init(), rocker_port->wpriv is allocated with
kzalloc(wops->port_priv_size, GFP_KERNEL). However, in
rocker_world_port_post_fini(), the memory is only freed when
wops->port_post_fini callback is set:
if (!wops->port_post_fini)
return;
wops->port_post_fini(rocker_port);
kfree(rocker_port->wpriv);
Since rocker_ofdpa_ops does not implement port_post_fini callback
(it is NULL), the wpriv memory allocated for each port is never freed
when ports are removed. This leads to a memory leak of
sizeof(struct ofdpa_port) bytes per port on every device removal.
Fix this by always calling kfree(rocker_port->wpriv) regardless of
whether the port_post_fini callback exists.
Fixes: e420114eef4a ("rocker: introduce worlds infrastructure")
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
drivers/net/ethernet/rocker/rocker_main.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c
index 36af94a2e062..2794f75df8fc 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1524,9 +1524,8 @@ static void rocker_world_port_post_fini(struct rocker_port *rocker_port)
{
struct rocker_world_ops *wops = rocker_port->rocker->wops;
- if (!wops->port_post_fini)
- return;
- wops->port_post_fini(rocker_port);
+ if (wops->port_post_fini)
+ wops->port_post_fini(rocker_port);
kfree(rocker_port->wpriv);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] rocker: fix memory leak in rocker_world_port_post_fini()
2026-01-23 21:10 [PATCH] rocker: fix memory leak in rocker_world_port_post_fini() Kery Qi
@ 2026-01-26 15:30 ` Simon Horman
2026-01-27 3:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2026-01-26 15:30 UTC (permalink / raw)
To: Kery Qi
Cc: jiri, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel
On Sat, Jan 24, 2026 at 05:10:31AM +0800, Kery Qi wrote:
> In rocker_world_port_pre_init(), rocker_port->wpriv is allocated with
> kzalloc(wops->port_priv_size, GFP_KERNEL). However, in
> rocker_world_port_post_fini(), the memory is only freed when
> wops->port_post_fini callback is set:
>
> if (!wops->port_post_fini)
> return;
> wops->port_post_fini(rocker_port);
> kfree(rocker_port->wpriv);
>
> Since rocker_ofdpa_ops does not implement port_post_fini callback
> (it is NULL), the wpriv memory allocated for each port is never freed
> when ports are removed. This leads to a memory leak of
> sizeof(struct ofdpa_port) bytes per port on every device removal.
>
> Fix this by always calling kfree(rocker_port->wpriv) regardless of
> whether the port_post_fini callback exists.
>
> Fixes: e420114eef4a ("rocker: introduce worlds infrastructure")
> Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rocker: fix memory leak in rocker_world_port_post_fini()
2026-01-23 21:10 [PATCH] rocker: fix memory leak in rocker_world_port_post_fini() Kery Qi
2026-01-26 15:30 ` Simon Horman
@ 2026-01-27 3:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-27 3:40 UTC (permalink / raw)
To: Kery Qi
Cc: jiri, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 24 Jan 2026 05:10:31 +0800 you wrote:
> In rocker_world_port_pre_init(), rocker_port->wpriv is allocated with
> kzalloc(wops->port_priv_size, GFP_KERNEL). However, in
> rocker_world_port_post_fini(), the memory is only freed when
> wops->port_post_fini callback is set:
>
> if (!wops->port_post_fini)
> return;
> wops->port_post_fini(rocker_port);
> kfree(rocker_port->wpriv);
>
> [...]
Here is the summary with links:
- rocker: fix memory leak in rocker_world_port_post_fini()
https://git.kernel.org/netdev/net/c/8d7ba71e4621
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-27 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-23 21:10 [PATCH] rocker: fix memory leak in rocker_world_port_post_fini() Kery Qi
2026-01-26 15:30 ` Simon Horman
2026-01-27 3:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox