Subject: Re: [PATCH net-next] eth: mlx5: avoid iterator use outside of a loop

From: Leon Romanovsky <[email-masked]>
Date: Sun, 16 Apr 2023 13:17:53 +0300

On Fri, Apr 14, 2023 at 11:07:29AM -0700, Jakub Kicinski wrote:
> Fix the following warning about risky iterator use:
> 
> drivers/net/ethernet/mellanox/mlx5/core/eq.c:1010 mlx5_comp_irq_get_affinity_mask() warn: iterator used outside loop: 'eq'
> 
> Signed-off-by: Jakub Kicinski <[email-masked]>
> ---
> CC: [email-masked]
> CC: [email-masked]
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/eq.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> index eb41f0abf798..03c0165a8fd5 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> @@ -1070,10 +1070,11 @@ mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector)
>  
>  	list_for_each_entry(eq, &table->comp_eqs_list, list) {
>  		if (i++ == vector)
> -			break;
> +			return mlx5_irq_get_affinity_mask(eq->core.irq);
>  	}
>  
> -	return mlx5_irq_get_affinity_mask(eq->core.irq);
> +	WARN_ON_ONCE(1);
> +	return 0;

I would do it without changing last return, but "return ERR_PTR(0);"
will do the trick too.

Thanks

>  }
>  EXPORT_SYMBOL(mlx5_comp_irq_get_affinity_mask);
>  
> -- 
> 2.39.2
>