2017-09-03 12:30:47

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 0/10] Use ARRAY_SIZE macro - v4.13-rc7

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.

Run against version v4.13-rc7

Let me know when you as a maintainer are not interested in these kind of patches.
I can exclude you by path; e.g. all findings in "drivers/scsi" will never
be reported again by this semi-automatic program runs.


2017-09-03 12:30:36

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 5/10] [media] lgdt3306a: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c
index c9b1eb38444e..724e9aac0f11 100644
--- a/drivers/media/dvb-frontends/lgdt3306a.c
+++ b/drivers/media/dvb-frontends/lgdt3306a.c
@@ -19,6 +19,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <asm/div64.h>
+#include <linux/kernel.h>
#include <linux/dvb/frontend.h>
#include "dvb_math.h"
#include "lgdt3306a.h"
@@ -2072,7 +2073,7 @@ static const short regtab[] = {
0x30aa, /* MPEGLOCK */
};

-#define numDumpRegs (sizeof(regtab)/sizeof(regtab[0]))
+#define numDumpRegs (ARRAY_SIZE(regtab))
static u8 regval1[numDumpRegs] = {0, };
static u8 regval2[numDumpRegs] = {0, };


2017-09-03 12:30:46

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 2/10] drm/amdgpu: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c
index 9804318f3488..7ef84d884714 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c
@@ -20,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
*/
+#include <linux/kernel.h>
+
#include "amdgpu.h"
#include "mmhub_v1_0.h"

@@ -268,7 +270,7 @@ const struct pctl_data pctl0_data[] = {
{0x135, 0x12a810},
{0x149, 0x7a82c}
};
-#define PCTL0_DATA_LEN (sizeof(pctl0_data)/sizeof(pctl0_data[0]))
+#define PCTL0_DATA_LEN (ARRAY_SIZE(pctl0_data))

#define PCTL0_RENG_EXEC_END_PTR 0x151
#define PCTL0_STCTRL_REG_SAVE_RANGE0_BASE 0xa640
@@ -297,7 +299,7 @@ const struct pctl_data pctl1_data[] = {
{0x1be, 0x17a7dd},
{0x1d7, 0x12a810}
};
-#define PCTL1_DATA_LEN (sizeof(pctl1_data)/sizeof(pctl1_data[0]))
+#define PCTL1_DATA_LEN (ARRAY_SIZE(pctl1_data))

#define PCTL1_RENG_EXEC_END_PTR 0x1ea
#define PCTL1_STCTRL_REG_SAVE_RANGE0_BASE 0xa000

2017-09-03 12:30:35

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 8/10] ath9k: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index 3dbfd86ebe36..c2e210c0a770 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -15,6 +15,7 @@
*/

#include <asm/unaligned.h>
+#include <linux/kernel.h>
#include "hw.h"
#include "ar9003_phy.h"
#include "ar9003_eeprom.h"
@@ -2946,14 +2947,12 @@ static const struct ar9300_eeprom *ar9300_eep_templates[] = {

static const struct ar9300_eeprom *ar9003_eeprom_struct_find_by_id(int id)
{
-#define N_LOOP (sizeof(ar9300_eep_templates) / sizeof(ar9300_eep_templates[0]))
int it;

- for (it = 0; it < N_LOOP; it++)
+ for (it = 0; it < ARRAY_SIZE(ar9300_eep_templates); it++)
if (ar9300_eep_templates[it]->templateVersion == id)
return ar9300_eep_templates[it];
return NULL;
-#undef N_LOOP
}

static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah)

2017-09-03 12:31:25

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 10/10] staging/atomisp: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c
index a7c6bba7e094..11d3995ba0db 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/ifmtr/src/ifmtr.c
@@ -29,6 +29,7 @@ more details.
#endif

#include "system_global.h"
+#include <linux/kernel.h>

#ifdef USE_INPUT_SYSTEM_VERSION_2

