The pool name is a small fixed string, but it was allocated separately
and the pointer was stored in the pool config. Destroy always freed
that pointer. The create error path freed it again, which logged
"Invalid memory".
Keep the name in the pool config. The string is copied with the config,
so create and destroy no longer allocate or free it.
Fixes: 9e34fcc81c00 ("net/mlx5: fix leak in HWS flow counter action")
Cc: [email protected]
Signed-off-by: Maayan Kashani <[email protected]>
Acked-by: Dariusz Sosnowski <[email protected]>
---
drivers/net/mlx5/mlx5_hws_cnt.c | 13 ++-----------
drivers/net/mlx5/mlx5_hws_cnt.h | 3 ++-
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index d0c4ead71b7..d6f713fd9bd 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -730,18 +730,11 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
struct mlx5_priv *priv = dev->data->dev_private;
struct mlx5_hws_cache_param cparam = {0};
struct mlx5_hws_cnt_pool_cfg pcfg = {0};
- char *mp_name;
int ret = 0;
size_t sz;
- mp_name = mlx5_malloc(MLX5_MEM_ZERO, RTE_MEMZONE_NAMESIZE, 0,
SOCKET_ID_ANY);
- if (mp_name == NULL) {
- ret = rte_flow_error_set(error, ENOMEM,
RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "failed to allocate counter pool name
prefix");
- goto error;
- }
- snprintf(mp_name, RTE_MEMZONE_NAMESIZE, "MLX5_HWS_CNT_P_%x",
dev->data->port_id);
- pcfg.name = mp_name;
+ snprintf(pcfg.name, sizeof(pcfg.name), "MLX5_HWS_CNT_P_%x",
+ dev->data->port_id);
pcfg.request_num = nb_counters;
pcfg.alloc_factor = HWS_CNT_ALLOC_FACTOR_DEFAULT;
if (chost) {
@@ -814,7 +807,6 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
MLX5_ASSERT(ret);
mlx5_hws_cnt_pool_destroy(priv->sh, cpool);
priv->hws_cpool = NULL;
- mlx5_free(mp_name);
return ret;
}
@@ -842,7 +834,6 @@ mlx5_hws_cnt_pool_destroy(struct mlx5_dev_ctx_shared *sh,
mlx5_hws_cnt_pool_dcs_free(cpool);
mlx5_hws_cnt_raw_data_free(cpool->raw_mng);
}
- mlx5_free((void *)cpool->cfg.name);
mlx5_hws_cnt_pool_deinit(cpool);
}
diff --git a/drivers/net/mlx5/mlx5_hws_cnt.h b/drivers/net/mlx5/mlx5_hws_cnt.h
index 63a14f4f7a0..5a55820abec 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.h
+++ b/drivers/net/mlx5/mlx5_hws_cnt.h
@@ -5,6 +5,7 @@
#ifndef _MLX5_HWS_CNT_H_
#define _MLX5_HWS_CNT_H_
+#include <rte_memzone.h>
#include <rte_ring.h>
#include "mlx5_utils.h"
#include "mlx5_flow.h"
@@ -87,7 +88,7 @@ struct mlx5_hws_cache_param {
};
struct mlx5_hws_cnt_pool_cfg {
- char *name;
+ char name[RTE_MEMZONE_NAMESIZE];
uint32_t request_num;
uint32_t alloc_factor;
struct mlx5_hws_cnt_pool *host_cpool;
--
2.25.1