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


Groups > linux.kernel > #1742863 > unrolled thread

[PATCH 00/18] use ARRAY_SIZE macro

Started byJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
First post2017-10-01 21:40 +0200
Last post2017-10-02 15:10 +0200
Articles 20 on this page of 29 — 12 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 04/18] IB/mlx5: Use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 12/18] x86: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 02/18] tracing/filter: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 16/18] media: staging: atomisp: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 06/18] drm: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
      Re: [PATCH 06/18] drm: use ARRAY_SIZE Jani Nikula <jani.nikula@linux.intel.com> - 2017-10-02 09:50 +0200
      Re: [PATCH 06/18] drm: use ARRAY_SIZE Thierry Reding <thierry.reding@gmail.com> - 2017-10-02 10:30 +0200
    [PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 15/18] acpi: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
      Re: [PATCH 15/18] acpi: use ARRAY_SIZE "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-10-02 14:40 +0200
    [PATCH 01/18] sound: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
      Re: [PATCH 01/18] sound: use ARRAY_SIZE Joe Perches <joe@perches.com> - 2017-10-02 06:20 +0200
    [PATCH 09/18] nfsd: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
      Re: [PATCH 09/18] nfsd: use ARRAY_SIZE Jeff Layton <jlayton@redhat.com> - 2017-10-02 13:10 +0200
    [PATCH 08/18] ecryptfs: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 03/18] media: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
      Re: [PATCH 03/18] media: use ARRAY_SIZE Michael Ira Krufky <mkrufky@linuxtv.org> - 2017-10-02 12:40 +0200
    [PATCH 14/18] ipmi: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 07/18] scsi: bfa: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 17/18] staging: rtl8723bs: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 10/18] orangefs: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 13/18] tpm: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    [PATCH 11/18] dm space map metadata: use ARRAY_SIZE Jérémy Lefaure          <jeremy.lefaure@lse.epita.fr> - 2017-10-01 21:40 +0200
    Re: [PATCH 00/18] use ARRAY_SIZE macro "Tobin C. Harding" <me@tobin.cc> - 2017-10-02 00:10 +0200
      Re: [PATCH 00/18] use ARRAY_SIZE macro Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> - 2017-10-02 03:00 +0200
        Re: [PATCH 00/18] use ARRAY_SIZE macro Greg KH <greg@kroah.com> - 2017-10-02 07:40 +0200
        Re: [PATCH 00/18] use ARRAY_SIZE macro Mauro Carvalho Chehab <mchehab@s-opensource.com> - 2017-10-02 22:50 +0200
    Re: [PATCH 05/18] net: use ARRAY_SIZE Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-10-02 15:10 +0200

Page 1 of 2  [1] 2  Next page →


#1742863 — [PATCH 00/18] use ARRAY_SIZE macro

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 00/18] use ARRAY_SIZE macro
Message-ID<uvSfL-67y-3@gated-at.bofh.it>
Hi everyone,
Using ARRAY_SIZE improves the code readability. I used coccinelle (I
made a change to the array_size.cocci file [1]) to find several places
where ARRAY_SIZE could be used instead of other macros or sizeof
division.

I tried to divide the changes into a patch per subsystem (excepted for
staging). If one of the patch should be split into several patches, let
me know.

In order to reduce the size of the To: and Cc: lines, each patch of the
series is sent only to the maintainers and lists concerned by the patch.
This cover letter is sent to every list concerned by this series.

This series is based on linux-next next-20170929. Each patch has been
tested by building the relevant files with W=1.

This series contains the following patches:
[PATCH 01/18] sound: use ARRAY_SIZE
[PATCH 02/18] tracing/filter: use ARRAY_SIZE
[PATCH 03/18] media: use ARRAY_SIZE
[PATCH 04/18] IB/mlx5: Use ARRAY_SIZE
[PATCH 05/18] net: use ARRAY_SIZE
[PATCH 06/18] drm: use ARRAY_SIZE
[PATCH 07/18] scsi: bfa: use ARRAY_SIZE
[PATCH 08/18] ecryptfs: use ARRAY_SIZE
[PATCH 09/18] nfsd: use ARRAY_SIZE
[PATCH 10/18] orangefs: use ARRAY_SIZE
[PATCH 11/18] dm space map metadata: use ARRAY_SIZE
[PATCH 12/18] x86: use ARRAY_SIZE
[PATCH 13/18] tpm: use ARRAY_SIZE
[PATCH 14/18] ipmi: use ARRAY_SIZE
[PATCH 15/18] acpi: use ARRAY_SIZE
[PATCH 16/18] media: staging: atomisp: use ARRAY_SIZE
[PATCH 17/18] staging: rtl8723bs: use ARRAY_SIZE
[PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE


[1]: https://lkml.org/lkml/2017/9/13/689

[toc] | [next] | [standalone]


#1742864 — [PATCH 04/18] IB/mlx5: Use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 04/18] IB/mlx5: Use ARRAY_SIZE
Message-ID<uvSfM-67y-15@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/infiniband/hw/mlx5/odp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
index 3d701c7a4c91..e2197bdda89c 100644
--- a/drivers/infiniband/hw/mlx5/odp.c
+++ b/drivers/infiniband/hw/mlx5/odp.c
@@ -32,6 +32,7 @@
 
 #include <rdma/ib_umem.h>
 #include <rdma/ib_umem_odp.h>
+#include <linux/kernel.h>
 
 #include "mlx5_ib.h"
 #include "cmd.h"
@@ -929,9 +930,8 @@ 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]) ||
-	    !(transport_caps & mlx5_ib_odp_opcode_cap[opcode]))) {
+	if (unlikely(opcode >= ARRAY_SIZE(mlx5_ib_odp_opcode_cap) ||
+		     !(transport_caps & mlx5_ib_odp_opcode_cap[opcode]))) {
 		mlx5_ib_err(dev, "ODP fault on QP of an unsupported opcode 0x%x\n",
 			    opcode);
 		return -EFAULT;
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742865 — [PATCH 12/18] x86: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 12/18] x86: use ARRAY_SIZE
Message-ID<uvSfL-67y-11@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is not always useful to use a variable to store this constant
calculated at compile time.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 arch/x86/boot/video-vga.c                                    | 6 +++---
 arch/x86/entry/vdso/vdso2c.c                                 | 3 ++-
 arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c | 5 ++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/boot/video-vga.c b/arch/x86/boot/video-vga.c
index 45bc9402aa49..a14c5178d4ba 100644
--- a/arch/x86/boot/video-vga.c
+++ b/arch/x86/boot/video-vga.c
@@ -241,9 +241,9 @@ static int vga_probe(void)
 		vga_modes,
 	};
 	static int mode_count[] = {
-		sizeof(cga_modes)/sizeof(struct mode_info),
-		sizeof(ega_modes)/sizeof(struct mode_info),
-		sizeof(vga_modes)/sizeof(struct mode_info),
+		ARRAY_SIZE(cga_modes),
+		ARRAY_SIZE(ega_modes),
+		ARRAY_SIZE(vga_modes),
 	};
 
 	struct biosregs ireg, oreg;
diff --git a/arch/x86/entry/vdso/vdso2c.c b/arch/x86/entry/vdso/vdso2c.c
index 0780a443a53b..4674f58581a1 100644
--- a/arch/x86/entry/vdso/vdso2c.c
+++ b/arch/x86/entry/vdso/vdso2c.c
@@ -65,6 +65,7 @@
 
 #include <linux/elf.h>
 #include <linux/types.h>
+#include <linux/kernel.h>
 
 const char *outfilename;
 
@@ -151,7 +152,7 @@ extern void bad_put_le(void);
 	PLE(x, val, 64, PLE(x, val, 32, PLE(x, val, 16, LAST_PLE(x, val))))
 
 
-#define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
+#define NSYMS ARRAY_SIZE(required_syms)
 
 #define BITSFUNC3(name, bits, suffix) name##bits##suffix
 #define BITSFUNC2(name, bits, suffix) BITSFUNC3(name, bits, suffix)
