[v3,2/2] distributor: fix additional check on no of workers

Message ID 1562321046-25195-2-git-send-email-hkalra@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v3,1/2] test/distributor: fix flush with worker shutdown test |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Harman Kalra July 5, 2019, 10:05 a.m. UTC
  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>
---
 lib/librte_distributor/rte_distributor.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
  

Comments

Thomas Monjalon July 16, 2019, 10:51 a.m. UTC | #1
Any review please?

05/07/2019 12:05, Harman Kalra:
> 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>
> ---
>  lib/librte_distributor/rte_distributor.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
> index 208abfb1d..bfcc536fd 100644
> --- a/lib/librte_distributor/rte_distributor.c
> +++ b/lib/librte_distributor/rte_distributor.c
> @@ -595,6 +595,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) {
> @@ -612,11 +618,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) {
>
  
Hunt, David July 17, 2019, 3:32 p.m. UTC | #2
Hi Harman,

On 05/07/2019 11:05, Harman Kalra wrote:
> 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>
> ---
>   lib/librte_distributor/rte_distributor.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
> index 208abfb1d..bfcc536fd 100644
> --- a/lib/librte_distributor/rte_distributor.c
> +++ b/lib/librte_distributor/rte_distributor.c
> @@ -595,6 +595,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) {
> @@ -612,11 +618,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) {


Builds OK, runs OK. Change makes sense, also good to move the check to 
the new location.

Acked-by: David Hunt <david.hunt@intel.com>
  
Thomas Monjalon July 17, 2019, 8:37 p.m. UTC | #3
17/07/2019 17:32, Hunt, David:
> Hi Harman,
> 
> On 05/07/2019 11:05, Harman Kalra wrote:
> > 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>
> 
> Builds OK, runs OK. Change makes sense, also good to move the check to 
> the new location.
> 
> Acked-by: David Hunt <david.hunt@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c
index 208abfb1d..bfcc536fd 100644
--- a/lib/librte_distributor/rte_distributor.c
+++ b/lib/librte_distributor/rte_distributor.c
@@ -595,6 +595,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) {
@@ -612,11 +618,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) {