Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1725705

Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7

From Joe Perches <joe@perches.com>
Newsgroups linux.kernel
Subject Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7
Date 2017-09-03 17:40 +0200
Message-ID <ulFab-1GL-31@gated-at.bofh.it> (permalink)
References <ulClX-8pn-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

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.

It seems none of those styles exist though.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  [PATCH 8/10] ath9k: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  [PATCH 4/10] drm/nouveau/bios/init: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  [PATCH 10/10] staging/atomisp: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  [PATCH 9/10] [SCSI] bfa: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
    Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro David Miller <davem@davemloft.net> - 2017-09-05 21:00 +0200
      Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-05 21:50 +0200
        Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro Joe Perches <joe@perches.com> - 2017-09-05 22:10 +0200
          Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro David Miller <davem@davemloft.net> - 2017-09-05 23:30 +0200
            Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-06 11:10 +0200
              Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro Joe Perches <joe@perches.com> - 2017-09-06 17:20 +0200
  [PATCH 2/10] drm/amdgpu: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  [PATCH 5/10] [media] lgdt3306a: Use ARRAY_SIZE macro Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 14:40 +0200
  Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Joe Perches <joe@perches.com> - 2017-09-03 17:40 +0200
    Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Thomas Meyer <thomas@m3y3r.de> - 2017-09-03 22:00 +0200
      Re: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7 Joe Perches <joe@perches.com> - 2017-09-03 22:30 +0200

csiph-web