All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Jakub Raczynski <j.raczynski@samsung.com>
Cc: netdev@vger.kernel.org, kuba@kernel.org,
	przemyslaw.kitszel@intel.com, anthony.l.nguyen@intel.com,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] net/intel: Replace manual array size calculation with ARRAY_SIZE
Date: Wed, 22 Apr 2026 16:22:58 +0300	[thread overview]
Message-ID: <aejLsqoXKBHwWTbL@stanley.mountain> (raw)
In-Reply-To: <aeiHkejLjhRKyj/u@AMDC4622.eu.corp.samsungelectronics.net>

On Wed, Apr 22, 2026 at 10:32:17AM +0200, Jakub Raczynski wrote:
> On Tue, Apr 21, 2026 at 05:11:19PM +0300, Dan Carpenter wrote:
> > On Tue, Apr 21, 2026 at 01:40:29PM +0200, Jakub Raczynski wrote:
> > >  
> > > -	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
> >
> 
> Alright, will beautify it and resend soon.
> 
> I can see potential original intention of not comparing unsigned from sizeof
> with int, maybe that was original compiler configuration to include that
> warning.

Yeah.  I know.  I wrote a blog about this...

https://staticthinking.wordpress.com/2023/07/25/wsign-compare-is-garbage/

Check this out:

$ git grep '(int)' | grep ARRAY_SIZE | wc -l
53

It's as if we want array underflows.

> But at this variable range it is irrelevant and it is probably most disabled
> warning ever.

With the unnecessary cast I had to review to ensure that aq_rc is not
unsigned long type.  There is a real downside to this kind of rule.

regards,
dan carpenter


  reply	other threads:[~2026-04-22 13:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260421114034eucas1p1d746ffe32b49aeb57f10e729d1331124@eucas1p1.samsung.com>
2026-04-21 11:40 ` [PATCH] net/intel: Replace manual array size calculation with ARRAY_SIZE Jakub Raczynski
2026-04-21 14:11   ` Dan Carpenter
2026-04-22  8:32     ` Jakub Raczynski
2026-04-22 13:22       ` Dan Carpenter [this message]
2026-04-22 10:57     ` [PATCH v2] " Jakub Raczynski
2026-04-22 13:24       ` Dan Carpenter
2026-04-23  7:41       ` Przemek Kitszel

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=aejLsqoXKBHwWTbL@stanley.mountain \
    --to=error27@gmail.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=j.raczynski@samsung.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=przemyslaw.kitszel@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.