diff --git a/arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c b/arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c
index 74283875c7e8..e639e3116acf 100644
--- a/arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c
+++ b/arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c
@@ -62,10 +62,9 @@ static struct platform_device pb_device = {
 static int __init pb_keys_init(void)
 {
 	struct gpio_keys_button *gb = gpio_button;
-	int i, num, good = 0;
+	int i, good = 0;
 
-	num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
-	for (i = 0; i < num; i++) {
+	for (i = 0; i < ARRAY_SIZE(gpio_button); i++) {
 		gb[i].gpio = get_gpio_by_name(gb[i].desc);
 		pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
 					gb[i].gpio);
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742866 — [PATCH 02/18] tracing/filter: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 02/18] tracing/filter: use ARRAY_SIZE
Message-ID<uvSfM-67y-17@gated-at.bofh.it>
In reply to#1742863
It is useless to re-invent the ARRAY_SIZE macro so let's use it instead
of DATA_CNT.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 kernel/trace/trace_events_filter.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 61e7f0678d33..02d0f378dc5c 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -23,6 +23,7 @@
 #include <linux/mutex.h>
 #include <linux/perf_event.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 
 #include "trace.h"
 #include "trace_output.h"
@@ -2376,8 +2377,6 @@ static struct test_filter_data_t {
 #undef YES
 #undef NO
 
-#define DATA_CNT (sizeof(test_filter_data)/sizeof(struct test_filter_data_t))
-
 static int test_pred_visited;
 
 static int test_pred_visited_fn(struct filter_pred *pred, void *event)
@@ -2417,7 +2416,7 @@ static __init int ftrace_test_event_filter(void)
 
 	printk(KERN_INFO "Testing ftrace filter: ");
 
-	for (i = 0; i < DATA_CNT; i++) {
+	for (i = 0; i < ARRAY_SIZE(test_filter_data); i++) {
 		struct event_filter *filter = NULL;
 		struct test_filter_data_t *d = &test_filter_data[i];
 		int err;
@@ -2463,7 +2462,7 @@ static __init int ftrace_test_event_filter(void)
 		}
 	}
 
-	if (i == DATA_CNT)
+	if (i == ARRAY_SIZE(test_filter_data))
 		printk(KERN_CONT "OK\n");
 
 	return 0;
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742867 — [PATCH 16/18] media: staging: atomisp: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 16/18] media: staging: atomisp: use ARRAY_SIZE
Message-ID<uvSfM-67y-21@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to use a variable to store this constant calculated at
compile time.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 .../pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c       | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
index 17d3b7de93ba..98a2a3e9b3e6 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
@@ -22,6 +22,7 @@
 #include <assert_support.h>
 /* HRT_GDC_N */
 #include "gdc_device.h"
+#include <linux/kernel.h>
 
 /* This module provides a binary descriptions to used to find a binary. Since,
  * every stage is associated with a binary, it implicity helps stage
@@ -147,11 +148,9 @@ enum ia_css_err sh_css_bds_factor_get_numerator_denominator(
 	unsigned int *bds_factor_denominator)
 {
 	unsigned int i;
-	unsigned int bds_list_size = sizeof(bds_factors_list) /
-				sizeof(struct sh_css_bds_factor);
 
 	/* Loop over all bds factors until a match is found */
-	for (i = 0; i < bds_list_size; i++) {
+	for (i = 0; i < ARRAY_SIZE(bds_factors_list); i++) {
 		if (bds_factors_list[i].bds_factor == bds_factor) {
 			*bds_factor_numerator = bds_factors_list[i].numerator;
 			*bds_factor_denominator = bds_factors_list[i].denominator;
@@ -170,8 +169,6 @@ enum ia_css_err binarydesc_calculate_bds_factor(
 	unsigned int *bds_factor)
 {
 	unsigned int i;
-	unsigned int bds_list_size = sizeof(bds_factors_list) /
-	    sizeof(struct sh_css_bds_factor);
 	unsigned int in_w = input_res.width,
 	    in_h = input_res.height,
 	    out_w = output_res.width, out_h = output_res.height;
@@ -186,7 +183,7 @@ enum ia_css_err binarydesc_calculate_bds_factor(
 	assert(out_w != 0 && out_h != 0);
 
 	/* Loop over all bds factors until a match is found */
-	for (i = 0; i < bds_list_size; i++) {
+	for (i = 0; i < ARRAY_SIZE(bds_factors_list); i++) {
 		unsigned num = bds_factors_list[i].numerator;
 		unsigned den = bds_factors_list[i].denominator;
 
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742868 — [PATCH 06/18] drm: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 06/18] drm: use ARRAY_SIZE
Message-ID<uvSfM-67y-19@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is not always useful to use a variable to store this constant
calculated at compile time nor to re-invent the ARRAY_SIZE macro.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c           |  9 +++++----
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c           |  9 +++++----
 drivers/gpu/drm/gma500/psb_intel_sdvo.c         |  9 ++++-----
 drivers/gpu/drm/i915/gvt/vgpu.c                 |  3 ++-
 drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c |  7 ++++---
 drivers/gpu/drm/via/via_verifier.c              | 10 ++++------
 6 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index dfc10b1baea0..304862e2a8a6 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -20,6 +20,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  *
  */
+#include <linux/kernel.h>
 #include <linux/firmware.h>
 #include <drm/drmP.h>
 #include "amdgpu.h"
@@ -3952,10 +3953,10 @@ static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
 				adev->gfx.rlc.reg_list_format_size_bytes >> 2,
 				unique_indices,
 				&indices_count,
-				sizeof(unique_indices) / sizeof(int),
+				ARRAY_SIZE(unique_indices),
 				indirect_start_offsets,
 				&offset_count,
-				sizeof(indirect_start_offsets)/sizeof(int));
+				ARRAY_SIZE(indirect_start_offsets));
 
 	/* save and restore list */
 	WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
@@ -3977,14 +3978,14 @@ static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
 	/* starting offsets starts */
 	WREG32(mmRLC_GPM_SCRATCH_ADDR,
 		adev->gfx.rlc.starting_offsets_start);
-	for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
+	for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
 		WREG32(mmRLC_GPM_SCRATCH_DATA,
 				indirect_start_offsets[i]);
 
 	/* unique indices */
 	temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
 	data = mmRLC_SRM_INDEX_CNTL_DATA_0;
-	for (i = 0; i < sizeof(unique_indices) / sizeof(int); i++) {
+	for (i = 0; i < ARRAY_SIZE(unique_indices); i++) {
 		if (unique_indices[i] != 0) {
 			WREG32(temp + i, unique_indices[i] & 0x3FFFF);
 			WREG32(data + i, unique_indices[i] >> 20);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index deeaee1457ef..180726f4f34e 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -20,6 +20,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  *
  */
+#include <linux/kernel.h>
 #include <linux/firmware.h>
 #include <drm/drmP.h>
 #include "amdgpu.h"
@@ -1730,10 +1731,10 @@ static int gfx_v9_0_init_rlc_save_restore_list(struct amdgpu_device *adev)
 				adev->gfx.rlc.reg_list_format_size_bytes >> 2,
 				unique_indirect_regs,
 				&unique_indirect_reg_count,
-				sizeof(unique_indirect_regs)/sizeof(int),
+				ARRAY_SIZE(unique_indirect_regs),
 				indirect_start_offsets,
 				&indirect_start_offsets_count,
-				sizeof(indirect_start_offsets)/sizeof(int));
+				ARRAY_SIZE(indirect_start_offsets));
 
 	/* enable auto inc in case it is disabled */
 	tmp = RREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_CNTL));
@@ -1770,12 +1771,12 @@ static int gfx_v9_0_init_rlc_save_restore_list(struct amdgpu_device *adev)
 	/* write the starting offsets to RLC scratch ram */
 	WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_GPM_SCRATCH_ADDR),
 		adev->gfx.rlc.starting_offsets_start);
-	for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
+	for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
 		WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_GPM_SCRATCH_DATA),
 			indirect_start_offsets[i]);
 
 	/* load unique indirect regs*/
-	for (i = 0; i < sizeof(unique_indirect_regs)/sizeof(int); i++) {
+	for (i = 0; i < ARRAY_SIZE(unique_indirect_regs); i++) {
 		WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_ADDR_0) + i,
 			unique_indirect_regs[i] & 0x3FFFF);
 		WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_DATA_0) + i,
diff --git a/drivers/gpu/drm/gma500/psb_intel_sdvo.c b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
index e787d376ba67..84507912be84 100644
--- a/drivers/gpu/drm/gma500/psb_intel_sdvo.c
+++ b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
@@ -37,6 +37,7 @@
 #include "psb_drv.h"
 #include "psb_intel_sdvo_regs.h"
 #include "psb_intel_reg.h"
+#include <linux/kernel.h>
 
 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
 #define SDVO_RGB_MASK  (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
@@ -62,8 +63,6 @@ static const char *tv_format_names[] = {
 	"SECAM_60"
 };
 
