Re: [PATCH] net/intel: Replace manual array size calculation with ARRAY_SIZE
Dan Carpenter <[email protected]>
| Newsgroups | org.kernel.vger.kernel-janitors,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
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