From: Joe Perches <joe@perches.com>
To: Thomas Meyer <thomas@m3y3r.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7
Date: Sun, 03 Sep 2017 13:20:40 -0700 [thread overview]
Message-ID: <1504470040.18971.9.camel@perches.com> (raw)
In-Reply-To: <20170903194605.qh6k3fthcc6qevpn@olymp>
On Sun, 2017-09-03 at 21:59 +0200, Thomas Meyer wrote:
> On Sun, Sep 03, 2017 at 08:36:02AM -0700, Joe Perches wrote:
> > On Sun, 2017-09-03 at 14:19 +0200, Thomas Meyer wrote:
> > > Use ARRAY_SIZE macro, rather than explicitly coding some variant of it
> > > yourself.
> > >
> > > Found with: find -type f -name "*.c" -o -name "*.h" | xargs perl -p -i -e
> > > 's/\bsizeof\s*\(\s*(\w+)\s*\)\s*\ /\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\)
> > > /ARRAY_SIZE(\1)/g' and manual check/verification.
> >
> > Hey Thomas.
>
> Hi Joe,
> >
> > There are some instances that span multiple lines that
> > the regex above misses.
> >
> > For instance:
> >
> > diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
> > index 3d701c7a4c91..26a825bd7581 100644
> > --- a/drivers/infiniband/hw/mlx5/odp.c
> > +++ b/drivers/infiniband/hw/mlx5/odp.c
> > @@ -929,8 +929,7 @@ static int mlx5_ib_mr_initiator_pfault_handler(
> > return -EFAULT;
> > }
> >
> > - if (unlikely(opcode >= sizeof(mlx5_ib_odp_opcode_cap) /
> > - sizeof(mlx5_ib_odp_opcode_cap[0]) ||
> > + if (unlikely(opcode >= ARRAY_SIZE(mlx5_ib_odp_opcode_cap) ||
> >
> > Here is another perl command regex that fixes a few more:
> >
> > $ perl -i -e 'local $/; while (<>) { s/\bsizeof\s*\(\s*(\w+)\s*\)\s*\/\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\)/ARRAY_SIZE(\1)/g; print; }' $file
> >
> > This regex could still miss variants that
> > have a comment or that don't use parentheses
> > around the sizeof.
>
> Okay, fine, but I think this patch series is okay to go in anyway. I will
> re-run with above regex after the next rcX tag. Would that be fine for you?
> What do you think?
I think whatever you want to do is fine with me.
If you want, you could use the simple cocci script below
which is _much_ better than the perl regex as it can
find all the appropriate cases not just
sizeof(var)/sizeof(var[0])
$ cat array_size.cocci
@@
type T;
T[] E;
@@
(
- sizeof(E) /sizeof(*E)
+ ARRAY_SIZE(E)
|
- sizeof(E) /sizeof(E[...])
+ ARRAY_SIZE(E)
|
- sizeof(E) /sizeof(T)
+ ARRAY_SIZE(E)
)
$
and maybe this
$ spatch --in-place --all-includes --sp-file array_size.cocci .
prev parent reply other threads:[~2017-09-03 20:20 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-03 12:19 [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Thomas Meyer
2017-09-03 12:19 ` [PATCH 2/10] drm/amdgpu: Use ARRAY_SIZE macro Thomas Meyer
2017-09-03 12:19 ` [PATCH 10/10] staging/atomisp: " Thomas Meyer
2017-09-03 12:19 ` [PATCH 6/10] ixgbe: " Thomas Meyer
2017-09-05 18:50 ` David Miller
2017-09-05 19:45 ` Thomas Meyer
2017-09-05 20:01 ` Joe Perches
2017-09-05 21:22 ` David Miller
2017-09-06 9:08 ` Thomas Meyer
2017-09-06 15:19 ` Joe Perches
2017-09-03 12:19 ` [PATCH 3/10] drm/i915/gvt: " Thomas Meyer
2017-09-03 12:19 ` [PATCH 9/10] [SCSI] bfa: " Thomas Meyer
2017-09-03 12:19 ` [PATCH 5/10] [media] lgdt3306a: " Thomas Meyer
2017-09-03 12:19 ` [PATCH 1/10] KVM: PPC: Book3S HV: " Thomas Meyer
2017-09-03 12:19 ` Thomas Meyer
2017-10-19 3:44 ` Paul Mackerras
2017-10-19 3:44 ` Paul Mackerras
2017-09-03 12:19 ` [PATCH 4/10] drm/nouveau/bios/init: " Thomas Meyer
2017-09-03 12:19 ` [PATCH 8/10] ath9k: " Thomas Meyer
2017-09-25 7:15 ` [8/10] " Kalle Valo
2017-09-03 12:19 ` [PATCH 7/10] net/mlx4_core: " Thomas Meyer
2017-09-03 13:14 ` Tariq Toukan
[not found] ` <1504439110050-1961876957-7-diffsplit-thomas-VsYtu1Qij5c@public.gmane.org>
2017-09-05 18:50 ` David Miller
2017-09-05 18:50 ` David Miller
2017-09-03 15:36 ` [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Joe Perches
2017-09-03 19:59 ` Thomas Meyer
2017-09-03 20:20 ` 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=1504470040.18971.9.camel@perches.com \
--to=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas@m3y3r.de \
/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.