netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats()
@ 2025-11-12  5:21 Zilin Guan
  2025-11-12  7:35 ` Ido Schimmel
  2025-11-14  1:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Zilin Guan @ 2025-11-12  5:21 UTC (permalink / raw)
  To: idosch
  Cc: petrm, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, jianhao.xu, Zilin Guan

The function mlxsw_sp_flower_stats() calls mlxsw_sp_acl_ruleset_get() to
obtain a ruleset reference. If the subsequent call to
mlxsw_sp_acl_rule_lookup() fails to find a rule, the function returns
an error without releasing the ruleset reference, causing a memory leak.

Fix this by using a goto to the existing error handling label, which
calls mlxsw_sp_acl_ruleset_put() to properly release the reference.

Fixes: 7c1b8eb175b69 ("mlxsw: spectrum: Add support for TC flower offload statistics")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index 6a4a81c63451..353fd9ca89a6 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -830,8 +830,10 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
 		return -EINVAL;
 
 	rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
-	if (!rule)
-		return -EINVAL;
+	if (!rule) {
+		err = -EINVAL;
+		goto err_rule_get_stats;
+	}
 
 	err = mlxsw_sp_acl_rule_get_stats(mlxsw_sp, rule, &packets, &bytes,
 					  &drops, &lastuse, &used_hw_stats);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats()
  2025-11-12  5:21 [PATCH] mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats() Zilin Guan
@ 2025-11-12  7:35 ` Ido Schimmel
  2025-11-14  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2025-11-12  7:35 UTC (permalink / raw)
  To: Zilin Guan
  Cc: petrm, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, jianhao.xu

On Wed, Nov 12, 2025 at 05:21:14AM +0000, Zilin Guan wrote:
> The function mlxsw_sp_flower_stats() calls mlxsw_sp_acl_ruleset_get() to
> obtain a ruleset reference. If the subsequent call to
> mlxsw_sp_acl_rule_lookup() fails to find a rule, the function returns
> an error without releasing the ruleset reference, causing a memory leak.
> 
> Fix this by using a goto to the existing error handling label, which
> calls mlxsw_sp_acl_ruleset_put() to properly release the reference.
> 
> Fixes: 7c1b8eb175b69 ("mlxsw: spectrum: Add support for TC flower offload statistics")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

Subject prefix should be "[PATCH net]". See [1] for next time.

Thanks

[1] https://docs.kernel.org/process/maintainer-netdev.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats()
  2025-11-12  5:21 [PATCH] mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats() Zilin Guan
  2025-11-12  7:35 ` Ido Schimmel
@ 2025-11-14  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-14  1:40 UTC (permalink / raw)
  To: Zilin Guan
  Cc: idosch, petrm, andrew+netdev, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, jianhao.xu

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 12 Nov 2025 05:21:14 +0000 you wrote:
> The function mlxsw_sp_flower_stats() calls mlxsw_sp_acl_ruleset_get() to
> obtain a ruleset reference. If the subsequent call to
> mlxsw_sp_acl_rule_lookup() fails to find a rule, the function returns
> an error without releasing the ruleset reference, causing a memory leak.
> 
> Fix this by using a goto to the existing error handling label, which
> calls mlxsw_sp_acl_ruleset_put() to properly release the reference.
> 
> [...]

Here is the summary with links:
  - mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats()
    https://git.kernel.org/netdev/net/c/407a06507c23

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:[~2025-11-14  1:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12  5:21 [PATCH] mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats() Zilin Guan
2025-11-12  7:35 ` Ido Schimmel
2025-11-14  1: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;
as well as URLs for NNTP newsgroup(s).