Skip to contentSkip to conversation

net/mlx5: fix incorrect buddy mempool init

PATCH In review Bing Zhao 2 participants 2 messages Nov 12, 2025 Network drivers

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

PATCH 3/4 net/mlx5: fix incorrect buddy mempool init

From: Nupur Uttarwar <[email protected]>

buddy was erroroneously declared as static. When multiple threads call this routine, they set the same static variable corrupting pool data and can cause potential double free when releasing resources.

Fixes b4dd7bcb0dcb ("net/mlx5/hws: add pool and buddy")
---
 drivers/net/mlx5/hws/mlx5dr_buddy.c | 1 +
 drivers/net/mlx5/hws/mlx5dr_pool.c  | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_buddy.c +1 -0
index 394ca71217..abfbdf1be5 100644
@@ -147,6 +147,7 @@ void mlx5dr_buddy_cleanup(struct mlx5dr_buddy_mem *buddy)
 
 	simple_free(buddy->num_free);
 	simple_free(buddy->bits);
+	simple_free(buddy);
 }
 
 int mlx5dr_buddy_alloc_mem(struct mlx5dr_buddy_mem *buddy, int order)
drivers/net/mlx5/hws/mlx5dr_pool.c +1 -2
index 8e3718ac42..e383027d3e 100644
@@ -167,7 +167,7 @@ static struct mlx5dr_buddy_mem *
 mlx5dr_pool_buddy_get_next_buddy(struct mlx5dr_pool *pool, int idx,
 				 uint32_t order, bool *is_new_buddy)
 {
-	static struct mlx5dr_buddy_mem *buddy;
+	struct mlx5dr_buddy_mem *buddy;
 	uint32_t new_buddy_size;
 
 	buddy = pool->db.buddy_manager->buddies[idx];
@@ -271,7 +271,6 @@ static void mlx5dr_pool_buddy_db_uninit(struct mlx5dr_pool *pool)
 		buddy = pool->db.buddy_manager->buddies[i];
 		if (buddy) {
 			mlx5dr_buddy_cleanup(buddy);
-			simple_free(buddy);
 			pool->db.buddy_manager->buddies[i] = NULL;
 		}
 	}
Signature · 1 line
2.34.1