Re: [PATCH] net/intel: Replace manual array size calculation with ARRAY_SIZE

Dan Carpenter <[email protected]>
Newsgroups org.kernel.vger.kernel-janitors,org.kernel.vger.netdev
Message-ID <[email protected]>
On Tue, Apr 21, 2026 at 01:40:29PM +0200, Jakub Raczynski wrote:
> There are still places in the code where manual calculation of array size
> exist, but it is good to enforce usage of single macro through the whole
> code as it makes code bit more readable.
> 
> Signed-off-by: Jakub Raczynski <[email protected]>
> ---
>  drivers/net/ethernet/intel/i40e/i40e_adminq.h | 2 +-
>  drivers/net/ethernet/intel/iavf/iavf_adminq.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_adminq.h b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
> index 1be97a3a86ce..0e7cecd00169 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_adminq.h
> +++ b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
> @@ -109,7 +109,7 @@ static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
>  		-EFBIG,      /* I40E_AQ_RC_EFBIG */
>  	};
>  
> -	if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
> +	if (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix)))

This still isn't beautiful.  There are so many parens.  The !(foo < size)
formulation is weird.  The cast is unnnecessary.  Better to write it as:

	if (aq_rc >= ARRAY_SIZE(aq_to_posix))
		return -ERANGE;

>  		return -ERANGE;
>  
>  	return aq_to_posix[aq_rc];

regards,
dan carpenter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.