[dpdk-stable] [PATCH] ethdev: fix switching domain allocation

Ferruh Yigit ferruh.yigit at intel.com
Tue Jan 14 16:32:24 CET 2020


On 12/19/2019 12:47 PM, Viacheslav Ovsiienko wrote:
> The maximum amount of unique switching domain is supposed
> to be equal to RTE_MAX_ETHPORTS. The current implementation
> allows to allocate only RTE_MAX_ETHPORTS-1 domains.
> 
> Fixes: ce9250406323 ("ethdev: add switch domain allocator")
> Cc: stable at dpdk.org
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo at mellanox.com>
> ---
>  lib/librte_ethdev/rte_ethdev.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index 6e9cb24..4c2312c 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -5065,10 +5065,10 @@ enum rte_eth_switch_domain_state {
>  	*domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
>  
>  	for (i = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID + 1;
> -		i < RTE_MAX_ETHPORTS; i++) {
> -		if (rte_eth_switch_domains[i].state ==
> +		i <= RTE_MAX_ETHPORTS; i++) {
> +		if (rte_eth_switch_domains[i - 1].state ==
>  			RTE_ETH_SWITCH_DOMAIN_UNUSED) {
> -			rte_eth_switch_domains[i].state =
> +			rte_eth_switch_domains[i - 1].state =
>  				RTE_ETH_SWITCH_DOMAIN_ALLOCATED;
>  			*domain_id = i;

I would keep the indexes same but change how to set the 'domain_id' to
"*domain_id = i + 1;", that makes logic simpler.

Would it be simpler if the invalid domain id value used as UINT16_MAX instead of
'0'? This enables using 'domain_id' as index and prevent this error prone indexing.

And I think it makes sense to start the loop with "i = 0", instead of
'RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID', you are walking through the port list,
why to involve the 'RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID' here.

>  			return 0;
> @@ -5082,14 +5082,15 @@ enum rte_eth_switch_domain_state {
>  rte_eth_switch_domain_free(uint16_t domain_id)
>  {
>  	if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID ||
> -		domain_id >= RTE_MAX_ETHPORTS)
> +		domain_id > RTE_MAX_ETHPORTS)
>  		return -EINVAL;
>  
> -	if (rte_eth_switch_domains[domain_id].state !=
> +	if (rte_eth_switch_domains[domain_id - 1].state !=
>  		RTE_ETH_SWITCH_DOMAIN_ALLOCATED)
>  		return -EINVAL;
>  
> -	rte_eth_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED;
> +	rte_eth_switch_domains[domain_id - 1].state =
> +		RTE_ETH_SWITCH_DOMAIN_UNUSED;
>  
>  	return 0;
>  }
> 



More information about the stable mailing list