[2/2] distributor: imposing additional check on no of workers
diff mbox series

Message ID 1543504135-137867-2-git-send-email-harman.kalra@caviumnetworks.com
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • [1/2] test/distributor: flush with worker shutdown test fails
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK

Commit Message

Harman Kalra Nov. 29, 2018, 3:09 p.m. UTC
From: Harman Kalra <harman.kalra@cavium.com>

No of workers should never exceed RTE_MAX_LCORE.
RTE_DIST_ALG_SINGLE also require no of workers check.

Signed-off-by: Harman Kalra <harman.kalra@cavium.com>
---
 lib/librte_distributor/rte_distributor.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git lib/librte_distributor/rte_distributor.c lib/librte_distributor/rte_distributor.c
index d505983..043b8f3 100644
--- lib/librte_distributor/rte_distributor.c
+++ lib/librte_distributor/rte_distributor.c
@@ -595,6 +595,12 @@  struct rte_distributor *
 	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) {
@@ -612,11 +618,6 @@  struct rte_distributor *
 		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) {