mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Wei Xu <xuwei5@hisilicon.com>, netdev@vger.kernel.org
Cc: davem@davemloft.net, linuxarm@huawei.com,
	shameerali.kolothum.thodi@huawei.com,
	jonathan.cameron@huawei.com, john.garry@huawei.com,
	salil.mehta@huawei.com, shiju.jose@huawei.com,
	jinying@hisilicon.com, zhangyi.ac@huawei.com,
	liguozhu@hisilicon.com, tangkunshan@huawei.com,
	huangdaode@hisilicon.com,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
	Jakub Kicinski <kuba@kernel.org>,
	intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [net-next] net: iavf: Use the ARRAY_SIZE macro for aq_to_posix
Date: Wed, 09 Sep 2020 02:33:48 -0700	[thread overview]
Message-ID: <2530c5c8a596b7edd7e2273cffc3b76ac4b437c7.camel@perches.com> (raw)
In-Reply-To: <1599641471-204919-1-git-send-email-xuwei5@hisilicon.com>

On Wed, 2020-09-09 at 16:51 +0800, Wei Xu wrote:
> 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 b/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;

If you want to use a cast,

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

would be a more common and simpler style, though
perhaps testing ac_rc < 0 would be more intelligible.

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




  reply	other threads:[~2020-09-09  9:34 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 [this message]
2020-09-09  9:38   ` Joe Perches
2021-01-14  9:57 ` [Intel-wired-lan] " Jankowski, Konrad0
2021-01-14 10:55   ` Joe Perches

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=2530c5c8a596b7edd7e2273cffc3b76ac4b437c7.camel@perches.com \
    --to=joe@perches.com \
    --cc=davem@davemloft.net \
    --cc=huangdaode@hisilicon.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jinying@hisilicon.com \
    --cc=john.garry@huawei.com \
    --cc=jonathan.cameron@huawei.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®