Re: [PATCH v3 net-next] net/intel: Replace manual array size calculation with ARRAY_SIZE
Przemek Kitszel <[email protected]>
| Newsgroups | org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel,org.kernel.vger.netdev,org.osuosl.intel-wired-lan |
|---|---|
| Message-ID | <[email protected]> |
On 4/28/26 12:36, 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. > While at it, beautify condition surrounding it by reversing check and remove > unnecessary casting. > > Signed-off-by: Jakub Raczynski <[email protected]> > Reviewed-by: Dan Carpenter <[email protected]> thank you, Reviewed-by: Przemek Kitszel <[email protected]> (next time use "iwl-next" in the title, no need to repost just for that) > --- > Link to v1/v2: > https://lore.kernel.org/kernel-janitors/[email protected]/ > > Changes in v3: > - Add 'Reviewed-by' from previous thread > Changes in v2: > - Beautify code by removing excessive parentheses > - Reverse if condition to remove negation of whole check > > 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..dcf3baec7b73 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 (aq_rc >= ARRAY_SIZE(aq_to_posix)) > return -ERANGE; > > return aq_to_posix[aq_rc]; > diff --git a/drivers/net/ethernet/intel/iavf/iavf_adminq.h b/drivers/net/ethernet/intel/iavf/iavf_adminq.h > index bbf5c4b3a2ae..dd2f61172157 100644 > --- a/drivers/net/ethernet/intel/iavf/iavf_adminq.h > +++ b/drivers/net/ethernet/intel/iavf/iavf_adminq.h > @@ -113,7 +113,7 @@ static inline int iavf_aq_rc_to_posix(int aq_ret, int aq_rc) > if (aq_ret == IAVF_ERR_ADMIN_QUEUE_TIMEOUT) > return -EAGAIN; > > - if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0])))) > + if (aq_rc >= ARRAY_SIZE(aq_to_posix)) > return -ERANGE; > > return aq_to_posix[aq_rc];