-#define TV_FORMAT_NUM  (sizeof(tv_format_names) / sizeof(*tv_format_names))
-
 struct psb_intel_sdvo {
 	struct gma_encoder base;
 
@@ -148,7 +147,7 @@ struct psb_intel_sdvo_connector {
 	int force_audio;
 
 	/* This contains all current supported TV format */
-	u8 tv_format_supported[TV_FORMAT_NUM];
+	u8 tv_format_supported[ARRAY_SIZE(tv_format_names)];
 	int   format_supported_num;
 	struct drm_property *tv_format;
 
@@ -1709,7 +1708,7 @@ psb_intel_sdvo_set_property(struct drm_connector *connector,
 	}
 
 	if (property == psb_intel_sdvo_connector->tv_format) {
-		if (val >= TV_FORMAT_NUM)
+		if (val >= ARRAY_SIZE(tv_format_names))
 			return -EINVAL;
 
 		if (psb_intel_sdvo->tv_format_index ==
@@ -2269,7 +2268,7 @@ static bool psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo *psb_intel_s
 		return false;
 
 	psb_intel_sdvo_connector->format_supported_num = 0;
-	for (i = 0 ; i < TV_FORMAT_NUM; i++)
+	for (i = 0 ; i < ARRAY_SIZE(tv_format_names); i++)
 		if (format_map & (1 << i))
 			psb_intel_sdvo_connector->tv_format_supported[psb_intel_sdvo_connector->format_supported_num++] = i;
 
diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 02c61a1ad56a..9c6d2849c5b7 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -31,6 +31,7 @@
  *
  */
 
+#include <linux/kernel.h>
 #include "i915_drv.h"
 #include "gvt.h"
 #include "i915_pvinfo.h"
@@ -116,7 +117,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);
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c
index b58ee99f7bfc..9cc10e438b3d 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c
@@ -36,6 +36,8 @@
 #include <subdev/i2c.h>
 #include <subdev/vga.h>
 
+#include <linux/kernel.h>
+
 #define bioslog(lvl, fmt, args...) do {                                        \
 	nvkm_printk(init->subdev, lvl, info, "0x%08x[%c]: "fmt,                \
 		    init->offset, init_exec(init) ?                            \
@@ -2271,8 +2273,6 @@ static struct nvbios_init_opcode {
 	[0xaa] = { init_reserved },
 };
 
-#define init_opcode_nr (sizeof(init_opcode) / sizeof(init_opcode[0]))
-
 int
 nvbios_exec(struct nvbios_init *init)
 {
@@ -2281,7 +2281,8 @@ nvbios_exec(struct nvbios_init *init)
 	init->nested++;
 	while (init->offset) {
 		u8 opcode = nvbios_rd08(bios, init->offset);
-		if (opcode >= init_opcode_nr || !init_opcode[opcode].exec) {
+		if (opcode >= ARRAY_SIZE(init_opcode) ||
+		    !init_opcode[opcode].exec) {
 			error("unknown opcode 0x%02x\n", opcode);
 			return -EINVAL;
 		}
diff --git a/drivers/gpu/drm/via/via_verifier.c b/drivers/gpu/drm/via/via_verifier.c
index 0677bbf4ec7e..fb2609434df7 100644
--- a/drivers/gpu/drm/via/via_verifier.c
+++ b/drivers/gpu/drm/via/via_verifier.c
@@ -34,6 +34,7 @@
 #include <drm/drm_legacy.h>
 #include "via_verifier.h"
 #include "via_drv.h"
+#include <linux/kernel.h>
 
 typedef enum {
 	state_command,
@@ -1102,10 +1103,7 @@ setup_hazard_table(hz_init_t init_table[], hazard_t table[], int size)
 
 void via_init_command_verifier(void)
 {
-	setup_hazard_table(init_table1, table1,
-			   sizeof(init_table1) / sizeof(hz_init_t));
-	setup_hazard_table(init_table2, table2,
-			   sizeof(init_table2) / sizeof(hz_init_t));
-	setup_hazard_table(init_table3, table3,
-			   sizeof(init_table3) / sizeof(hz_init_t));
+	setup_hazard_table(init_table1, table1, ARRAY_SIZE(init_table1));
+	setup_hazard_table(init_table2, table2, ARRAY_SIZE(init_table2));
+	setup_hazard_table(init_table3, table3, ARRAY_SIZE(init_table3));
 }
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742999 — Re: [PATCH 06/18] drm: use ARRAY_SIZE

FromJani Nikula <jani.nikula@linux.intel.com>
Date2017-10-02 09:50 +0200
SubjectRe: [PATCH 06/18] drm: use ARRAY_SIZE
Message-ID<uw3Ed-4x1-3@gated-at.bofh.it>
In reply to#1742868
On Sun, 01 Oct 2017, Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. Also,
> it is not always useful to use a variable to store this constant
> calculated at compile time nor to re-invent the ARRAY_SIZE macro.
>
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> |
>  (sizeof(E)@p /sizeof(E[...]))
> |
>  (sizeof(E)@p /sizeof(T))
> )
>
> Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>

Please split this up.

Patch 1:
>  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c           |  9 +++++----
>  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c           |  9 +++++----

Patch 2:
>  drivers/gpu/drm/gma500/psb_intel_sdvo.c         |  9 ++++-----

Patch 3:
>  drivers/gpu/drm/i915/gvt/vgpu.c                 |  3 ++-

Patch 4:
>  drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c |  7 ++++---

Patch 5:
>  drivers/gpu/drm/via/via_verifier.c              | 10 ++++------

BR,
Jani.

-- 
Jani Nikula, Intel Open Source Technology Center

[toc] | [prev] | [next] | [standalone]


#1743011 — Re: [PATCH 06/18] drm: use ARRAY_SIZE

FromThierry Reding <thierry.reding@gmail.com>
Date2017-10-02 10:30 +0200
SubjectRe: [PATCH 06/18] drm: use ARRAY_SIZE
Message-ID<uw4gV-4Z8-1@gated-at.bofh.it>
In reply to#1742868

[Multipart message — attachments visible in raw view] — view raw

On Sun, Oct 01, 2017 at 03:30:44PM -0400, Jérémy Lefaure wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. Also,
> it is not always useful to use a variable to store this constant
> calculated at compile time nor to re-invent the ARRAY_SIZE macro.
> 
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> |
>  (sizeof(E)@p /sizeof(E[...]))
> |
>  (sizeof(E)@p /sizeof(T))
> )
> 
> Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
> ---
>  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c           |  9 +++++----
>  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c           |  9 +++++----
>  drivers/gpu/drm/gma500/psb_intel_sdvo.c         |  9 ++++-----
>  drivers/gpu/drm/i915/gvt/vgpu.c                 |  3 ++-
>  drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c |  7 ++++---
>  drivers/gpu/drm/via/via_verifier.c              | 10 ++++------
>  6 files changed, 24 insertions(+), 23 deletions(-)

Reviewed-by: Thierry Reding <treding@nvidia.com>

[toc] | [prev] | [next] | [standalone]


#1742869 — [PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE
Message-ID<uvSfM-67y-23@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to use a variable to store this constant calculated at
compile time.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/staging/rtlwifi/phydm/phydm_debug.c                |  4 ++--
 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c  | 10 ++++------
 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c |  4 ++--
 drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c  | 13 +++++--------
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/rtlwifi/phydm/phydm_debug.c b/drivers/staging/rtlwifi/phydm/phydm_debug.c
index a5f90afdae9b..d4dd0fd3d1c7 100644
--- a/drivers/staging/rtlwifi/phydm/phydm_debug.c
+++ b/drivers/staging/rtlwifi/phydm/phydm_debug.c
@@ -29,6 +29,7 @@
 
 #include "mp_precomp.h"
 #include "phydm_precomp.h"
+#include <linux/kernel.h>
 
 bool phydm_api_set_txagc(struct phy_dm_struct *, u32, enum odm_rf_radio_path,
 			 u8, bool);
@@ -2107,8 +2108,7 @@ void phydm_cmd_parser(struct phy_dm_struct *dm, char input[][MAX_ARGV],
 
 	/* Parsing Cmd ID */
 	if (input_num) {
-		phydm_ary_size =
-			sizeof(phy_dm_ary) / sizeof(struct phydm_command);
+		phydm_ary_size = ARRAY_SIZE(phy_dm_ary);
 		for (i = 0; i < phydm_ary_size; i++) {
 			if (strcmp(phy_dm_ary[i].name, input[0]) == 0) {
 				id = phy_dm_ary[i].id;
diff --git a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c
index 4e7946019fcb..29d19f2b300e 100644
--- a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c
+++ b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c
@@ -26,6 +26,7 @@
 /*Image2HeaderVersion: 3.2*/
 #include "../mp_precomp.h"
 #include "../phydm_precomp.h"
+#include <linux/kernel.h>
 
 static bool check_positive(struct phy_dm_struct *dm, const u32 condition1,
 			   const u32 condition2, const u32 condition3,
@@ -1350,7 +1351,6 @@ void odm_read_and_config_mp_8822b_agc_tab(struct phy_dm_struct *dm)
 	u32 i = 0;
 	u8 c_cond;
 	bool is_matched = true, is_skipped = false;
-	u32 array_len = sizeof(array_mp_8822b_agc_tab) / sizeof(u32);
 	u32 *array = array_mp_8822b_agc_tab;
 
 	u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
@@ -1358,7 +1358,7 @@ void odm_read_and_config_mp_8822b_agc_tab(struct phy_dm_struct *dm)
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> %s\n", __func__);
 
-	for (; (i + 1) < array_len; i = i + 2) {
+	for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_agc_tab); i = i + 2) {
 		v1 = array[i];
 		v2 = array[i + 1];
 
@@ -1843,7 +1843,6 @@ void odm_read_and_config_mp_8822b_phy_reg(struct phy_dm_struct *dm)
 	u32 i = 0;
 	u8 c_cond;
 	bool is_matched = true, is_skipped = false;
-	u32 array_len = sizeof(array_mp_8822b_phy_reg) / sizeof(u32);
 	u32 *array = array_mp_8822b_phy_reg;
 
 	u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
@@ -1851,7 +1850,7 @@ void odm_read_and_config_mp_8822b_phy_reg(struct phy_dm_struct *dm)
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> %s\n", __func__);
 
-	for (; (i + 1) < array_len; i = i + 2) {
+	for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_phy_reg); i = i + 2) {
 		v1 = array[i];
 		v2 = array[i + 1];
 
@@ -1947,7 +1946,6 @@ static u32 array_mp_8822b_phy_reg_pg[] = {
 void odm_read_and_config_mp_8822b_phy_reg_pg(struct phy_dm_struct *dm)
 {
 	u32 i = 0;
-	u32 array_len = sizeof(array_mp_8822b_phy_reg_pg) / sizeof(u32);
 	u32 *array = array_mp_8822b_phy_reg_pg;
 
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
@@ -1956,7 +1954,7 @@ void odm_read_and_config_mp_8822b_phy_reg_pg(struct phy_dm_struct *dm)
 	dm->phy_reg_pg_version = 1;
 	dm->phy_reg_pg_value_type = PHY_REG_PG_EXACT_VALUE;
 
-	for (i = 0; i < array_len; i += 6) {
+	for (i = 0; i < ARRAY_SIZE(array_mp_8822b_phy_reg_pg); i += 6) {
 		u32 v1 = array[i];
 		u32 v2 = array[i + 1];
 		u32 v3 = array[i + 2];
diff --git a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c
index 1a9daed2e609..70924f002541 100644
--- a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c
+++ b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c
@@ -26,6 +26,7 @@
 /*Image2HeaderVersion: 3.2*/
 #include "../mp_precomp.h"
 #include "../phydm_precomp.h"
+#include <linux/kernel.h>
 
 static bool check_positive(struct phy_dm_struct *dm, const u32 condition1,
 			   const u32 condition2, const u32 condition3,
@@ -173,7 +174,6 @@ void odm_read_and_config_mp_8822b_mac_reg(struct phy_dm_struct *dm)
 	u32 i = 0;
 	u8 c_cond;
 	bool is_matched = true, is_skipped = false;
-	u32 array_len = sizeof(array_mp_8822b_mac_reg) / sizeof(u32);
 	u32 *array = array_mp_8822b_mac_reg;
 
 	u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
@@ -181,7 +181,7 @@ void odm_read_and_config_mp_8822b_mac_reg(struct phy_dm_struct *dm)
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> %s\n", __func__);
 
-	for (; (i + 1) < array_len; i = i + 2) {
+	for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_mac_reg); i = i + 2) {
 		v1 = array[i];
 		v2 = array[i + 1];
 
diff --git a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c
index 84cdc0644207..0ff3a9a712d6 100644
--- a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c
+++ b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c
@@ -26,6 +26,7 @@
 /*Image2HeaderVersion: 3.2*/
 #include "../mp_precomp.h"
 #include "../phydm_precomp.h"
+#include <linux/kernel.h>
 
 static bool check_positive(struct phy_dm_struct *dm, const u32 condition1,
 			   const u32 condition2, const u32 condition3,
@@ -1346,7 +1347,6 @@ void odm_read_and_config_mp_8822b_radioa(struct phy_dm_struct *dm)
 	u32 i = 0;
 	u8 c_cond;
 	bool is_matched = true, is_skipped = false;
-	u32 array_len = sizeof(array_mp_8822b_radioa) / sizeof(u32);
 	u32 *array = array_mp_8822b_radioa;
 
 	u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
@@ -1354,7 +1354,7 @@ void odm_read_and_config_mp_8822b_radioa(struct phy_dm_struct *dm)
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> %s\n", __func__);
 
-	for (; (i + 1) < array_len; i = i + 2) {
+	for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_radioa); i = i + 2) {
 		v1 = array[i];
 		v2 = array[i + 1];
 
@@ -2506,7 +2506,6 @@ void odm_read_and_config_mp_8822b_radiob(struct phy_dm_struct *dm)
 	u32 i = 0;
 	u8 c_cond;
 	bool is_matched = true, is_skipped = false;
-	u32 array_len = sizeof(array_mp_8822b_radiob) / sizeof(u32);
 	u32 *array = array_mp_8822b_radiob;
 
 	u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0;
@@ -2514,7 +2513,7 @@ void odm_read_and_config_mp_8822b_radiob(struct phy_dm_struct *dm)
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> %s\n", __func__);
 
-	for (; (i + 1) < array_len; i = i + 2) {
+	for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_radiob); i = i + 2) {
 		v1 = array[i];
 		v2 = array[i + 1];
 
@@ -4239,13 +4238,12 @@ static const char *const array_mp_8822b_txpwr_lmt[] = {
 void odm_read_and_config_mp_8822b_txpwr_lmt(struct phy_dm_struct *dm)
 {
 	u32 i = 0;
-	u32 array_len = sizeof(array_mp_8822b_txpwr_lmt) / sizeof(u8 *);
 	u8 **array = (u8 **)array_mp_8822b_txpwr_lmt;
 
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> %s\n", __func__);
 
-	for (i = 0; i < array_len; i += 7) {
+	for (i = 0; i < ARRAY_SIZE(array_mp_8822b_txpwr_lmt); i += 7) {
 		u8 *regulation = array[i];
 		u8 *band = array[i + 1];
 		u8 *bandwidth = array[i + 2];
@@ -4723,13 +4721,12 @@ static const char *const array_mp_8822b_txpwr_lmt_type5[] = {
 void odm_read_and_config_mp_8822b_txpwr_lmt_type5(struct phy_dm_struct *dm)
 {
 	u32 i = 0;
-	u32 array_len = sizeof(array_mp_8822b_txpwr_lmt_type5) / sizeof(u8 *);
 	u8 **array = (u8 **)array_mp_8822b_txpwr_lmt_type5;
 
 	ODM_RT_TRACE(dm, ODM_COMP_INIT,
 		     "===> odm_read_and_config_mp_8822b_txpwr_lmt_type5\n");
 
-	for (i = 0; i < array_len; i += 7) {
+	for (i = 0; i < ARRAY_SIZE(array_mp_8822b_txpwr_lmt_type5); i += 7) {
 		u8 *regulation = array[i];
 		u8 *band = array[i + 1];
 		u8 *bandwidth = array[i + 2];
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742870 — [PATCH 15/18] acpi: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 15/18] acpi: use ARRAY_SIZE
Message-ID<uvSfM-67y-29@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. It is
useless to re-invent the ARRAY_SIZE macro so let's use it.

It is useless to re-invent the ARRAY_SIZE macro so let's use it.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/acpi/acpica/rsdumpinfo.c | 66 ++++++++++++++++++++--------------------
 drivers/acpi/acpica/tbfadt.c     | 13 +++-----
 2 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/drivers/acpi/acpica/rsdumpinfo.c b/drivers/acpi/acpica/rsdumpinfo.c
index da150e17795b..2cc52720b705 100644
--- a/drivers/acpi/acpica/rsdumpinfo.c
+++ b/drivers/acpi/acpica/rsdumpinfo.c
@@ -41,6 +41,7 @@
  * POSSIBILITY OF SUCH DAMAGES.
  */
 
+#include <linux/kernel.h>
 #include <acpi/acpi.h>
 #include "accommon.h"
 #include "acresrc.h"
@@ -51,7 +52,6 @@ ACPI_MODULE_NAME("rsdumpinfo")
 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUGGER)
 #define ACPI_RSD_OFFSET(f)          (u8) ACPI_OFFSET (union acpi_resource_data,f)
 #define ACPI_PRT_OFFSET(f)          (u8) ACPI_OFFSET (struct acpi_pci_routing_table,f)
-#define ACPI_RSD_TABLE_SIZE(name)   (sizeof(name) / sizeof (struct acpi_rsdump_info))
 /*******************************************************************************
  *
  * Resource Descriptor info tables
@@ -61,7 +61,7 @@ ACPI_MODULE_NAME("rsdumpinfo")
  *
  ******************************************************************************/
 struct acpi_rsdump_info acpi_rs_dump_irq[7] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_irq), "IRQ", NULL},
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_irq), "IRQ", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(irq.descriptor_length),
 	 "Descriptor Length", NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.triggering), "Triggering",
@@ -77,7 +77,7 @@ struct acpi_rsdump_info acpi_rs_dump_irq[7] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_dma[6] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_dma), "DMA", NULL},
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_dma), "DMA", NULL},
 	{ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(dma.type), "Speed",
 	 acpi_gbl_typ_decode},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(dma.bus_master), "Mastering",
@@ -91,7 +91,7 @@ struct acpi_rsdump_info acpi_rs_dump_dma[6] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_start_dpf[4] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_start_dpf),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_start_dpf),
 	 "Start-Dependent-Functions", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(start_dpf.descriptor_length),
 	 "Descriptor Length", NULL},
@@ -102,12 +102,12 @@ struct acpi_rsdump_info acpi_rs_dump_start_dpf[4] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_end_dpf[1] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_end_dpf),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_end_dpf),
 	 "End-Dependent-Functions", NULL}
 };
 
 struct acpi_rsdump_info acpi_rs_dump_io[6] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_io), "I/O", NULL},
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_io), "I/O", NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(io.io_decode), "Address Decoding",
 	 acpi_gbl_io_decode},
 	{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(io.minimum), "Address Minimum", NULL},
@@ -118,7 +118,7 @@ struct acpi_rsdump_info acpi_rs_dump_io[6] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_fixed_io[3] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_io),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_fixed_io),
 	 "Fixed I/O", NULL},
 	{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(fixed_io.address), "Address", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(fixed_io.address_length),
@@ -126,7 +126,7 @@ struct acpi_rsdump_info acpi_rs_dump_fixed_io[3] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_vendor[3] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_vendor),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_vendor),
 	 "Vendor Specific", NULL},
 	{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(vendor.byte_length), "Length", NULL},
 	{ACPI_RSD_LONGLIST, ACPI_RSD_OFFSET(vendor.byte_data[0]), "Vendor Data",
@@ -134,12 +134,12 @@ struct acpi_rsdump_info acpi_rs_dump_vendor[3] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_end_tag[1] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_end_tag), "EndTag",
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_end_tag), "EndTag",
 	 NULL}
 };
 
 struct acpi_rsdump_info acpi_rs_dump_memory24[6] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_memory24),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_memory24),
 	 "24-Bit Memory Range", NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(memory24.write_protect),
 	 "Write Protect", acpi_gbl_rw_decode},
