In case of an error in mlx5_hws_cnt_pool_create(),
value stored in ret is used as "error code".
There are however a few cases inside this function,
when this variable is not set, leading to failed
assertions (e.g., when requested number of counters is bigger
than maximum supported).

This patch addresses these cases, by propagating the rte_errno
set by failing functions.

Fixes: e1c83d295dd9 ("net/mlx5: support ASO actions with non-template flow")
Cc: mkash...@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 | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c
index 7b5e7310af..fd12bcd7ec 100644
--- a/drivers/net/mlx5/mlx5_hws_cnt.c
+++ b/drivers/net/mlx5/mlx5_hws_cnt.c
@@ -704,8 +704,11 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
        size_t sz;
 
        mp_name = mlx5_malloc(MLX5_MEM_ZERO, RTE_MEMZONE_NAMESIZE, 0, 
SOCKET_ID_ANY);
-       if (mp_name == NULL)
+       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;
        pcfg.request_num = nb_counters;
@@ -713,8 +716,10 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
        if (chost) {
                pcfg.host_cpool = chost;
                cpool = mlx5_hws_cnt_pool_init(priv->sh, &pcfg, &cparam, error);
-               if (cpool == NULL)
+               if (cpool == NULL) {
+                       ret = -rte_errno;
                        goto error;
+               }
                ret = mlx5_hws_cnt_pool_action_create(priv, cpool);
                if (ret != 0) {
                        rte_flow_error_set(error, -ret,
@@ -736,15 +741,19 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
        cparam.threshold = HWS_CNT_CACHE_THRESHOLD_DEFAULT;
        cparam.size = HWS_CNT_CACHE_SZ_DEFAULT;
        cpool = mlx5_hws_cnt_pool_init(priv->sh, &pcfg, &cparam, error);
-       if (cpool == NULL)
+       if (cpool == NULL) {
+               ret = -rte_errno;
                goto error;
+       }
        ret = mlx5_hws_cnt_pool_dcs_alloc(priv->sh, cpool, error);
        if (ret != 0)
                goto error;
        sz = RTE_ALIGN_CEIL(mlx5_hws_cnt_pool_get_size(cpool), 4);
        cpool->raw_mng = mlx5_hws_cnt_raw_data_alloc(priv->sh, sz, error);
-       if (cpool->raw_mng == NULL)
+       if (cpool->raw_mng == NULL) {
+               ret = -rte_errno;
                goto error;
+       }
        __hws_cnt_id_load(cpool);
        /*
         * Bump query gen right after pool create so the
-- 
2.39.5

Reply via email to