@@ -487,7 +488,7 @@ static void ifmtr_set_if_blocking_mode(
{
int i;
bool block[] = { false, false, false, false };
- assert(N_INPUT_FORMATTER_ID <= (sizeof(block) / sizeof(block[0])));
+ assert(N_INPUT_FORMATTER_ID <= (ARRAY_SIZE(block)));

#if !defined(IS_ISP_2400_SYSTEM)
#error "ifmtr_set_if_blocking_mode: ISP_SYSTEM must be one of {IS_ISP_2400_SYSTEM}"

2017-09-03 12:30:33

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 4/10] drm/nouveau/bios/init: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c
index b58ee99f7bfc..440efa333d6c 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c
@@ -21,6 +21,7 @@
*
* Authors: Ben Skeggs
*/
+#include <linux/kernel.h>
#include <subdev/bios.h>
#include <subdev/bios/bit.h>
#include <subdev/bios/bmp.h>
@@ -2271,7 +2272,7 @@ static struct nvbios_init_opcode {
[0xaa] = { init_reserved },
};

-#define init_opcode_nr (sizeof(init_opcode) / sizeof(init_opcode[0]))
+#define init_opcode_nr (ARRAY_SIZE(init_opcode))

int
nvbios_exec(struct nvbios_init *init)

2017-09-03 12:31:44

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 7/10] net/mlx4_core: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index 041c0ed65929..8eca12927be0 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -36,6 +36,7 @@
#include <linux/mlx4/cmd.h>
#include <linux/module.h>
#include <linux/cache.h>
+#include <linux/kernel.h>