@@ -154,7 +154,7 @@ struct acpi_rsdump_info acpi_rs_dump_memory24[6] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_memory32[6] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_memory32),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_memory32),
 	 "32-Bit Memory Range", NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(memory32.write_protect),
 	 "Write Protect", acpi_gbl_rw_decode},
@@ -169,7 +169,7 @@ struct acpi_rsdump_info acpi_rs_dump_memory32[6] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_fixed_memory32[4] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_memory32),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_fixed_memory32),
 	 "32-Bit Fixed Memory Range", NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(fixed_memory32.write_protect),
 	 "Write Protect", acpi_gbl_rw_decode},
@@ -180,7 +180,7 @@ struct acpi_rsdump_info acpi_rs_dump_fixed_memory32[4] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_address16[8] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_address16),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_address16),
 	 "16-Bit WORD Address Space", NULL},
 	{ACPI_RSD_ADDRESS, 0, NULL, NULL},
 	{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(address16.address.granularity),
@@ -197,7 +197,7 @@ struct acpi_rsdump_info acpi_rs_dump_address16[8] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_address32[8] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_address32),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_address32),
 	 "32-Bit DWORD Address Space", NULL},
 	{ACPI_RSD_ADDRESS, 0, NULL, NULL},
 	{ACPI_RSD_UINT32, ACPI_RSD_OFFSET(address32.address.granularity),
@@ -214,7 +214,7 @@ struct acpi_rsdump_info acpi_rs_dump_address32[8] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_address64[8] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_address64),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_address64),
 	 "64-Bit QWORD Address Space", NULL},
 	{ACPI_RSD_ADDRESS, 0, NULL, NULL},
 	{ACPI_RSD_UINT64, ACPI_RSD_OFFSET(address64.address.granularity),
@@ -231,7 +231,7 @@ struct acpi_rsdump_info acpi_rs_dump_address64[8] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_ext_address64[8] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_ext_address64),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_ext_address64),
 	 "64-Bit Extended Address Space", NULL},
 	{ACPI_RSD_ADDRESS, 0, NULL, NULL},
 	{ACPI_RSD_UINT64, ACPI_RSD_OFFSET(ext_address64.address.granularity),
@@ -250,7 +250,7 @@ struct acpi_rsdump_info acpi_rs_dump_ext_address64[8] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_ext_irq[8] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_ext_irq),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_ext_irq),
 	 "Extended IRQ", NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(extended_irq.producer_consumer),
 	 "Type", acpi_gbl_consume_decode},
