rocker: Fix memory leak in ofdpa_port_fdb()
Subsystems (3)
PATCH 1/1 rocker: Fix memory leak in ofdpa_port_fdb()
In ofdpa_port_fdb(), the hash_del() only unlinks the node from hash table, but does not free it.
Fix this by adding kfree(found) after the !found == removing check, where the pointer value is no longer needed.
Found by Coccinelle kfree script.
--- drivers/net/ethernet/rocker/rocker_ofdpa.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/rocker/rocker_ofdpa.c +3 -0
@@ -1924,6 +1924,9 @@ static int ofdpa_port_fdb(struct ofdpa_port *ofdpa_port, flags |=OFDPA_OP_FLAG_REFRESH ; } +if (found && removing) +kfree (found); +return ofdpa_port_fdb_learn (ofdpa_port, flags, addr, vlan_id); }
Signature · 1 line
2.43.0
Quoted 18 lines · Ziran Zhang
In
ofdpa_port_fdb(), thehash_del()only unlinks the node from hash table, but does not free it.Fix this by adding kfree(found) after the !found == removing check, where the pointer value is no longer needed.
Found by Coccinelle kfree script.
Signed-off-by Ziran Zhang <[email protected]>--- drivers/net/ethernet/rocker/rocker_ofdpa.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/ethernet/rocker/rocker_ofdpa.c +0
-0
drivers/net/ethernet/rocker/rocker_ofdpa.c static int ofdpa_port_fdb(struct ofdpa_port *ofdpa_port, · line 1932
Quoted 9 lines
drivers/net/ethernet/rocker/rocker_ofdpa.c +3
-0@@ -1924,6 +1924,9 @@ static int ofdpa_port_fdb(struct ofdpa_port *ofdpa_port, flags |=OFDPA_OP_FLAG_REFRESH ; } +if (found && removing) +kfree (found); +return ofdpa_port_fdb_learn (ofdpa_port, flags, addr, vlan_id); }
I looked at the surrounding code and I can't find any other place that would have released the found entry, so this does indeed look like a memory leak.
You could potentially verify it using the slab allocator stats and setting up a test where you add and remove port fdb in succession and see if the allocation of the correct size continue to grow.
This whole flow is somewhat confusing by combining both the add and remove into a single functional flow. I guess it is intended to reduce code duplication but it sure makes the processes difficult to follow.
I suspect the original code mistook freeing the searched entry as freeing the found entry.
Quoted 8 lines · Jacob Keller
I looked at the surrounding code and I can't find any other place that would have released the found entry, so this does indeed look like a memory leak.
You could potentially verify it using the slab allocator stats and setting up a test where you add and remove port fdb in succession and see if the allocation of the correct size continue to grow.
Quoted 8 lines
This whole flow is somewhat confusing by combining both the add and remove into a single functional flow. I guess it is intended to reduce code duplication but it sure makes the processes difficult to follow.
I suspect the original code mistook freeing the searched entry as freeing the found entry.
Reviewed-by Jacob Keller <[email protected]>
I don't have Rocker hardware to test the suggestion.
Thanks for the review!
Quoted 9 lines · Jacob Keller
Quoted 8 lines · Ziran Zhang
In
ofdpa_port_fdb(), thehash_del()only unlinks the node from hash table, but does not free it.Fix this by adding kfree(found) after the !found == removing check, where the pointer value is no longer needed.
Found by Coccinelle kfree script.
Is rocker actually used any more? I'm not too sure of the history, but was it not added as a way to develop the early switchdev code? There was a qemu implementation of the 'hardware'?
Is it still useful? Should we actually just remove the driver?
Andrew
Jakub Kicinski
maintainerQuoted 8 lines · On Wed, 17 Jun 2026 11:26:46 +0200 Andrew Lunn wrote:
Quoted 7 lines · Jacob Keller
Quoted 6 lines · Ziran Zhang
In
ofdpa_port_fdb(), thehash_del()only unlinks the node from hash table, but does not free it.Fix this by adding kfree(found) after the !found == removing check, where the pointer value is no longer needed.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Found by Coccinelle kfree script.
Is rocker actually used any more? I'm not too sure of the history, but was it not added as a way to develop the early switchdev code? There was a qemu implementation of the 'hardware'?
Is it still useful? Should we actually just remove the driver?
I think it came up before but I don't remember the conclusion :S We should either add rocker to NIPA or delete it. Jiri, WDYT?
Jiri Pirko
maintainerQuoted 11 lines · Thu, Jun 18, 2026 at 01:44:11AM +0200, [email protected] wrote:
Quoted 10 lines · On Wed, 17 Jun 2026 11:26:46 +0200 Andrew Lunn wrote:
Quoted 8 lines · Jacob Keller
Quoted 7 lines · Ziran Zhang
In
ofdpa_port_fdb(), thehash_del()only unlinks the node from hash table, but does not free it.Fix this by adding kfree(found) after the !found == removing check, where the pointer value is no longer needed.
Found by Coccinelle kfree script.
Quoted 8 lines
Quoted 5 lines
Is rocker actually used any more? I'm not too sure of the history, but was it not added as a way to develop the early switchdev code? There was a qemu implementation of the 'hardware'?
Is it still useful? Should we actually just remove the driver?
I think it came up before but I don't remember the conclusion :S We should either add rocker to NIPA or delete it. Jiri, WDYT?
Remove.
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 9 lines · On Tue, 16 Jun 2026 09:32:45 +0800 you wrote:
In
ofdpa_port_fdb(), thehash_del()only unlinks the node from hash table, but does not free it.Fix this by adding kfree(found) after the !found == removing check, where the pointer value is no longer needed.
Found by Coccinelle kfree script.
[...]
Here is the summary with links:
- rocker: Fix memory leak in ofdpa_port_fdb()
https://git.kernel.org/netdev/net/c/53442aad1d57
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html