Skip to contentSkip to conversation

net/mlx5: fix segfault in counter pool destroy

PATCH Applied Maayan Kashani 2 participants 2 messages Jun 25, 2025 – Jun 26, 2025 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: fix segfault in counter pool destroy

When there is not enough memory, counter pool creation fails. As a result, the pool is being destroyed.
Since not all pointers were initialized during creation, Need to check for null pointer in destruction.

Fixes 13ea6bdcc7ee ("net/mlx5: support counters in cross port shared mode")
---
 drivers/net/mlx5/mlx5_hws_cnt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx5/mlx5_hws_cnt.c +1 -1
index 83db242bf90..fce7a7e815f 100644
@@ -810,7 +810,7 @@ mlx5_hws_cnt_pool_destroy(struct mlx5_dev_ctx_shared *sh,
 		LIST_REMOVE(cpool, next);
 	rte_spinlock_unlock(&sh->cpool_lock);
 	if (cpool->cfg.host_cpool == NULL) {
-		if (--sh->cnt_svc->refcnt == 0)
+		if (sh->cnt_svc && --sh->cnt_svc->refcnt == 0)
 			mlx5_hws_cnt_svc_deinit(sh);
 	}
 	mlx5_hws_cnt_pool_action_destroy(cpool);
Signature · 1 line
2.21.0
#1 lore raw

25/06/2025 11:32, Maayan Kashani:

Quoted 14 lines

When there is not enough memory, counter pool creation fails. As a result, the pool is being destroyed.
Since not all pointers were initialized during creation, Need to check for null pointer in destruction.

Fixes 13ea6bdcc7ee ("net/mlx5: support counters in cross port shared mode")

---

drivers/net/mlx5/mlx5_hws_cnt.c mlx5_hws_cnt_pool_destroy(struct mlx5_dev_ctx_shared *sh, · line 814

Quoted 6 lines
drivers/net/mlx5/mlx5_hws_cnt.c +1 -1
@@ -810,7 +810,7 @@ mlx5_hws_cnt_pool_destroy(struct mlx5_dev_ctx_shared *sh,
 		LIST_REMOVE(cpool, next);
 	rte_spinlock_unlock(&sh->cpool_lock);
 	if (cpool->cfg.host_cpool == NULL) {
-		if (--sh->cnt_svc->refcnt == 0)
+		if (sh->cnt_svc && --sh->cnt_svc->refcnt == 0)
 			mlx5_hws_cnt_svc_deinit(sh);

Applied, thanks.