Skip to content

Commit c4d6c59

Browse files
GoodLuck612Ulrich Hecht
authored andcommitted
mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats()
[ Upstream commit 407a06507c2358554958e8164dc97176feddcafc ] 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: 7c1b8eb ("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> Link: https://patch.msgid.link/20251112052114.1591695-1-zilin@seu.edu.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent b4643c0 commit c4d6c59

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,10 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
480480
return -EINVAL;
481481

482482
rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
483-
if (!rule)
484-
return -EINVAL;
483+
if (!rule) {
484+
err = -EINVAL;
485+
goto err_rule_get_stats;
486+
}
485487

486488
err = mlxsw_sp_acl_rule_get_stats(mlxsw_sp, rule, &packets, &bytes,
487489
&lastuse);

0 commit comments

Comments
 (0)