rocker: fix memory leak in rocker_world_port_post_fini()
Subsystems (3)
PATCH 1/1 rocker: fix memory leak in rocker_world_port_post_fini()
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.
--- drivers/net/ethernet/rocker/rocker_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/rocker/rocker_main.c +2 -3
@@ -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); }
Signature · 1 line
2.34.1
Quoted 15 lines · Kery Qi
In
rocker_world_port_pre_init(),rocker_port->wprivis allocated withkzalloc(wops->port_priv_size, GFP_KERNEL). However, inrocker_world_port_post_fini(), the memory is only freed whenwops->port_post_finicallback is set:if (!wops->port_post_fini) return; wops->port_post_fini(rocker_port); kfree(rocker_port->wpriv);Since
rocker_ofdpa_opsdoes not implementport_post_finicallback (it is NULL), the wpriv memory allocated for each port is never freed when ports are removed. This leads to a memory leak ofsizeof(struct ofdpa_port)bytes per port on every device removal.
Quoted 5 lines
Fix this by always calling
kfree(rocker_port->wpriv)regardless of whether theport_post_finicallback exists.Fixes e420114eef4a ("rocker: introduce worlds infrastructure")Signed-off-by Kery Qi <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Sat, 24 Jan 2026 05:10:31 +0800 you wrote:
In
rocker_world_port_pre_init(),rocker_port->wprivis allocated withkzalloc(wops->port_priv_size, GFP_KERNEL). However, inrocker_world_port_post_fini(), the memory is only freed whenwops->port_post_finicallback 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html