distributor: fix check of workers number
authorHarman Kalra <hkalra@marvell.com>
Fri, 5 Jul 2019 10:05:12 +0000 (10:05 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 17 Jul 2019 20:35:19 +0000 (22:35 +0200)
No of workers should never exceed RTE_MAX_LCORE.
RTE_DIST_ALG_SINGLE also require no of workers check.

Fixes: 775003ad2f96 ("distributor: add new burst-capable library")
Cc: stable@dpdk.org
Signed-off-by: Harman Kalra <hkalra@marvell.com>
Acked-by: David Hunt <david.hunt@intel.com>
lib/librte_distributor/rte_distributor.c

index 0a3213b..9fa05f6 100644 (file)
@@ -596,6 +596,12 @@ rte_distributor_create_v1705(const char *name,
        RTE_BUILD_BUG_ON((sizeof(*d) & RTE_CACHE_LINE_MASK) != 0);
        RTE_BUILD_BUG_ON((RTE_DISTRIB_MAX_WORKERS & 7) != 0);
 
+       if (name == NULL || num_workers >=
+               (unsigned int)RTE_MIN(RTE_DISTRIB_MAX_WORKERS, RTE_MAX_LCORE)) {
+               rte_errno = EINVAL;
+               return NULL;
+       }
+
        if (alg_type == RTE_DIST_ALG_SINGLE) {
                d = malloc(sizeof(struct rte_distributor));
                if (d == NULL) {
@@ -613,11 +619,6 @@ rte_distributor_create_v1705(const char *name,
                return d;
        }
 
-       if (name == NULL || num_workers >= RTE_DISTRIB_MAX_WORKERS) {
-               rte_errno = EINVAL;
-               return NULL;
-       }
-
        snprintf(mz_name, sizeof(mz_name), RTE_DISTRIB_PREFIX"%s", name);
        mz = rte_memzone_reserve(mz_name, sizeof(*d), socket_id, NO_FLAGS);
        if (mz == NULL) {