From: Joe Perches <joe@perches.com>
To: "Jankowski, Konrad0" <konrad0.jankowski@intel.com>,
Wei Xu <xuwei5@hisilicon.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "salil.mehta@huawei.com" <salil.mehta@huawei.com>,
"jinying@hisilicon.com" <jinying@hisilicon.com>,
"tangkunshan@huawei.com" <tangkunshan@huawei.com>,
"huangdaode@hisilicon.com" <huangdaode@hisilicon.com>,
"john.garry@huawei.com" <john.garry@huawei.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linuxarm@huawei.com" <linuxarm@huawei.com>,
"shameerali.kolothum.thodi@huawei.com"
<shameerali.kolothum.thodi@huawei.com>,
"zhangyi.ac@huawei.com" <zhangyi.ac@huawei.com>,
"intel-wired-lan@lists.osuosl.org"
<intel-wired-lan@lists.osuosl.org>,
"jonathan.cameron@huawei.com" <jonathan.cameron@huawei.com>,
Jakub Kicinski <kuba@kernel.org>,
"liguozhu@hisilicon.com" <liguozhu@hisilicon.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"shiju.jose@huawei.com" <shiju.jose@huawei.com>
Subject: Re: [Intel-wired-lan] [net-next] net: iavf: Use the ARRAY_SIZE macro for aq_to_posix
Date: Thu, 14 Jan 2021 02:55:13 -0800 [thread overview]
Message-ID: <ff6c529f78396aa3ce8d9cb9fefeeb098e64342f.camel@perches.com> (raw)
In-Reply-To: <CY4PR11MB15769D5697074F230C8742CAABA80@CY4PR11MB1576.namprd11.prod.outlook.com>
On Thu, 2021-01-14 at 09:57 +0000, Jankowski, Konrad0 wrote:
> > -----Original Message-----
> > From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.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@intel.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;
prev parent reply other threads:[~2021-01-14 10:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 8:51 Wei Xu
2020-09-09 9:33 ` Joe Perches
2020-09-09 9:38 ` Joe Perches
2021-01-14 9:57 ` [Intel-wired-lan] " Jankowski, Konrad0
2021-01-14 10:55 ` Joe Perches [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ff6c529f78396aa3ce8d9cb9fefeeb098e64342f.camel@perches.com \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=huangdaode@hisilicon.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jinying@hisilicon.com \
--cc=john.garry@huawei.com \
--cc=jonathan.cameron@huawei.com \
--cc=konrad0.jankowski@intel.com \
--cc=kuba@kernel.org \
--cc=liguozhu@hisilicon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=salil.mehta@huawei.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=shiju.jose@huawei.com \
--cc=tangkunshan@huawei.com \
--cc=xuwei5@hisilicon.com \
--cc=zhangyi.ac@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®