During counter pool initialization (mlx5_hws_cnt_pool_create()), a background service thread is started by mlx5 PMD, which refreshes counter values periodically.
During initialization it might happen that: - background thread creation succeeds, - pool creation fails (e.g. due to error in configuration provided by the user). In this case, the procedure on error rollback will not clean up counter service thread, because rollback assumes that is there is no pool, then there is nothing to clean up. This patch fixes that, by moving background thread creation to the end of counter pool initialization. This ensures proper order of resource release during rollback. Also, this patch adds missing "goto error" in case of failure to initialize the service thread. Fixes: 4d368e1da3a4 ("net/mlx5: support flow counter action for HWS") Cc: jack...@nvidia.com Cc: sta...@dpdk.org Signed-off-by: Dariusz Sosnowski <dsosnow...@nvidia.com> Acked-by: Bing Zhao <bi...@nvidia.com> --- drivers/net/mlx5/mlx5_hws_cnt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c index fd12bcd7ec..5c7c0041aa 100644 --- a/drivers/net/mlx5/mlx5_hws_cnt.c +++ b/drivers/net/mlx5/mlx5_hws_cnt.c @@ -729,12 +729,6 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev, } goto success; } - /* init cnt service if not. */ - if (priv->sh->cnt_svc == NULL) { - ret = mlx5_hws_cnt_svc_init(priv->sh, error); - if (ret) - goto error; - } cparam.fetch_sz = HWS_CNT_CACHE_FETCH_DEFAULT; cparam.preload_sz = HWS_CNT_CACHE_PRELOAD_DEFAULT; cparam.q_num = nb_queue; @@ -769,6 +763,12 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev, NULL, "failed to allocate counter actions"); goto error; } + /* init cnt service if not. */ + if (priv->sh->cnt_svc == NULL) { + ret = mlx5_hws_cnt_svc_init(priv->sh, error); + if (ret) + goto error; + } priv->sh->cnt_svc->refcnt++; cpool->priv = priv; rte_spinlock_lock(&priv->sh->cpool_lock); -- 2.39.5