@@ -269,7 +269,7 @@ struct acpi_rsdump_info acpi_rs_dump_ext_irq[8] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_generic_reg[6] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_generic_reg),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_generic_reg),
 	 "Generic Register", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(generic_reg.space_id), "Space ID",
 	 NULL},
@@ -283,7 +283,7 @@ struct acpi_rsdump_info acpi_rs_dump_generic_reg[6] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_gpio[16] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_gpio), "GPIO", NULL},
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_gpio), "GPIO", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(gpio.revision_id), "RevisionId", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(gpio.connection_type),
 	 "ConnectionType", acpi_gbl_ct_decode},
@@ -315,7 +315,7 @@ struct acpi_rsdump_info acpi_rs_dump_gpio[16] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_pin_function[10] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_function),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_pin_function),
 	 "PinFunction", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_function.revision_id),
 	 "RevisionId", NULL},
@@ -338,7 +338,7 @@ struct acpi_rsdump_info acpi_rs_dump_pin_function[10] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_pin_config[11] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_config),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_pin_config),
 	 "PinConfig", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_config.revision_id), "RevisionId",
 	 NULL},
@@ -363,7 +363,7 @@ struct acpi_rsdump_info acpi_rs_dump_pin_config[11] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_pin_group[8] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_group),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_pin_group),
 	 "PinGroup", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group.revision_id), "RevisionId",
 	 NULL},
@@ -382,7 +382,7 @@ struct acpi_rsdump_info acpi_rs_dump_pin_group[8] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_pin_group_function[9] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_group_function),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_pin_group_function),
 	 "PinGroupFunction", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group_function.revision_id),
 	 "RevisionId", NULL},
@@ -405,7 +405,7 @@ struct acpi_rsdump_info acpi_rs_dump_pin_group_function[9] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_pin_group_config[10] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_group_config),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_pin_group_config),
 	 "PinGroupConfig", NULL},
 	{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_group_config.revision_id),
 	 "RevisionId", NULL},
@@ -429,7 +429,7 @@ struct acpi_rsdump_info acpi_rs_dump_pin_group_config[10] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_fixed_dma[4] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_dma),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_fixed_dma),
 	 "FixedDma", NULL},
 	{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(fixed_dma.request_lines),
 	 "RequestLines", NULL},
@@ -452,13 +452,13 @@ struct acpi_rsdump_info acpi_rs_dump_fixed_dma[4] = {
 	{ACPI_RSD_SHORTLISTX,ACPI_RSD_OFFSET (common_serial_bus.vendor_data),   "VendorData",               NULL},
 
 struct acpi_rsdump_info acpi_rs_dump_common_serial_bus[11] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_common_serial_bus),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_common_serial_bus),
 	 "Common Serial Bus", NULL},
 	ACPI_RS_DUMP_COMMON_SERIAL_BUS
 };
 
 struct acpi_rsdump_info acpi_rs_dump_i2c_serial_bus[14] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_i2c_serial_bus),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_i2c_serial_bus),
 	 "I2C Serial Bus", NULL},
 	ACPI_RS_DUMP_COMMON_SERIAL_BUS {ACPI_RSD_1BITFLAG,
 					ACPI_RSD_OFFSET(i2c_serial_bus.
@@ -471,7 +471,7 @@ struct acpi_rsdump_info acpi_rs_dump_i2c_serial_bus[14] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_spi_serial_bus[18] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_spi_serial_bus),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_spi_serial_bus),
 	 "Spi Serial Bus", NULL},
 	ACPI_RS_DUMP_COMMON_SERIAL_BUS {ACPI_RSD_1BITFLAG,
 					ACPI_RSD_OFFSET(spi_serial_bus.
@@ -492,7 +492,7 @@ struct acpi_rsdump_info acpi_rs_dump_spi_serial_bus[18] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_uart_serial_bus[20] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_uart_serial_bus),
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_uart_serial_bus),
 	 "Uart Serial Bus", NULL},
 	ACPI_RS_DUMP_COMMON_SERIAL_BUS {ACPI_RSD_2BITFLAG,
 					ACPI_RSD_OFFSET(uart_serial_bus.
@@ -520,7 +520,7 @@ struct acpi_rsdump_info acpi_rs_dump_uart_serial_bus[20] = {
  * Tables used for common address descriptor flag fields
  */
 struct acpi_rsdump_info acpi_rs_dump_general_flags[5] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_general_flags), NULL,
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_general_flags), NULL,
 	 NULL},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.producer_consumer),
 	 "Consumer/Producer", acpi_gbl_consume_decode},
