* [PATCH] rocker: Fix memory leak in ofdpa_port_fdb()
@ 2026-06-16 1:32 Ziran Zhang
2026-06-16 23:29 ` Jacob Keller
0 siblings, 1 reply; 3+ messages in thread
From: Ziran Zhang @ 2026-06-16 1:32 UTC (permalink / raw)
To: Jiri Pirko, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Ziran Zhang, netdev, linux-kernel
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.
Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
drivers/net/ethernet/rocker/rocker_ofdpa.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c
index 66a8ae67c..15d19a8a1 100644
--- a/drivers/net/ethernet/rocker/rocker_ofdpa.c
+++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c
@@ -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);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rocker: Fix memory leak in ofdpa_port_fdb()
2026-06-16 1:32 [PATCH] rocker: Fix memory leak in ofdpa_port_fdb() Ziran Zhang
@ 2026-06-16 23:29 ` Jacob Keller
2026-06-17 1:37 ` Ziran Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Jacob Keller @ 2026-06-16 23:29 UTC (permalink / raw)
To: Ziran Zhang, Jiri Pirko, Andrew Lunn, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel
On 6/15/2026 6:32 PM, Ziran Zhang wrote:
> 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.
>
> Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
> ---
> drivers/net/ethernet/rocker/rocker_ofdpa.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c
> index 66a8ae67c..15d19a8a1 100644
> --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c
> +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c
> @@ -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.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rocker: Fix memory leak in ofdpa_port_fdb()
2026-06-16 23:29 ` Jacob Keller
@ 2026-06-17 1:37 ` Ziran Zhang
0 siblings, 0 replies; 3+ messages in thread
From: Ziran Zhang @ 2026-06-17 1:37 UTC (permalink / raw)
To: Jacob Keller, Jiri Pirko, Andrew Lunn, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Ziran Zhang
On Tue, 16 Jun 2026 16:29:59 -0700, Jacob Keller wrote:
> 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.
>
> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
I don't have Rocker hardware to test the suggestion.
Thanks for the review!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-17 1:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 1:32 [PATCH] rocker: Fix memory leak in ofdpa_port_fdb() Ziran Zhang
2026-06-16 23:29 ` Jacob Keller
2026-06-17 1:37 ` Ziran Zhang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.