net: mvpp2: cls: Fix memory leak in mvpp2_ethtool_cls_rule_ins()
Subsystems (3)
PATCH v2 1/1 net: mvpp2: cls: Fix memory leak in mvpp2_ethtool_cls_rule_ins()
In mvpp2_ethtool_cls_rule_ins(), the ethtool_rule is allocated by ethtool_rx_flow_rule_create(). If the subsequent conversion to flow type fails, the function jumps to the clean_rule label.
However, the clean_rule label only frees efs, skipping the cleanup of ethtool_rule, which leads to a memory leak.
Fix this by jumping to the clean_eth_rule label, which properly calls ethtool_rx_flow_rule_destroy() before freeing efs.
Compile tested only. Issue found using a prototype static analysis tool and code review.
---
Changes in v2:
- Cc the author of the commit under Fixes.
drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c +1 -1
@@ -1389,7 +1389,7 @@ int mvpp2_ethtool_cls_rule_ins(struct mvpp2_port *port, efs->rule.flow_type =mvpp2_cls_ethtool_flow_to_type (info->fs.flow_type);if (efs->rule.flow_type <0 ) { ret = efs->rule.flow_type; - goto clean_rule; + goto clean_eth_rule; } ret =mvpp2_cls_rfs_parse_rule (&efs->rule);
Signature · 1 line
2.34.1
Hi,
Quoted 4 lines · Zilin Guan
In
mvpp2_ethtool_cls_rule_ins(), theethtool_ruleis allocated byethtool_rx_flow_rule_create(). If the subsequent conversion to flow type fails, the function jumps to theclean_rulelabel.
Quoted 8 lines
However, the
clean_rulelabel only frees efs, skipping the cleanup ofethtool_rule, which leads to a memory leak.Fix this by jumping to the
clean_eth_rulelabel, which properly callsethtool_rx_flow_rule_destroy()before freeing efs.Compile tested only. Issue found using a prototype static analysis tool and code review.
Thanks for clarifying how you found that
Quoted 3 lines
Fixes f4f1ba18195d ("net: mvpp2: cls: Report an error for unsupported flow types")Signed-off-by Zilin Guan <[email protected]>
Change is fine, thanks for fixing this.
Maxime
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 8 lines · On Fri, 23 Jan 2026 06:57:16 +0000 you wrote:
In
mvpp2_ethtool_cls_rule_ins(), theethtool_ruleis allocated byethtool_rx_flow_rule_create(). If the subsequent conversion to flow type fails, the function jumps to theclean_rulelabel.However, the
clean_rulelabel only frees efs, skipping the cleanup ofethtool_rule, which leads to a memory leak.[...]
Here is the summary with links:
- [net,v2] net: mvpp2: cls: Fix memory leak in mvpp2_ethtool_cls_rule_ins()
https://git.kernel.org/netdev/net/c/09f979d1f312
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html