Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats()

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>
Link: https://patch.msgid.link/20251112052114.1591695-1-zilin@seu.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Zilin Guan and committed by
Jakub Kicinski
407a0650 f796a8de

+4 -2
+4 -2
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
··· 830 830 return -EINVAL; 831 831 832 832 rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie); 833 - if (!rule) 834 - return -EINVAL; 833 + if (!rule) { 834 + err = -EINVAL; 835 + goto err_rule_get_stats; 836 + } 835 837 836 838 err = mlxsw_sp_acl_rule_get_stats(mlxsw_sp, rule, &packets, &bytes, 837 839 &drops, &lastuse, &used_hw_stats);