lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 14 Jan 2021 02:55:13 -0800
From:   Joe Perches <joe@...ches.com>
To:     "Jankowski, Konrad0" <konrad0.jankowski@...el.com>,
        Wei Xu <xuwei5@...ilicon.com>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Cc:     "salil.mehta@...wei.com" <salil.mehta@...wei.com>,
        "jinying@...ilicon.com" <jinying@...ilicon.com>,
        "tangkunshan@...wei.com" <tangkunshan@...wei.com>,
        "huangdaode@...ilicon.com" <huangdaode@...ilicon.com>,
        "john.garry@...wei.com" <john.garry@...wei.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linuxarm@...wei.com" <linuxarm@...wei.com>,
        "shameerali.kolothum.thodi@...wei.com" 
        <shameerali.kolothum.thodi@...wei.com>,
        "zhangyi.ac@...wei.com" <zhangyi.ac@...wei.com>,
        "intel-wired-lan@...ts.osuosl.org" <intel-wired-lan@...ts.osuosl.org>,
        "jonathan.cameron@...wei.com" <jonathan.cameron@...wei.com>,
        Jakub Kicinski <kuba@...nel.org>,
        "liguozhu@...ilicon.com" <liguozhu@...ilicon.com>,
        "davem@...emloft.net" <davem@...emloft.net>,
        "shiju.jose@...wei.com" <shiju.jose@...wei.com>
Subject: Re: [Intel-wired-lan] [net-next] net: iavf: Use the ARRAY_SIZE
 macro for aq_to_posix

On Thu, 2021-01-14 at 09:57 +0000, Jankowski, Konrad0 wrote:
> > -----Original Message-----
> > From: Intel-wired-lan <intel-wired-lan-bounces@...osl.org> On Behalf Of Wei Xu
[]
> > Use the ARRAY_SIZE macro to calculate the size of an array.
> > This code was detected with the help of Coccinelle.
[]
> > diff --git a/drivers/net/ethernet/intel/iavf/iavf_adminq.h
[]
> > @@ -120,7 +120,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 (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix)))
> >  		return -ERANGE;
> > 
> >  	return aq_to_posix[aq_rc];
> 
> Tested-by: Konrad Jankowski <konrad0.jankowski@...el.com>

I think several things are poor here.

This function shouldn't really be a static inline as it would just bloat
whatever uses it and should just be a typical function in a utility .c file.

And it doesn't seem this function is used at all so it should be deleted.

aq_to_posix should be static const.

And if it's really necessary, I think it would be simpler to read using code
without the cast and negation.

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



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