#include "fw.h"
#include "icm.h"
@@ -2450,14 +2451,14 @@ int mlx4_config_dev_retrieval(struct mlx4_dev *dev,
csum_mask = (config_dev.rx_checksum_val >> CONFIG_DEV_RX_CSUM_MODE_PORT1_BIT_OFFSET) &
CONFIG_DEV_RX_CSUM_MODE_MASK;

- if (csum_mask >= sizeof(config_dev_csum_flags)/sizeof(config_dev_csum_flags[0]))
+ if (csum_mask >= ARRAY_SIZE(config_dev_csum_flags))
return -EINVAL;
params->rx_csum_flags_port_1 = config_dev_csum_flags[csum_mask];

csum_mask = (config_dev.rx_checksum_val >> CONFIG_DEV_RX_CSUM_MODE_PORT2_BIT_OFFSET) &
CONFIG_DEV_RX_CSUM_MODE_MASK;

- if (csum_mask >= sizeof(config_dev_csum_flags)/sizeof(config_dev_csum_flags[0]))
+ if (csum_mask >= ARRAY_SIZE(config_dev_csum_flags))
return -EINVAL;
params->rx_csum_flags_port_2 = config_dev_csum_flags[csum_mask];

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 5fe5cdc51357..fe18650c9342 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -34,6 +34,7 @@
*/

#include <linux/module.h>
+#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/pci.h>
@@ -3658,7 +3659,7 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data,
* per port, we must limit the number of VFs to 63 (since their are
* 128 MACs)
*/
- for (i = 0; i < sizeof(nvfs)/sizeof(nvfs[0]) && i < num_vfs_argc;
+ for (i = 0; i < ARRAY_SIZE(nvfs) && i < num_vfs_argc;
total_vfs += nvfs[param_map[num_vfs_argc - 1][i]], i++) {
nvfs[param_map[num_vfs_argc - 1][i]] = num_vfs[i];
if (nvfs[i] < 0) {
@@ -3667,7 +3668,7 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data,
goto err_disable_pdev;
}
}
- for (i = 0; i < sizeof(prb_vf)/sizeof(prb_vf[0]) && i < probe_vfs_argc;
+ for (i = 0; i < ARRAY_SIZE(prb_vf) && i < probe_vfs_argc;
i++) {
prb_vf[param_map[probe_vfs_argc - 1][i]] = probe_vf[i];
if (prb_vf[i] < 0 || prb_vf[i] > nvfs[i]) {
@@ -3746,11 +3747,11 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data,
if (total_vfs) {
unsigned vfs_offset = 0;

- for (i = 0; i < sizeof(nvfs)/sizeof(nvfs[0]) &&
+ for (i = 0; i < ARRAY_SIZE(nvfs) &&
vfs_offset + nvfs[i] < extended_func_num(pdev);
vfs_offset += nvfs[i], i++)
;
- if (i == sizeof(nvfs)/sizeof(nvfs[0])) {
+ if (i == ARRAY_SIZE(nvfs)) {
err = -ENODEV;
goto err_release_regions;
}

2017-09-03 12:32:53

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 9/10] [SCSI] bfa: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/scsi/bfa/bfa_core.c b/drivers/scsi/bfa/bfa_core.c
index 3e1caec82554..4a03cd9fa63f 100644
--- a/drivers/scsi/bfa/bfa_core.c
+++ b/drivers/scsi/bfa/bfa_core.c
@@ -16,6 +16,7 @@
* General Public License for more details.
*/

+#include <linux/kernel.h>
#include "bfad_drv.h"
#include "bfa_modules.h"
#include "bfi_reg.h"
@@ -1957,7 +1958,7 @@ bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
{BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
};

- *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
+ *npciids = ARRAY_SIZE(__pciids);
*pciids = __pciids;
}


2017-09-03 12:33:12

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 3/10] drm/i915/gvt: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 3deadcbd5a24..7d8035093a1e 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -30,6 +30,7 @@
* Bing Niu <[email protected]>
*
*/
+#include <linux/kernel.h>

#include "i915_drv.h"
#include "gvt.h"
@@ -115,7 +116,7 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
*/
low_avail = gvt_aperture_sz(gvt) - HOST_LOW_GM_SIZE;
high_avail = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE;
- num_types = sizeof(vgpu_types) / sizeof(vgpu_types[0]);
+ num_types = ARRAY_SIZE(vgpu_types);

gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type),
GFP_KERNEL);

2017-09-03 12:33:29

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
index 72d84a065e34..fabb11475fb4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
@@ -21,6 +21,7 @@
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
*
******************************************************************************/
+#include <linux/kernel.h>
#include "ixgbe_x540.h"
#include "ixgbe_type.h"
#include "ixgbe_common.h"
@@ -947,7 +948,7 @@ static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
u16 length, bufsz, i, start;
u16 *local_buffer;

- bufsz = sizeof(buf) / sizeof(buf[0]);
+ bufsz = ARRAY_SIZE(buf);

/* Read a chunk at the pointer location */
if (!buffer) {

2017-09-03 12:33:52

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 1/10] KVM: PPC: Book3S HV: Use ARRAY_SIZE macro

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.

Signed-off-by: Thomas Meyer <[email protected]>
---

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 359c79cdf0cc..ae80181c4e1f 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -19,6 +19,7 @@
*/

#include <linux/kvm_host.h>
+#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/preempt.h>
@@ -1766,7 +1767,7 @@ static struct debugfs_timings_element {
{"cede", offsetof(struct kvm_vcpu, arch.cede_time)},
};

-#define N_TIMINGS (sizeof(timings) / sizeof(timings[0]))
+#define N_TIMINGS (ARRAY_SIZE(timings))

struct debugfs_timings_state {
struct kvm_vcpu *vcpu;

2017-09-03 13:14:49

by Tariq Toukan

[permalink] [raw]
Subject: Re: [PATCH 7/10] net/mlx4_core: Use ARRAY_SIZE macro



On 03/09/2017 3:19 PM, 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.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---


Reviewed-by: Tariq Toukan <[email protected]>

Thanks Thomas!

2017-09-03 15:36:06

by Joe Perches

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

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.


2017-09-03 19:59:44

by Thomas Meyer

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

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?

>
> It seems none of those styles exist though.
>

2017-09-03 20:20:44

by Joe Perches

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

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 .

2017-09-05 18:50:47

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

From: Thomas Meyer <[email protected]>
Date: Sun, 03 Sep 2017 14:19:31 +0200

> 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.
>
> Signed-off-by: Thomas Meyer <[email protected]>

This should be submitted to the Intel ethernet driver maintainers.

Thank you.

2017-09-05 18:50:57

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 7/10] net/mlx4_core: Use ARRAY_SIZE macro

From: Thomas Meyer <[email protected]>
Date: Sun, 03 Sep 2017 14:19:31 +0200

> 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.
>
> Signed-off-by: Thomas Meyer <[email protected]>

Applied.

2017-09-05 19:45:20

by Thomas Meyer

[permalink] [raw]
Subject: Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

On Tue, Sep 05, 2017 at 11:50:44AM -0700, David Miller wrote:
> From: Thomas Meyer <[email protected]>
> Date: Sun, 03 Sep 2017 14:19:31 +0200
>
> > 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.
> >
> > Signed-off-by: Thomas Meyer <[email protected]>
>
> This should be submitted to the Intel ethernet driver maintainers.
Hi,

my script checks the output of get_maintainer scripts and only sends to "open
list" entries.

The [email protected] is moderated, so that's why the patch
wasn't send there.

Strangely the lists for [email protected] and
[email protected] appears as open lists in the MAINTAINERS
file but seems to be also moderated lists... At least I got some reply that my
message awaits approval. Maybe an update to the MAINTAINERS file is missing
here?

I may drop above check in my script and send to all mailing lists that
get_maintainer.pl will return.

>
> Thank you.

2017-09-05 20:01:25

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

On Tue, 2017-09-05 at 21:45 +0200, Thomas Meyer wrote:
> On Tue, Sep 05, 2017 at 11:50:44AM -0700, David Miller wrote:
> > From: Thomas Meyer <[email protected]>
> > Date: Sun, 03 Sep 2017 14:19:31 +0200
> >
> > > 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.
> > >
> > > Signed-off-by: Thomas Meyer <[email protected]>
> >
> > This should be submitted to the Intel ethernet driver maintainers.
>
> Hi,
>
> my script checks the output of get_maintainer scripts and only sends to "open
> list" entries.
>
> The [email protected] is moderated, so that's why the patch
> wasn't send there.
>
> Strangely the lists for [email protected] and
> [email protected] appears as open lists in the MAINTAINERS
> file but seems to be also moderated lists... At least I got some reply that my
> message awaits approval. Maybe an update to the MAINTAINERS file is missing
> here?
>
> I may drop above check in my script and send to all mailing lists that
> get_maintainer.pl will return.

There's a difference between moderated and subscriber-only
entries in MAINTAINERS.

get_maintainers will by default list moderated lists and
not show subscriber-only lists unless using the -s switch.

2017-09-05 21:22:13

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

From: Joe Perches <[email protected]>
Date: Tue, 05 Sep 2017 13:01:18 -0700

> On Tue, 2017-09-05 at 21:45 +0200, Thomas Meyer wrote:
>> On Tue, Sep 05, 2017 at 11:50:44AM -0700, David Miller wrote:
>> > From: Thomas Meyer <[email protected]>
>> > Date: Sun, 03 Sep 2017 14:19:31 +0200
>> >
>> > > 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.
>> > >
>> > > Signed-off-by: Thomas Meyer <[email protected]>
>> >
>> > This should be submitted to the Intel ethernet driver maintainers.
>>
>> Hi,
>>
>> my script checks the output of get_maintainer scripts and only sends to "open
>> list" entries.
>>
>> The [email protected] is moderated, so that's why the patch
>> wasn't send there.
>>
>> Strangely the lists for [email protected] and
>> [email protected] appears as open lists in the MAINTAINERS
>> file but seems to be also moderated lists... At least I got some reply that my
>> message awaits approval. Maybe an update to the MAINTAINERS file is missing
>> here?
>>
>> I may drop above check in my script and send to all mailing lists that
>> get_maintainer.pl will return.
>
> There's a difference between moderated and subscriber-only
> entries in MAINTAINERS.
>
> get_maintainers will by default list moderated lists and
> not show subscriber-only lists unless using the -s switch.

Furthermore, nothing prevented you from CC:'ing the maintainer,
Jeff Kirscher.

2017-09-06 09:08:24

by Thomas Meyer

[permalink] [raw]
Subject: Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

On Tue, Sep 05, 2017 at 02:22:05PM -0700, David Miller wrote:
> From: Joe Perches <[email protected]>
> Date: Tue, 05 Sep 2017 13:01:18 -0700
>
> > On Tue, 2017-09-05 at 21:45 +0200, Thomas Meyer wrote:
> >> On Tue, Sep 05, 2017 at 11:50:44AM -0700, David Miller wrote:
> >> > From: Thomas Meyer <[email protected]>
> >> > Date: Sun, 03 Sep 2017 14:19:31 +0200
> >> >
> >> > > 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.
> >> > >
> >> > > Signed-off-by: Thomas Meyer <[email protected]>
> >> >
> >> > This should be submitted to the Intel ethernet driver maintainers.
> >>
> >> Hi,
> >>
> >> my script checks the output of get_maintainer scripts and only sends to "open
> >> list" entries.
> >>
> >> The [email protected] is moderated, so that's why the patch
> >> wasn't send there.
> >>
> >> Strangely the lists for [email protected] and
> >> [email protected] appears as open lists in the MAINTAINERS
> >> file but seems to be also moderated lists... At least I got some reply that my
> >> message awaits approval. Maybe an update to the MAINTAINERS file is missing
> >> here?
> >>
> >> I may drop above check in my script and send to all mailing lists that
> >> get_maintainer.pl will return.
> >
> > There's a difference between moderated and subscriber-only
> > entries in MAINTAINERS.
> >
> > get_maintainers will by default list moderated lists and
> > not show subscriber-only lists unless using the -s switch.
>
> Furthermore, nothing prevented you from CC:'ing the maintainer,
> Jeff Kirscher.

Hi,

That's the other condition in my script. I only send to the role
"maintainer" from the output of get_maintainer.pl. But Mr Jeff
Kirscher is only listed as supporter...

Anyway I did bounce the email to him.

with kind regards
thomas

2017-09-06 15:19:26

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 6/10] ixgbe: Use ARRAY_SIZE macro

On Wed, 2017-09-06 at 11:08 +0200, Thomas Meyer wrote:
> On Tue, Sep 05, 2017 at 02:22:05PM -0700, David Miller wrote:
> > nothing prevented you from CC:'ing the maintainer,
> > Jeff Kirscher.
[]
> That's the other condition in my script. I only send to the role
> "maintainer" from the output of get_maintainer.pl. But Mr Jeff
> Kirscher is only listed as supporter...

Supporter means he gets paid to look after that
subsystem so he is something other than a volunteer.

from MAINTAINERS:
S: Status, one of the following:
???Supported: Someone is actually paid to look after this.
???Maintained: Someone actually looks after it.
???Odd Fixes: It has a maintainer but they don't have time to do
much other than throw the odd patch in. See below..
???Orphan: No current maintainer [but maybe you could take the
role as you write your new code].
???Obsolete: Old code. Something tagged obsolete generally means
it has been replaced by a better system and you
should be using that.

2017-09-25 07:15:32

by Kalle Valo

[permalink] [raw]
Subject: Re: [8/10] ath9k: Use ARRAY_SIZE macro

Thomas Meyer <[email protected]> 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.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> Signed-off-by: Kalle Valo <[email protected]>

Patch applied to ath-next branch of ath.git, thanks.

896cbefadf62 ath9k: Use ARRAY_SIZE macro

--
https://patchwork.kernel.org/patch/9936271/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches