[RFT 2/4] net/mlx5: fix counter leak in hairpin queue setup

Stephen Hemminger
2026-02-17T15:06:58Z

When rxq_obj_modify_counter_set_id() fails in
mlx5_enable_per_queue_hairpin_counter(), the freshly allocated DevX
queue counter object is not destroyed before returning. Destroy it
on the error path.

Fixes: f0c0731b6d40 ("net/mlx5: add counters for hairpin drop")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/mlx5/mlx5.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 4d3bfddc36..d533ce41e1 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -3704,6 +3704,8 @@ mlx5_enable_per_queue_hairpin_counter(struct rte_eth_dev *dev, uint64_t id)
if (ret) {
DRV_LOG(ERR, "failed to modify rq object for port %u"
"%s", priv->dev_data->port_id, strerror(rte_errno));
+ mlx5_devx_cmd_destroy(rxq->q_counter);
+ rxq->q_counter = NULL;
return ret;
}

--
2.51.0