Skip to contentSkip to conversation

mlxsw: spectrum_router: destroy FIB hash table on bind failure

PATCH Applied Sang-Hoon Choi 4 participants 4 messages Oct 2 – Oct 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlxsw: spectrum_router: destroy FIB hash table on bind failure

mlxsw_sp_fib_create() initializes fib->ht before binding the LPM tree. If the bind fails, the error path releases the tree and frees fib without destroying the initialized hash table, leaking its bucket allocation.

Destroy fib->ht on the post-initialization failure path.

Fixes 2b52ce02e1d1 ("mlxsw: spectrum_router: Remove unnecessary prefix lengths from LPM tree")
Assisted-by LLM

---
Compile-tested the affected object with x86_64 allmodconfig
and W=1 (GCC 13.3.0). Base: mainline 3b7cab693ba2bab63774bf5b988e8a61b2ef0f32. No hardware testing or runtime failure reproduction was performed.

 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 -0
index 3d6fdbab05e0..456c60b9be17 100644
@@ -556,6 +556,7 @@ static struct mlxsw_sp_fib *mlxsw_sp_fib_create(struct mlxsw_sp *mlxsw_sp,
 
 err_lpm_tree_bind:
 	mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree);
+	rhashtable_destroy(&fib->ht);
 err_rhashtable_init:
 	kfree(fib);
 	return ERR_PTR(err);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Sang-Hoon Choi

mlxsw_sp_fib_create() initializes fib->ht before binding the LPM tree. If the bind fails, the error path releases the tree and frees fib without destroying the initialized hash table, leaking its bucket allocation.

Destroy fib->ht on the post-initialization failure path.

Fixes 2b52ce02e1d1 ("mlxsw: spectrum_router: Remove unnecessary prefix lengths from LPM tree")
Assisted-by LLM

---
Compile-tested the affected object with x86_64 allmodconfig
and W=1 (GCC 13.3.0). Base: mainline 3b7cab693ba2bab63774bf5b988e8a61b2ef0f32. No hardware testing or runtime failure reproduction was performed.

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 1 +

1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +0 -0
index 3d6fdbab05e0..456c60b9be17 100644
@@ -556,6 +556,7 @@ static struct mlxsw_sp_fib *mlxsw_sp_fib_create(struct mlxsw_sp *mlxsw_sp,
 

err_lpm_tree_bind:

	mlxsw_sp_lpm_tree_put(mlxsw_sp, lpm_tree);
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 -0
+	rhashtable_destroy(&fib->ht);

err_rhashtable_init:

Quoted 3 lines
	kfree(fib);
	return ERR_PTR(err);
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Sang-Hoon Choi
Quoted 10 lines · Sang-Hoon Choi

mlxsw_sp_fib_create() initializes fib->ht before binding the LPM tree. If the bind fails, the error path releases the tree and frees fib without destroying the initialized hash table, leaking its bucket allocation.

Destroy fib->ht on the post-initialization failure path.

Fixes 2b52ce02e1d1 ("mlxsw: spectrum_router: Remove unnecessary prefix lengths from LPM tree")
Assisted-by LLM
#3 lore raw
In reply to Sang-Hoon Choi
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 4 lines · On Fri, 02 Oct 2026 19:47:40 +0000 you wrote:

mlxsw_sp_fib_create() initializes fib->ht before binding the LPM tree. If the bind fails, the error path releases the tree and frees fib without destroying the initialized hash table, leaking its bucket allocation.

Quoted 8 lines

Destroy fib->ht on the post-initialization failure path.

Fixes 2b52ce02e1d1 ("mlxsw: spectrum_router: Remove unnecessary prefix lengths from LPM tree")
Assisted-by LLM

[...]

Here is the summary with links:
- [net] mlxsw: spectrum_router: destroy FIB hash table on bind failure

    https://git.kernel.org/netdev/net-next/c/a089139eb47b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html