@@ -533,7 +533,7 @@ struct acpi_rsdump_info acpi_rs_dump_general_flags[5] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_memory_flags[5] = {
-	{ACPI_RSD_LITERAL, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_memory_flags),
+	{ACPI_RSD_LITERAL, ARRAY_SIZE(acpi_rs_dump_memory_flags),
 	 "Resource Type", (void *)"Memory Range"},
 	{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(address.info.mem.write_protect),
 	 "Write Protect", acpi_gbl_rw_decode},
@@ -546,7 +546,7 @@ struct acpi_rsdump_info acpi_rs_dump_memory_flags[5] = {
 };
 
 struct acpi_rsdump_info acpi_rs_dump_io_flags[4] = {
-	{ACPI_RSD_LITERAL, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_io_flags),
+	{ACPI_RSD_LITERAL, ARRAY_SIZE(acpi_rs_dump_io_flags),
 	 "Resource Type", (void *)"I/O Range"},
 	{ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(address.info.io.range_type),
 	 "Range Type", acpi_gbl_rng_decode},
@@ -560,7 +560,7 @@ struct acpi_rsdump_info acpi_rs_dump_io_flags[4] = {
  * Table used to dump _PRT contents
  */
 struct acpi_rsdump_info acpi_rs_dump_prt[5] = {
-	{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_prt), NULL, NULL},
+	{ACPI_RSD_TITLE, ARRAY_SIZE(acpi_rs_dump_prt), NULL, NULL},
 	{ACPI_RSD_UINT64, ACPI_PRT_OFFSET(address), "Address", NULL},
 	{ACPI_RSD_UINT32, ACPI_PRT_OFFSET(pin), "Pin", NULL},
 	{ACPI_RSD_STRING, ACPI_PRT_OFFSET(source[0]), "Source", NULL},
diff --git a/drivers/acpi/acpica/tbfadt.c b/drivers/acpi/acpica/tbfadt.c
index 5f051d82188d..d8322e62bb22 100644
--- a/drivers/acpi/acpica/tbfadt.c
+++ b/drivers/acpi/acpica/tbfadt.c
@@ -44,6 +44,7 @@
 #include <acpi/acpi.h>
 #include "accommon.h"
 #include "actables.h"
+#include <linux/kernel.h>
 
 #define _COMPONENT          ACPI_TABLES
 ACPI_MODULE_NAME("tbfadt")
@@ -137,9 +138,6 @@ static struct acpi_fadt_info fadt_info_table[] = {
 	 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
 };
 
-#define ACPI_FADT_INFO_ENTRIES \
-			(sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
-
 /* Table used to split Event Blocks into separate status/enable registers */
 
 typedef struct acpi_fadt_pm_info {
@@ -167,9 +165,6 @@ static struct acpi_fadt_pm_info fadt_pm_info_table[] = {
 	 1}
 };
 
-#define ACPI_FADT_PM_INFO_ENTRIES \
-			(sizeof (fadt_pm_info_table) / sizeof (struct acpi_fadt_pm_info))
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_tb_init_generic_address
@@ -520,7 +515,7 @@ static void acpi_tb_convert_fadt(void)
 
 	/* Examine all of the 64-bit extended address fields (X fields) */
 
-	for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
+	for (i = 0; i < ARRAY_SIZE(fadt_info_table); i++) {
 		/*
 		 * Get the 32-bit and 64-bit addresses, as well as the register
 		 * length and register name.
@@ -686,7 +681,7 @@ static void acpi_tb_setup_fadt_registers(void)
 	 * update them if they are incorrect.
 	 */
 	if (acpi_gbl_use_default_register_widths) {
-		for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
+		for (i = 0; i < ARRAY_SIZE(fadt_info_table); i++) {
 			target64 =
 			    ACPI_ADD_PTR(struct acpi_generic_address,
 					 &acpi_gbl_FADT,
@@ -737,7 +732,7 @@ static void acpi_tb_setup_fadt_registers(void)
 	 * used.
 	 */
 
-	for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++) {
+	for (i = 0; i < ARRAY_SIZE(fadt_pm_info_table); i++) {
 		source64 =
 		    ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
 				 fadt_pm_info_table[i].source);
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1743182 — Re: [PATCH 15/18] acpi: use ARRAY_SIZE

From"Rafael J. Wysocki" <rjw@rjwysocki.net>
Date2017-10-02 14:40 +0200
SubjectRe: [PATCH 15/18] acpi: use ARRAY_SIZE
Message-ID<uw8aS-7hy-19@gated-at.bofh.it>
In reply to#1742870
On Sunday, October 1, 2017 9:30:53 PM CEST Jérémy Lefaure wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. It is
> useless to re-invent the ARRAY_SIZE macro so let's use it.
> 
> It is useless to re-invent the ARRAY_SIZE macro so let's use it.

ACPICA is soewhat special code, though and I'm not taking or ACKing patches
for it directly as a rule.

For one, I'm not sure if ACPICA can use ARRAY_SIZE at all.

Thanks,
Rafael

[toc] | [prev] | [next] | [standalone]


#1742871 — [PATCH 01/18] sound: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 01/18] sound: use ARRAY_SIZE
Message-ID<uvSfM-67y-27@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 sound/oss/ad1848.c           | 7 ++++---
 sound/pci/hda/patch_ca0132.c | 8 +++-----
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
index 2421f59cf279..7e495054b51c 100644
--- a/sound/oss/ad1848.c
+++ b/sound/oss/ad1848.c
@@ -49,6 +49,7 @@
 #include <linux/isapnp.h>
 #include <linux/pnp.h>
 #include <linux/spinlock.h>
+#include <linux/kernel.h>
 
 #include "sound_config.h"
 
@@ -797,7 +798,7 @@ static int ad1848_set_speed(int dev, int arg)
 
 	int i, n, selected = -1;
 
-	n = sizeof(speed_table) / sizeof(speed_struct);
+	n = ARRAY_SIZE(speed_table);
 
 	if (arg <= 0)
 		return portc->speed;
@@ -908,7 +909,7 @@ static unsigned int ad1848_set_bits(int dev, unsigned int arg)
 			AFMT_U16_BE, 0
 		}
 	};
-	int i, n = sizeof(format2bits) / sizeof(struct format_tbl);
+	int i;
 
 	if (arg == 0)
 		return portc->audio_format;
@@ -918,7 +919,7 @@ static unsigned int ad1848_set_bits(int dev, unsigned int arg)
 
 	portc->audio_format = arg;
 
-	for (i = 0; i < n; i++)
+	for (i = 0; i < ARRAY_SIZE(format2bits); i++)
 		if (format2bits[i].format == arg)
 		{
 			if ((portc->format_bits = format2bits[i].bits) == 0)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 3e73d5c6ccfc..768ea8651993 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -27,6 +27,7 @@
 #include <linux/mutex.h>
 #include <linux/module.h>
 #include <linux/firmware.h>
+#include <linux/kernel.h>
 #include <sound/core.h>
 #include "hda_codec.h"
 #include "hda_local.h"
@@ -3605,8 +3606,7 @@ static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
 static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
 				 struct snd_ctl_elem_info *uinfo)
 {
-	unsigned int items = sizeof(ca0132_voicefx_presets)
-				/ sizeof(struct ct_voicefx_preset);
+	unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
 
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
 	uinfo->count = 1;
@@ -3635,10 +3635,8 @@ static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
 	struct ca0132_spec *spec = codec->spec;
 	int i, err = 0;
 	int sel = ucontrol->value.enumerated.item[0];
-	unsigned int items = sizeof(ca0132_voicefx_presets)
-				/ sizeof(struct ct_voicefx_preset);
 
-	if (sel >= items)
+	if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
 		return 0;
 
 	codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742960 — Re: [PATCH 01/18] sound: use ARRAY_SIZE

FromJoe Perches <joe@perches.com>
Date2017-10-02 06:20 +0200
SubjectRe: [PATCH 01/18] sound: use ARRAY_SIZE
Message-ID<uw0n0-2FC-5@gated-at.bofh.it>
In reply to#1742871
On Sun, 2017-10-01 at 15:30 -0400, Jérémy Lefaure wrote:
> Using the ARRAY_SIZE macro improves the readability of the code.
> 
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> > 
> 
>  (sizeof(E)@p /sizeof(E[...]))
> > 
> 
>  (sizeof(E)@p /sizeof(T))
> )
[]
> diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
[]
> @@ -797,7 +798,7 @@ static int ad1848_set_speed(int dev, int arg)
>  
>  	int i, n, selected = -1;
>  
> -	n = sizeof(speed_table) / sizeof(speed_struct);
> +	n = ARRAY_SIZE(speed_table);

These sorts of changes are OK, but for many
uses, it's more readable to use ARRAY_SIZE(foo)
in each location rather than using a temporary.

[toc] | [prev] | [next] | [standalone]


#1742872 — [PATCH 09/18] nfsd: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 09/18] nfsd: use ARRAY_SIZE
Message-ID<uvSfN-67y-35@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 fs/nfsd/fault_inject.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
index 34c1c449fddf..3ec72c931ac5 100644
--- a/fs/nfsd/fault_inject.c
+++ b/fs/nfsd/fault_inject.c
@@ -11,6 +11,7 @@
 #include <linux/nsproxy.h>
 #include <linux/sunrpc/addr.h>
 #include <linux/uaccess.h>
+#include <linux/kernel.h>
 
 #include "state.h"
 #include "netns.h"
@@ -125,8 +126,6 @@ static struct nfsd_fault_inject_op inject_ops[] = {
 	},
 };
 
-#define NUM_INJECT_OPS (sizeof(inject_ops)/sizeof(struct nfsd_fault_inject_op))
-
 int nfsd_fault_inject_init(void)
 {
 	unsigned int i;
@@ -137,7 +136,7 @@ int nfsd_fault_inject_init(void)
 	if (!debug_dir)
 		goto fail;
 
-	for (i = 0; i < NUM_INJECT_OPS; i++) {
+	for (i = 0; i < ARRAY_SIZE(inject_ops); i++) {
 		op = &inject_ops[i];
 		if (!debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd))
 			goto fail;
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1743120 — Re: [PATCH 09/18] nfsd: use ARRAY_SIZE

FromJeff Layton <jlayton@redhat.com>
Date2017-10-02 13:10 +0200
SubjectRe: [PATCH 09/18] nfsd: use ARRAY_SIZE
Message-ID<uw6LL-6zz-3@gated-at.bofh.it>
In reply to#1742872
On Sun, 2017-10-01 at 15:30 -0400, Jérémy Lefaure wrote:
> Using the ARRAY_SIZE macro improves the readability of the code.
> 
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> > 
> 
>  (sizeof(E)@p /sizeof(E[...]))
> > 
> 
>  (sizeof(E)@p /sizeof(T))
> )
> 
> Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
> ---
>  fs/nfsd/fault_inject.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
> index 34c1c449fddf..3ec72c931ac5 100644
> --- a/fs/nfsd/fault_inject.c
> +++ b/fs/nfsd/fault_inject.c
> @@ -11,6 +11,7 @@
>  #include <linux/nsproxy.h>
>  #include <linux/sunrpc/addr.h>
>  #include <linux/uaccess.h>
> +#include <linux/kernel.h>
>  
>  #include "state.h"
>  #include "netns.h"
> @@ -125,8 +126,6 @@ static struct nfsd_fault_inject_op inject_ops[] =
> {
>  	},
>  };
>  
> -#define NUM_INJECT_OPS (sizeof(inject_ops)/sizeof(struct
> nfsd_fault_inject_op))
> -
>  int nfsd_fault_inject_init(void)
>  {
>  	unsigned int i;
> @@ -137,7 +136,7 @@ int nfsd_fault_inject_init(void)
>  	if (!debug_dir)
>  		goto fail;
>  
> -	for (i = 0; i < NUM_INJECT_OPS; i++) {
> +	for (i = 0; i < ARRAY_SIZE(inject_ops); i++) {
>  		op = &inject_ops[i];
>  		if (!debugfs_create_file(op->file, mode, debug_dir,
> op, &fops_nfsd))
>  			goto fail;

Reviewed-by: Jeff Layton <jlayton@redhat.com>

[toc] | [prev] | [next] | [standalone]


#1742873 — [PATCH 08/18] ecryptfs: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 08/18] ecryptfs: use ARRAY_SIZE
Message-ID<uvSfM-67y-31@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 fs/ecryptfs/crypto.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 7acd57da4f14..2e78e851788e 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -36,6 +36,7 @@
 #include <linux/scatterlist.h>
 #include <linux/slab.h>
 #include <asm/unaligned.h>
+#include <linux/kernel.h>
 #include "ecryptfs_kernel.h"
 
 #define DECRYPT		0
@@ -884,8 +885,7 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat,
 	u32 flags;
 
 	flags = get_unaligned_be32(page_virt);
-	for (i = 0; i < ((sizeof(ecryptfs_flag_map)
-			  / sizeof(struct ecryptfs_flag_map_elem))); i++)
+	for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++)
 		if (flags & ecryptfs_flag_map[i].file_flag) {
 			crypt_stat->flags |= ecryptfs_flag_map[i].local_flag;
 		} else
@@ -922,8 +922,7 @@ void ecryptfs_write_crypt_stat_flags(char *page_virt,
 	u32 flags = 0;
 	int i;
 
-	for (i = 0; i < ((sizeof(ecryptfs_flag_map)
-			  / sizeof(struct ecryptfs_flag_map_elem))); i++)
+	for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++)
 		if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag)
 			flags |= ecryptfs_flag_map[i].file_flag;
 	/* Version is in top 8 bits of the 32-bit flag vector */
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742874 — [PATCH 03/18] media: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 03/18] media: use ARRAY_SIZE
Message-ID<uvSfN-67y-39@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is not always useful to use a variable to store this constant
calculated at compile time.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/media/common/saa7146/saa7146_video.c | 9 ++++-----
 drivers/media/dvb-frontends/cxd2841er.c      | 7 +++----
 drivers/media/pci/saa7146/hexium_gemini.c    | 3 ++-
 drivers/media/pci/saa7146/hexium_orion.c     | 3 ++-
 drivers/media/pci/saa7146/mxb.c              | 3 ++-
 drivers/media/usb/dvb-usb/cxusb.c            | 3 ++-
 drivers/media/usb/dvb-usb/friio-fe.c         | 5 ++---
 7 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
index 37b4654dc21c..612aefd804f0 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -4,6 +4,7 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-ctrls.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 static int max_memory = 32;
 
@@ -86,13 +87,11 @@ static struct saa7146_format formats[] = {
    due to this, it's impossible to provide additional *packed* formats, which are simply byte swapped
    (like V4L2_PIX_FMT_YUYV) ... 8-( */
 
-static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format);
-
 struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc)
 {
-	int i, j = NUM_FORMATS;
+	int i;
 
-	for (i = 0; i < j; i++) {
+	for (i = 0; i < ARRAY_SIZE(formats); i++) {
 		if (formats[i].pixelformat == fourcc) {
 			return formats+i;
 		}
@@ -524,7 +523,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuf
 
 static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
 {
-	if (f->index >= NUM_FORMATS)
+	if (f->index >= ARRAY_SIZE(formats))
 		return -EINVAL;
 	strlcpy((char *)f->description, formats[f->index].name,
 			sizeof(f->description));
diff --git a/drivers/media/dvb-frontends/cxd2841er.c b/drivers/media/dvb-frontends/cxd2841er.c
index 48ee9bc00c06..2cb97a3130be 100644
--- a/drivers/media/dvb-frontends/cxd2841er.c
+++ b/drivers/media/dvb-frontends/cxd2841er.c
@@ -29,6 +29,7 @@
 #include <linux/math64.h>
 #include <linux/log2.h>
 #include <linux/dynamic_debug.h>
+#include <linux/kernel.h>
 
 #include "dvb_math.h"
 #include "dvb_frontend.h"
@@ -1696,12 +1697,10 @@ static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv,
 		min_index = 0;
 		if (delsys == SYS_DVBS) {
 			cn_data = s_cn_data;
-			max_index = sizeof(s_cn_data) /
-				sizeof(s_cn_data[0]) - 1;
+			max_index = ARRAY_SIZE(s_cn_data) - 1;
 		} else {
 			cn_data = s2_cn_data;
-			max_index = sizeof(s2_cn_data) /
-				sizeof(s2_cn_data[0]) - 1;
+			max_index = ARRAY_SIZE(s2_cn_data) - 1;
 		}
 		if (value >= cn_data[min_index].value) {
 			res = cn_data[min_index].cnr_x1000;
diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c
index d31a2d4494d1..39357eddee32 100644
--- a/drivers/media/pci/saa7146/hexium_gemini.c
+++ b/drivers/media/pci/saa7146/hexium_gemini.c
@@ -27,6 +27,7 @@
 
 #include <media/drv-intf/saa7146_vv.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 static int debug;
 module_param(debug, int, 0);
@@ -388,7 +389,7 @@ static struct saa7146_ext_vv vv_data = {
 	.inputs = HEXIUM_INPUTS,
 	.capabilities = 0,
 	.stds = &hexium_standards[0],
-	.num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+	.num_stds = ARRAY_SIZE(hexium_standards),
 	.std_callback = &std_callback,
 };
 
diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c
index 043318aa19e2..461e421080f3 100644
--- a/drivers/media/pci/saa7146/hexium_orion.c
+++ b/drivers/media/pci/saa7146/hexium_orion.c
@@ -27,6 +27,7 @@
 
 #include <media/drv-intf/saa7146_vv.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 static int debug;
 module_param(debug, int, 0);
@@ -460,7 +461,7 @@ static struct saa7146_ext_vv vv_data = {
 	.inputs = HEXIUM_INPUTS,
 	.capabilities = 0,
 	.stds = &hexium_standards[0],
-	.num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+	.num_stds = ARRAY_SIZE(hexium_standards),
 	.std_callback = &std_callback,
 };
 
diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
index 930218cc2de1..0144f305ea24 100644
--- a/drivers/media/pci/saa7146/mxb.c
+++ b/drivers/media/pci/saa7146/mxb.c
@@ -30,6 +30,7 @@
 #include <media/v4l2-common.h>
 #include <media/i2c/saa7115.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 #include "tea6415c.h"
 #include "tea6420.h"
@@ -837,7 +838,7 @@ static struct saa7146_ext_vv vv_data = {
 	.inputs		= MXB_INPUTS,
 	.capabilities	= V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_AUDIO,
 	.stds		= &standard[0],
-	.num_stds	= sizeof(standard)/sizeof(struct saa7146_standard),
+	.num_stds	= ARRAY_SIZE(standard),
 	.std_callback	= &std_callback,
 };
 
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index 37dea0adc695..9b486bb5004d 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -26,6 +26,7 @@
 #include <media/tuner.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 
 #include "cxusb.h"
 
@@ -303,7 +304,7 @@ static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
 			0x0e, 0x2, 0x47, 0x88,
 		};
 		msleep(20);
-		for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {
+		for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
 			ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
 					     bufs+i, 4, &buf, 1);
 			if (ret)
diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
index 0251a4e91d47..a6c84a4390d1 100644
--- a/drivers/media/usb/dvb-usb/friio-fe.c
+++ b/drivers/media/usb/dvb-usb/friio-fe.c
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 
 #include "friio.h"
 
@@ -362,8 +363,6 @@ static u8 init_code[][2] = {
 	{0x76, 0x0C},
 };
 
-static const int init_code_len = sizeof(init_code) / sizeof(u8[2]);
-
 static int jdvbt90502_init(struct dvb_frontend *fe)
 {
 	int i = -1;
@@ -377,7 +376,7 @@ static int jdvbt90502_init(struct dvb_frontend *fe)
 	msg.addr = state->config.demod_address;
 	msg.flags = 0;
 	msg.len = 2;
-	for (i = 0; i < init_code_len; i++) {
+	for (i = 0; i < ARRAY_SIZE(init_code); i++) {
 		msg.buf = init_code[i];
 		ret = i2c_transfer(state->i2c, &msg, 1);
 		if (ret != 1)
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1743092 — Re: [PATCH 03/18] media: use ARRAY_SIZE

FromMichael Ira Krufky <mkrufky@linuxtv.org>
Date2017-10-02 12:40 +0200
SubjectRe: [PATCH 03/18] media: use ARRAY_SIZE
Message-ID<uw6iJ-6a9-9@gated-at.bofh.it>
In reply to#1742874
On Sun, Oct 1, 2017 at 3:30 PM, Jérémy Lefaure
<jeremy.lefaure@lse.epita.fr> wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. Also,
> it is not always useful to use a variable to store this constant
> calculated at compile time.
>
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> |
>  (sizeof(E)@p /sizeof(E[...]))
> |
>  (sizeof(E)@p /sizeof(T))
> )
>
> Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>


Reviewed-by: Michael Ira Krufky <mkrufky@linuxtv.org>


> ---
>  drivers/media/common/saa7146/saa7146_video.c | 9 ++++-----
>  drivers/media/dvb-frontends/cxd2841er.c      | 7 +++----
>  drivers/media/pci/saa7146/hexium_gemini.c    | 3 ++-
>  drivers/media/pci/saa7146/hexium_orion.c     | 3 ++-
>  drivers/media/pci/saa7146/mxb.c              | 3 ++-
>  drivers/media/usb/dvb-usb/cxusb.c            | 3 ++-
>  drivers/media/usb/dvb-usb/friio-fe.c         | 5 ++---
>  7 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
> index 37b4654dc21c..612aefd804f0 100644
> --- a/drivers/media/common/saa7146/saa7146_video.c
> +++ b/drivers/media/common/saa7146/saa7146_video.c
> @@ -4,6 +4,7 @@
>  #include <media/v4l2-event.h>
>  #include <media/v4l2-ctrls.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  static int max_memory = 32;
>
> @@ -86,13 +87,11 @@ static struct saa7146_format formats[] = {
>     due to this, it's impossible to provide additional *packed* formats, which are simply byte swapped
>     (like V4L2_PIX_FMT_YUYV) ... 8-( */
>
> -static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format);
> -
>  struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc)
>  {
> -       int i, j = NUM_FORMATS;
> +       int i;
>
> -       for (i = 0; i < j; i++) {
> +       for (i = 0; i < ARRAY_SIZE(formats); i++) {
>                 if (formats[i].pixelformat == fourcc) {
>                         return formats+i;
>                 }
> @@ -524,7 +523,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuf
>
>  static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
>  {
> -       if (f->index >= NUM_FORMATS)
> +       if (f->index >= ARRAY_SIZE(formats))
>                 return -EINVAL;
>         strlcpy((char *)f->description, formats[f->index].name,
>                         sizeof(f->description));
> diff --git a/drivers/media/dvb-frontends/cxd2841er.c b/drivers/media/dvb-frontends/cxd2841er.c
> index 48ee9bc00c06..2cb97a3130be 100644
> --- a/drivers/media/dvb-frontends/cxd2841er.c
> +++ b/drivers/media/dvb-frontends/cxd2841er.c
> @@ -29,6 +29,7 @@
>  #include <linux/math64.h>
>  #include <linux/log2.h>
>  #include <linux/dynamic_debug.h>
> +#include <linux/kernel.h>
>
>  #include "dvb_math.h"
>  #include "dvb_frontend.h"
> @@ -1696,12 +1697,10 @@ static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv,
>                 min_index = 0;
>                 if (delsys == SYS_DVBS) {
>                         cn_data = s_cn_data;
> -                       max_index = sizeof(s_cn_data) /
> -                               sizeof(s_cn_data[0]) - 1;
> +                       max_index = ARRAY_SIZE(s_cn_data) - 1;
>                 } else {
>                         cn_data = s2_cn_data;
> -                       max_index = sizeof(s2_cn_data) /
> -                               sizeof(s2_cn_data[0]) - 1;
> +                       max_index = ARRAY_SIZE(s2_cn_data) - 1;
>                 }
>                 if (value >= cn_data[min_index].value) {
>                         res = cn_data[min_index].cnr_x1000;
> diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c
> index d31a2d4494d1..39357eddee32 100644
> --- a/drivers/media/pci/saa7146/hexium_gemini.c
> +++ b/drivers/media/pci/saa7146/hexium_gemini.c
> @@ -27,6 +27,7 @@
>
>  #include <media/drv-intf/saa7146_vv.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  static int debug;
>  module_param(debug, int, 0);
> @@ -388,7 +389,7 @@ static struct saa7146_ext_vv vv_data = {
>         .inputs = HEXIUM_INPUTS,
>         .capabilities = 0,
>         .stds = &hexium_standards[0],
> -       .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
> +       .num_stds = ARRAY_SIZE(hexium_standards),
>         .std_callback = &std_callback,
>  };
>
> diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c
> index 043318aa19e2..461e421080f3 100644
> --- a/drivers/media/pci/saa7146/hexium_orion.c
> +++ b/drivers/media/pci/saa7146/hexium_orion.c
> @@ -27,6 +27,7 @@
>
>  #include <media/drv-intf/saa7146_vv.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  static int debug;
>  module_param(debug, int, 0);
> @@ -460,7 +461,7 @@ static struct saa7146_ext_vv vv_data = {
>         .inputs = HEXIUM_INPUTS,
>         .capabilities = 0,
>         .stds = &hexium_standards[0],
> -       .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
> +       .num_stds = ARRAY_SIZE(hexium_standards),
>         .std_callback = &std_callback,
>  };
>
> diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
> index 930218cc2de1..0144f305ea24 100644
> --- a/drivers/media/pci/saa7146/mxb.c
> +++ b/drivers/media/pci/saa7146/mxb.c
> @@ -30,6 +30,7 @@
>  #include <media/v4l2-common.h>
>  #include <media/i2c/saa7115.h>
>  #include <linux/module.h>
> +#include <linux/kernel.h>
>
>  #include "tea6415c.h"
>  #include "tea6420.h"
> @@ -837,7 +838,7 @@ static struct saa7146_ext_vv vv_data = {
>         .inputs         = MXB_INPUTS,
>         .capabilities   = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_AUDIO,
>         .stds           = &standard[0],
> -       .num_stds       = sizeof(standard)/sizeof(struct saa7146_standard),
> +       .num_stds       = ARRAY_SIZE(standard),
>         .std_callback   = &std_callback,
>  };
>
> diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
> index 37dea0adc695..9b486bb5004d 100644
> --- a/drivers/media/usb/dvb-usb/cxusb.c
> +++ b/drivers/media/usb/dvb-usb/cxusb.c
> @@ -26,6 +26,7 @@
>  #include <media/tuner.h>
>  #include <linux/vmalloc.h>
>  #include <linux/slab.h>
> +#include <linux/kernel.h>
>
>  #include "cxusb.h"
>
> @@ -303,7 +304,7 @@ static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
>                         0x0e, 0x2, 0x47, 0x88,
>                 };
>                 msleep(20);
> -               for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {
> +               for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
>                         ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
>                                              bufs+i, 4, &buf, 1);
>                         if (ret)
> diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
> index 0251a4e91d47..a6c84a4390d1 100644
> --- a/drivers/media/usb/dvb-usb/friio-fe.c
> +++ b/drivers/media/usb/dvb-usb/friio-fe.c
> @@ -13,6 +13,7 @@
>  #include <linux/init.h>
>  #include <linux/string.h>
>  #include <linux/slab.h>
> +#include <linux/kernel.h>
>
>  #include "friio.h"
>
> @@ -362,8 +363,6 @@ static u8 init_code[][2] = {
>         {0x76, 0x0C},
>  };
>
> -static const int init_code_len = sizeof(init_code) / sizeof(u8[2]);
> -
>  static int jdvbt90502_init(struct dvb_frontend *fe)
>  {
>         int i = -1;
> @@ -377,7 +376,7 @@ static int jdvbt90502_init(struct dvb_frontend *fe)
>         msg.addr = state->config.demod_address;
>         msg.flags = 0;
>         msg.len = 2;
> -       for (i = 0; i < init_code_len; i++) {
> +       for (i = 0; i < ARRAY_SIZE(init_code); i++) {
>                 msg.buf = init_code[i];
>                 ret = i2c_transfer(state->i2c, &msg, 1);
>                 if (ret != 1)
> --
> 2.14.1
>

[toc] | [prev] | [next] | [standalone]


#1742875 — [PATCH 14/18] ipmi: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 14/18] ipmi: use ARRAY_SIZE
Message-ID<uvSfN-67y-37@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code. In this
case, it's useless to define the macro NUM_PO_FUNCS so let's use
ARRAY_SIZE instead.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/char/ipmi/ipmi_poweroff.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index cd0f41fd4a51..7b36d7550840 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -40,6 +40,7 @@
 #include <linux/kdev_t.h>
 #include <linux/ipmi.h>
 #include <linux/ipmi_smi.h>
+#include <linux/kernel.h>
 
 #define PFX "IPMI poweroff: "
 
@@ -539,8 +540,6 @@ static struct poweroff_function poweroff_functions[] = {
 	  .detect		= ipmi_chassis_detect,
 	  .poweroff_func	= ipmi_poweroff_chassis },
 };
-#define NUM_PO_FUNCS (sizeof(poweroff_functions) \
-		      / sizeof(struct poweroff_function))
 
 
 /* Called on a powerdown request. */
@@ -616,7 +615,7 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
 
 
 	/* Scan for a poweroff method */
-	for (i = 0; i < NUM_PO_FUNCS; i++) {
+	for (i = 0; i < ARRAY_SIZE(poweroff_functions); i++) {
 		if (poweroff_functions[i].detect(ipmi_user))
 			goto found;
 	}
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


#1742876 — [PATCH 07/18] scsi: bfa: use ARRAY_SIZE

FromJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Date2017-10-01 21:40 +0200
Subject[PATCH 07/18] scsi: bfa: use ARRAY_SIZE
Message-ID<uvSfN-67y-43@gated-at.bofh.it>
In reply to#1742863
Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
---
 drivers/scsi/bfa/bfa_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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;
 }
 
-- 
2.14.1

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | linux.kernel


csiph-web