[RESEND PATCH 1/1] Coccinelle: array_size: report even if include is missing

2017-12-29 Thread Jérémy Lefaure
Rule r does not depend on rule i (which is the include of
linux/kernel.h) so the output should not depend on i in
org and report mode.

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
Acked-by: Julia Lawall <julia.law...@lip6.fr>
---

 scripts/coccinelle/misc/array_size.cocci | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/coccinelle/misc/array_size.cocci 
b/scripts/coccinelle/misc/array_size.cocci
index 6ec05710b017..09520f0941f0 100644
--- a/scripts/coccinelle/misc/array_size.cocci
+++ b/scripts/coccinelle/misc/array_size.cocci
@@ -72,13 +72,13 @@ position p;
  (sizeof(E)@p /sizeof(T))
 )
 
-@script:python depends on i&@
+@script:python depends on org@
 p << r.p;
 @@
 
 coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
 
-@script:python depends on i&@
+@script:python depends on report@
 p << r.p;
 @@
 
-- 
2.14.1



[RESEND PATCH 1/1] Coccinelle: array_size: report even if include is missing

2017-12-29 Thread Jérémy Lefaure
Rule r does not depend on rule i (which is the include of
linux/kernel.h) so the output should not depend on i in
org and report mode.

Signed-off-by: Jérémy Lefaure 
Acked-by: Julia Lawall 
---

 scripts/coccinelle/misc/array_size.cocci | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/coccinelle/misc/array_size.cocci 
b/scripts/coccinelle/misc/array_size.cocci
index 6ec05710b017..09520f0941f0 100644
--- a/scripts/coccinelle/misc/array_size.cocci
+++ b/scripts/coccinelle/misc/array_size.cocci
@@ -72,13 +72,13 @@ position p;
  (sizeof(E)@p /sizeof(T))
 )
 
-@script:python depends on i&@
+@script:python depends on org@
 p << r.p;
 @@
 
 coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
 
-@script:python depends on i&@
+@script:python depends on report@
 p << r.p;
 @@
 
-- 
2.14.1



Re: [PATCH 1/1] Coccinelle: array_size: report even if include is missing

2017-12-29 Thread Jérémy Lefaure
Hi,

On Thu, 14 Sep 2017 13:21:13 +0200 (CEST)
Julia Lawall <julia.law...@lip6.fr> wrote:

> On Wed, 13 Sep 2017, Jérémy Lefaure wrote:
> 
> > Rule r does not depend on rule i (which is the include of
> > linux/kernel.h) so the output should not depend on i in
> > org and report mode.
> >
> > Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>  
> 
> Acked-by: Julia Lawall <julia.law...@lip6.fr>
> 
> I guess that if the incude is missing, the person updating the code can
> always add it.
> 
I don't see this patch upstream, is it lost somewhere or should I send
it to someone else ?


> 
> > ---
> >
> > I have tested this patch in report mode on the file
> > drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c which does not
> > use ARRAY_SIZE and does not include linux/kernel.h.
> >
> >  scripts/coccinelle/misc/array_size.cocci | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/coccinelle/misc/array_size.cocci 
> > b/scripts/coccinelle/misc/array_size.cocci
> > index 6ec05710b017..09520f0941f0 100644
> > --- a/scripts/coccinelle/misc/array_size.cocci
> > +++ b/scripts/coccinelle/misc/array_size.cocci
> > @@ -72,13 +72,13 @@ position p;
> >   (sizeof(E)@p /sizeof(T))
> >  )
> >
> > -@script:python depends on i&@
> > +@script:python depends on org@
> >  p << r.p;
> >  @@
> >
> >  coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
> >
> > -@script:python depends on i&@
> > +@script:python depends on report@
> >  p << r.p;
> >  @@
> >
> > --
> > 2.14.1
> >
> >  



Re: [PATCH 1/1] Coccinelle: array_size: report even if include is missing

2017-12-29 Thread Jérémy Lefaure
Hi,

On Thu, 14 Sep 2017 13:21:13 +0200 (CEST)
Julia Lawall  wrote:

> On Wed, 13 Sep 2017, Jérémy Lefaure wrote:
> 
> > Rule r does not depend on rule i (which is the include of
> > linux/kernel.h) so the output should not depend on i in
> > org and report mode.
> >
> > Signed-off-by: Jérémy Lefaure   
> 
> Acked-by: Julia Lawall 
> 
> I guess that if the incude is missing, the person updating the code can
> always add it.
> 
I don't see this patch upstream, is it lost somewhere or should I send
it to someone else ?


> 
> > ---
> >
> > I have tested this patch in report mode on the file
> > drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c which does not
> > use ARRAY_SIZE and does not include linux/kernel.h.
> >
> >  scripts/coccinelle/misc/array_size.cocci | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/coccinelle/misc/array_size.cocci 
> > b/scripts/coccinelle/misc/array_size.cocci
> > index 6ec05710b017..09520f0941f0 100644
> > --- a/scripts/coccinelle/misc/array_size.cocci
> > +++ b/scripts/coccinelle/misc/array_size.cocci
> > @@ -72,13 +72,13 @@ position p;
> >   (sizeof(E)@p /sizeof(T))
> >  )
> >
> > -@script:python depends on i&@
> > +@script:python depends on org@
> >  p << r.p;
> >  @@
> >
> >  coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
> >
> > -@script:python depends on i&@
> > +@script:python depends on report@
> >  p << r.p;
> >  @@
> >
> > --
> > 2.14.1
> >
> >  



Re: [PATCH AUTOSEL for 3.18 16/16] EDAC, i5000, i5400: Fix use of MTR_DRAM_WIDTH macro

2017-11-29 Thread Jérémy Lefaure
On Wed, 29 Nov 2017 17:22:22 +
alexander.le...@verizon.com wrote:

> From: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
> 
> [ Upstream commit e61555c29c28a4a3b6ba6207f4a0883ee236004d ]
> 
> The MTR_DRAM_WIDTH macro returns the data width. It is sometimes used
> as if it returned a boolean true if the width if 8. Fix the tests where
> MTR_DRAM_WIDTH is misused.
> 
> Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
> Cc: linux-edac <linux-e...@vger.kernel.org>
> Link: 
> http://lkml.kernel.org/r/20170309011809.8340-1-jeremy.lefa...@lse.epita.fr
> Signed-off-by: Borislav Petkov <b...@suse.de>
> Signed-off-by: Sasha Levin <alexander.le...@verizon.com>
> 
Hi Sasha,
I noticed that you want to backport this commit to 3.18, 4.4 and 4.9.
Is there any reason for not backporting it to 4.1 ?

Also, I don't know if you saw my other patch on those files, upstream
commit a8c8261425649d ("EDAC, i5000, i5400: Fix definition of NRECMEMB
register"). Maybe it should be backported to stable too ?


Thanks,
Jérémy


Re: [PATCH AUTOSEL for 3.18 16/16] EDAC, i5000, i5400: Fix use of MTR_DRAM_WIDTH macro

2017-11-29 Thread Jérémy Lefaure
On Wed, 29 Nov 2017 17:22:22 +
alexander.le...@verizon.com wrote:

> From: Jérémy Lefaure 
> 
> [ Upstream commit e61555c29c28a4a3b6ba6207f4a0883ee236004d ]
> 
> The MTR_DRAM_WIDTH macro returns the data width. It is sometimes used
> as if it returned a boolean true if the width if 8. Fix the tests where
> MTR_DRAM_WIDTH is misused.
> 
> Signed-off-by: Jérémy Lefaure 
> Cc: linux-edac 
> Link: 
> http://lkml.kernel.org/r/20170309011809.8340-1-jeremy.lefa...@lse.epita.fr
> Signed-off-by: Borislav Petkov 
> Signed-off-by: Sasha Levin 
> 
Hi Sasha,
I noticed that you want to backport this commit to 3.18, 4.4 and 4.9.
Is there any reason for not backporting it to 4.1 ?

Also, I don't know if you saw my other patch on those files, upstream
commit a8c8261425649d ("EDAC, i5000, i5400: Fix definition of NRECMEMB
register"). Maybe it should be backported to stable too ?


Thanks,
Jérémy


[tip:x86/cleanups] x86: Use ARRAY_SIZE

2017-10-19 Thread tip-bot for Jérémy Lefaure
Commit-ID:  0cfe5b5fc0277463fa795dea312a3a2fd5e8bac2
Gitweb: https://git.kernel.org/tip/0cfe5b5fc0277463fa795dea312a3a2fd5e8bac2
Author: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
AuthorDate: Sun, 1 Oct 2017 15:30:50 -0400
Committer:  Thomas Gleixner <t...@linutronix.de>
CommitDate: Thu, 19 Oct 2017 16:15:47 +0200

x86: Use ARRAY_SIZE

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.lefa...@lse.epita.fr>
Signed-off-by: Thomas Gleixner <t...@linutronix.de>
Cc: linux-vi...@atrey.karlin.mff.cuni.cz
Cc: Martin Mares <m...@ucw.cz>
Cc: Andy Lutomirski <l...@amacapital.net>
Link: 
https://lkml.kernel.org/r/20171001193101.8898-13-jeremy.lefa...@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 45bc940..a14c517 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 0780a44..4674f58 100644
--- a/arch/x86/entry/vdso/vdso2c.c
+++ b/arch/x86/entry/vdso/vdso2c.c
@@ -65,6 +65,7 @@
 
 #include 
 #include 
+#include 
 
 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 7428387..e639e31 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);


[tip:x86/cleanups] x86: Use ARRAY_SIZE

2017-10-19 Thread tip-bot for Jérémy Lefaure
Commit-ID:  0cfe5b5fc0277463fa795dea312a3a2fd5e8bac2
Gitweb: https://git.kernel.org/tip/0cfe5b5fc0277463fa795dea312a3a2fd5e8bac2
Author: Jérémy Lefaure 
AuthorDate: Sun, 1 Oct 2017 15:30:50 -0400
Committer:  Thomas Gleixner 
CommitDate: Thu, 19 Oct 2017 16:15:47 +0200

x86: Use ARRAY_SIZE

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 
Signed-off-by: Thomas Gleixner 
Cc: linux-vi...@atrey.karlin.mff.cuni.cz
Cc: Martin Mares 
Cc: Andy Lutomirski 
Link: 
https://lkml.kernel.org/r/20171001193101.8898-13-jeremy.lefa...@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 45bc940..a14c517 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 0780a44..4674f58 100644
--- a/arch/x86/entry/vdso/vdso2c.c
+++ b/arch/x86/entry/vdso/vdso2c.c
@@ -65,6 +65,7 @@
 
 #include 
 #include 
+#include 
 
 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 7428387..e639e31 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);


[PATCH] drm/via: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
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))
)

Reviewed-by: Thierry Reding <tred...@nvidia.com>
Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/via/via_verifier.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

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 
 #include "via_verifier.h"
 #include "via_drv.h"
+#include 
 
 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.2



[PATCH] drm/via: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
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))
)

Reviewed-by: Thierry Reding 
Signed-off-by: Jérémy Lefaure 
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/via/via_verifier.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

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 
 #include "via_verifier.h"
 #include "via_drv.h"
+#include 
 
 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.2



[PATCH] drm/nouveau/bios/init: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to re-invent 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))
)

Reviewed-by: Thierry Reding <tred...@nvidia.com>
Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

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 
 #include 
 
+#include 
+
 #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;
}
-- 
2.14.2



[PATCH] drm/nouveau/bios/init: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to re-invent 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))
)

Reviewed-by: Thierry Reding 
Signed-off-by: Jérémy Lefaure 
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/nouveau/nvkm/subdev/bios/init.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

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 
 #include 
 
+#include 
+
 #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;
}
-- 
2.14.2



[PATCH] drm/i915/gvt: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it's 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.lefa...@lse.epita.fr>
---
This patch was part of a bigger patch [1].

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/i915/gvt/vgpu.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 02c61a1ad56a..b32c1c889ea8 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -31,6 +31,7 @@
  *
  */
 
+#include 
 #include "i915_drv.h"
 #include "gvt.h"
 #include "i915_pvinfo.h"
@@ -98,7 +99,6 @@ static struct {
  */
 int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
 {
-   unsigned int num_types;
unsigned int i, low_avail, high_avail;
unsigned int min_low;
 
@@ -116,15 +116,14 @@ 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]);
 
-   gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type),
-GFP_KERNEL);
+   gvt->types = kzalloc(ARRAY_SIZE(vgpu_types) *
+sizeof(struct intel_vgpu_type), GFP_KERNEL);
if (!gvt->types)
return -ENOMEM;
 
min_low = MB_TO_BYTES(32);
-   for (i = 0; i < num_types; ++i) {
+   for (i = 0; i < ARRAY_SIZE(vgpu_types); ++i) {
if (low_avail / vgpu_types[i].low_mm == 0)
break;
 
-- 
2.14.2



[PATCH] drm/i915/gvt: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it's 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 
---
This patch was part of a bigger patch [1].

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/i915/gvt/vgpu.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 02c61a1ad56a..b32c1c889ea8 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -31,6 +31,7 @@
  *
  */
 
+#include 
 #include "i915_drv.h"
 #include "gvt.h"
 #include "i915_pvinfo.h"
@@ -98,7 +99,6 @@ static struct {
  */
 int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
 {
-   unsigned int num_types;
unsigned int i, low_avail, high_avail;
unsigned int min_low;
 
@@ -116,15 +116,14 @@ 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]);
 
-   gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type),
-GFP_KERNEL);
+   gvt->types = kzalloc(ARRAY_SIZE(vgpu_types) *
+sizeof(struct intel_vgpu_type), GFP_KERNEL);
if (!gvt->types)
return -ENOMEM;
 
min_low = MB_TO_BYTES(32);
-   for (i = 0; i < num_types; ++i) {
+   for (i = 0; i < ARRAY_SIZE(vgpu_types); ++i) {
if (low_avail / vgpu_types[i].low_mm == 0)
break;
 
-- 
2.14.2



[PATCH] drm/gma500: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to re-invent 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))
)

Reviewed-by: Thierry Reding <tred...@nvidia.com>
Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/gma500/psb_intel_sdvo.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

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 
 
 #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;
 
-- 
2.14.2



[PATCH] drm/gma500: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to re-invent 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))
)

Reviewed-by: Thierry Reding 
Signed-off-by: Jérémy Lefaure 
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/gma500/psb_intel_sdvo.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

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 
 
 #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;
 
-- 
2.14.2



[PATCH] drm/amdgpu: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
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))
)

Reviewed-by: Thierry Reding <tred...@nvidia.com>
Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 9 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 9 +
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 147e92b3a959..c9f542b4e05c 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 
 #include 
 #include 
 #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,
_count,
-   sizeof(unique_indices) / sizeof(int),
+   ARRAY_SIZE(unique_indices),
indirect_start_offsets,
_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] & 0x3);
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 99a5b3b92e8e..7f15bb2c5233 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 
 #include 
 #include 
 #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,
_indirect_reg_count,
-   sizeof(unique_indirect_regs)/sizeof(int),
+   ARRAY_SIZE(unique_indirect_regs),
indirect_start_offsets,
_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] & 0x3);
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_DATA_0) + i,
-- 
2.14.2



[PATCH] drm/amdgpu: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
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))
)

Reviewed-by: Thierry Reding 
Signed-off-by: Jérémy Lefaure 
---
This patch was part of a bigger patch [1] reviewed by Thierry Reding
before it was split in several patches.

[1]: https://patchwork.kernel.org/patch/9979843/

 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 9 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 9 +
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 147e92b3a959..c9f542b4e05c 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 
 #include 
 #include 
 #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,
_count,
-   sizeof(unique_indices) / sizeof(int),
+   ARRAY_SIZE(unique_indices),
indirect_start_offsets,
_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] & 0x3);
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 99a5b3b92e8e..7f15bb2c5233 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 
 #include 
 #include 
 #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,
_indirect_reg_count,
-   sizeof(unique_indirect_regs)/sizeof(int),
+   ARRAY_SIZE(unique_indirect_regs),
indirect_start_offsets,
_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] & 0x3);
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_DATA_0) + i,
-- 
2.14.2



[PATCH v2] tracing/filter: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
Changes since v1:
- keep DATA_CNT as suggested by Steven Rostedt

 kernel/trace/trace_events_filter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_filter.c 
b/kernel/trace/trace_events_filter.c
index 61e7f0678d33..1b13ba6e3b1a 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "trace.h"
 #include "trace_output.h"
@@ -2376,7 +2377,7 @@ static struct test_filter_data_t {
 #undef YES
 #undef NO
 
-#define DATA_CNT (sizeof(test_filter_data)/sizeof(struct test_filter_data_t))
+#define DATA_CNT ARRAY_SIZE(test_filter_data)
 
 static int test_pred_visited;
 
-- 
2.14.2



[PATCH v2] tracing/filter: use ARRAY_SIZE

2017-10-15 Thread Jérémy Lefaure
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 
---
Changes since v1:
- keep DATA_CNT as suggested by Steven Rostedt

 kernel/trace/trace_events_filter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_filter.c 
b/kernel/trace/trace_events_filter.c
index 61e7f0678d33..1b13ba6e3b1a 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "trace.h"
 #include "trace_output.h"
@@ -2376,7 +2377,7 @@ static struct test_filter_data_t {
 #undef YES
 #undef NO
 
-#define DATA_CNT (sizeof(test_filter_data)/sizeof(struct test_filter_data_t))
+#define DATA_CNT ARRAY_SIZE(test_filter_data)
 
 static int test_pred_visited;
 
-- 
2.14.2



[PATCH v2] ALSA: hda/ca0132 - use ARRAY_SIZE

2017-10-12 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
Changes since v1:
- keep sound/oss untouched

 sound/pci/hda/patch_ca0132.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

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 
 #include 
 #include 
+#include 
 #include 
 #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.2



[PATCH v2] ALSA: hda/ca0132 - use ARRAY_SIZE

2017-10-12 Thread Jérémy Lefaure
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 
---
Changes since v1:
- keep sound/oss untouched

 sound/pci/hda/patch_ca0132.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

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 
 #include 
 #include 
+#include 
 #include 
 #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.2



Re: [PATCH 13/18] tpm: use ARRAY_SIZE

2017-10-10 Thread Jérémy Lefaure
On Wed, 4 Oct 2017 15:14:49 +0300
Jarkko Sakkinen <jarkko.sakki...@linux.intel.com> wrote:

> On Sun, Oct 01, 2017 at 03:30:51PM -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.lefa...@lse.epita.fr>  
> 
> Reviewed-by: Jarkko Sakkinen <jarkko.sakki...@linux.intel.com>
> 
Hi Jarkko,
This patch is an individual patch, it's not really part of a series
(my fault, sorry).

Could you apply this patch to your tree ?

Thank you,
Jérémy


Re: [PATCH 13/18] tpm: use ARRAY_SIZE

2017-10-10 Thread Jérémy Lefaure
On Wed, 4 Oct 2017 15:14:49 +0300
Jarkko Sakkinen  wrote:

> On Sun, Oct 01, 2017 at 03:30:51PM -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   
> 
> Reviewed-by: Jarkko Sakkinen 
> 
Hi Jarkko,
This patch is an individual patch, it's not really part of a series
(my fault, sorry).

Could you apply this patch to your tree ?

Thank you,
Jérémy


Re: [PATCH 15/18] acpi: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Mon, 02 Oct 2017 14:27:52 +0200
"Rafael J. Wysocki"  wrote:

> 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.
Why is it special code that can't use ARRAY_SIZE ? Is it because this
macro is defined in linux/kernel.h ?

Thank you,
Jérémy


Re: [PATCH 15/18] acpi: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Mon, 02 Oct 2017 14:27:52 +0200
"Rafael J. Wysocki"  wrote:

> 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.
Why is it special code that can't use ARRAY_SIZE ? Is it because this
macro is defined in linux/kernel.h ?

Thank you,
Jérémy


Re: [PATCH 00/18] use ARRAY_SIZE macro

2017-10-02 Thread Jérémy Lefaure
On Mon, 2 Oct 2017 15:22:24 -0400
bfie...@fieldses.org (J. Bruce Fields) wrote:

> Mainly I'd just like to know which you're asking for.  Do you want me to
> apply this, or to ACK it so someone else can?  If it's sent as a series
> I tend to assume the latter.
> 
> But in this case I'm assuming it's the former, so I'll pick up the nfsd
> one
Could you to apply the NFSD patch ("nfsd: use ARRAY_SIZE") with the
Reviewed-by: Jeff Layton ) tag please ?

This patch is an individual patch and it should not have been sent in a
series (sorry about that).

Thank you,
Jérémy


Re: [PATCH 00/18] use ARRAY_SIZE macro

2017-10-02 Thread Jérémy Lefaure
On Mon, 2 Oct 2017 15:22:24 -0400
bfie...@fieldses.org (J. Bruce Fields) wrote:

> Mainly I'd just like to know which you're asking for.  Do you want me to
> apply this, or to ACK it so someone else can?  If it's sent as a series
> I tend to assume the latter.
> 
> But in this case I'm assuming it's the former, so I'll pick up the nfsd
> one
Could you to apply the NFSD patch ("nfsd: use ARRAY_SIZE") with the
Reviewed-by: Jeff Layton ) tag please ?

This patch is an individual patch and it should not have been sent in a
series (sorry about that).

Thank you,
Jérémy


Re: [PATCH 05/18] net: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Mon, 2 Oct 2017 16:07:36 +0300
Andy Shevchenko  wrote:

> > +   {_lut_core0_rev0, ARRAY_SIZE(gainctrl_lut_core0_rev0), 26, 
> > 192,
> > +32},  
> 
> For all such cases I would rather put on one line disregard checkpatch
> warning for better readability.
I agree that it would be better. I didn't know that it was possible to
not follow this rule for anything else than a string.

I am waiting for more comments and I will send a v2.

Thank you,
Jérémy


Re: [PATCH 05/18] net: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Mon, 2 Oct 2017 16:07:36 +0300
Andy Shevchenko  wrote:

> > +   {_lut_core0_rev0, ARRAY_SIZE(gainctrl_lut_core0_rev0), 26, 
> > 192,
> > +32},  
> 
> For all such cases I would rather put on one line disregard checkpatch
> warning for better readability.
I agree that it would be better. I didn't know that it was possible to
not follow this rule for anything else than a string.

I am waiting for more comments and I will send a v2.

Thank you,
Jérémy


Re: [PATCH 01/18] sound: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Sun, 01 Oct 2017 21:16:19 -0700
Joe Perches  wrote:

> 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.

You're right, I missed that one. I will send a v2.

Thank you for your review,
Jérémy


Re: [PATCH 01/18] sound: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Sun, 01 Oct 2017 21:16:19 -0700
Joe Perches  wrote:

> 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.

You're right, I missed that one. I will send a v2.

Thank you for your review,
Jérémy


Re: [PATCH 05/18] net: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Mon, 02 Oct 2017 16:46:29 +0300
Kalle Valo  wrote:

> We have a tree for wireless so usually it's better to submit wireless
> changes on their own but here I assume Dave will apply this to his tree.
> If not, please resubmit the wireless part in a separate patch.
Ok, I note that.

I'll wait Dave's answer and I'll split this patch if needed.

Thank you,
Jérémy


Re: [PATCH 05/18] net: use ARRAY_SIZE

2017-10-02 Thread Jérémy Lefaure
On Mon, 02 Oct 2017 16:46:29 +0300
Kalle Valo  wrote:

> We have a tree for wireless so usually it's better to submit wireless
> changes on their own but here I assume Dave will apply this to his tree.
> If not, please resubmit the wireless part in a separate patch.
Ok, I note that.

I'll wait Dave's answer and I'll split this patch if needed.

Thank you,
Jérémy


Re: [PATCH 00/18] use ARRAY_SIZE macro

2017-10-01 Thread Jérémy Lefaure
On Mon, 2 Oct 2017 09:01:31 +1100
"Tobin C. Harding"  wrote:

> > 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.  
> 
> Why don't you just send individual patches for each subsystem? I'm not a 
> maintainer but I don't see
> how any one person is going to be able to apply this whole series, it is 
> making it hard for
> maintainers if they have to pick patches out from among the series (if indeed 
> any will bother
> doing that).
Yeah, maybe it would have been better to send individual patches.

>From my point of view it's a series because the patches are related (I
did a git format-patch from my local branch). But for the maintainers
point of view, they are individual patches.

As each patch in this series is standalone, the maintainers can pick
the patches they want and apply them individually. So yeah, maybe I
should have sent individual patches. But I also wanted to tie all
patches together as it's the same change.

Anyway, I can tell to each maintainer that they can apply the patches
they're concerned about and next time I may send individual patches.

Thank you for your answer,
Jérémy


Re: [PATCH 00/18] use ARRAY_SIZE macro

2017-10-01 Thread Jérémy Lefaure
On Mon, 2 Oct 2017 09:01:31 +1100
"Tobin C. Harding"  wrote:

> > 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.  
> 
> Why don't you just send individual patches for each subsystem? I'm not a 
> maintainer but I don't see
> how any one person is going to be able to apply this whole series, it is 
> making it hard for
> maintainers if they have to pick patches out from among the series (if indeed 
> any will bother
> doing that).
Yeah, maybe it would have been better to send individual patches.

>From my point of view it's a series because the patches are related (I
did a git format-patch from my local branch). But for the maintainers
point of view, they are individual patches.

As each patch in this series is standalone, the maintainers can pick
the patches they want and apply them individually. So yeah, maybe I
should have sent individual patches. But I also wanted to tie all
patches together as it's the same change.

Anyway, I can tell to each maintainer that they can apply the patches
they're concerned about and next time I may send individual patches.

Thank you for your answer,
Jérémy


[PATCH 04/18] IB/mlx5: Use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
+#include 
 
 #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



[PATCH 04/18] IB/mlx5: Use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
+#include 
 
 #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



[PATCH 05/18] net: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
 drivers/net/ethernet/emulex/benet/be_cmds.c|   4 +-
 drivers/net/ethernet/intel/i40e/i40e_adminq.h  |   3 +-
 drivers/net/ethernet/intel/i40evf/i40e_adminq.h|   3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c  |   3 +-
 drivers/net/ethernet/intel/ixgbevf/vf.c|  17 +-
 drivers/net/usb/kalmia.c   |   9 +-
 .../broadcom/brcm80211/brcmsmac/phy/phytbl_n.c | 473 ++---
 .../net/wireless/realtek/rtlwifi/rtl8723be/hw.c|   9 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/phy.c   |  12 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/table.c |  14 +-
 .../net/wireless/realtek/rtlwifi/rtl8821ae/table.c |  34 +-
 include/net/bond_3ad.h |   3 +-
 net/ipv6/seg6_local.c  |   6 +-
 13 files changed, 177 insertions(+), 413 deletions(-)

diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c 
b/drivers/net/ethernet/emulex/benet/be_cmds.c
index 02dd5246dfae..ec39363afd5f 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -15,6 +15,7 @@
  * Costa Mesa, CA 92626
  */
 
+#include 
 #include 
 #include "be.h"
 #include "be_cmds.h"
@@ -103,10 +104,9 @@ static struct be_cmd_priv_map cmd_priv_map[] = {
 static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem)
 {
int i;
-   int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
u32 cmd_privileges = adapter->cmd_privileges;
 
-   for (i = 0; i < num_entries; i++)
+   for (i = 0; i < ARRAY_SIZE(cmd_priv_map); i++)
if (opcode == cmd_priv_map[i].opcode &&
subsystem == cmd_priv_map[i].subsystem)
if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
diff --git a/drivers/net/ethernet/intel/i40e/i40e_adminq.h 
b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
index 2349fbe04bd2..892083b65b91 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_adminq.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
@@ -27,6 +27,7 @@
 #ifndef _I40E_ADMINQ_H_
 #define _I40E_ADMINQ_H_
 
+#include 
 #include "i40e_osdep.h"
 #include "i40e_status.h"
 #include "i40e_adminq_cmd.h"
@@ -143,7 +144,7 @@ static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
return -EAGAIN;
 
-   if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]
+   if (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix)))
return -ERANGE;
 
return aq_to_posix[aq_rc];
diff --git a/drivers/net/ethernet/intel/i40evf/i40e_adminq.h 
b/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
index e0bfaa3d4a21..5622a24cc74d 100644
--- a/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
+++ b/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
@@ -27,6 +27,7 @@
 #ifndef _I40E_ADMINQ_H_
 #define _I40E_ADMINQ_H_
 
+#include 
 #include "i40e_osdep.h"
 #include "i40e_status.h"
 #include "i40e_adminq_cmd.h"
@@ -143,7 +144,7 @@ static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
return -EAGAIN;
 
-   if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]
+   if (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix)))
return -ERANGE;
 
return aq_to_posix[aq_rc];
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
index 19fbb2f28ea4..9cfc8601fb54 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 
 #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) {
diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.c 
b/drivers/net/ethernet/intel/ixgbevf/vf.c
index 0c25006ce9af..96bfef92fb4c 100644
--- a/drivers/net/ethernet/intel/ixgbevf/vf.c
+++ b/drive

[PATCH 05/18] net: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 drivers/net/ethernet/emulex/benet/be_cmds.c|   4 +-
 drivers/net/ethernet/intel/i40e/i40e_adminq.h  |   3 +-
 drivers/net/ethernet/intel/i40evf/i40e_adminq.h|   3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c  |   3 +-
 drivers/net/ethernet/intel/ixgbevf/vf.c|  17 +-
 drivers/net/usb/kalmia.c   |   9 +-
 .../broadcom/brcm80211/brcmsmac/phy/phytbl_n.c | 473 ++---
 .../net/wireless/realtek/rtlwifi/rtl8723be/hw.c|   9 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/phy.c   |  12 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/table.c |  14 +-
 .../net/wireless/realtek/rtlwifi/rtl8821ae/table.c |  34 +-
 include/net/bond_3ad.h |   3 +-
 net/ipv6/seg6_local.c  |   6 +-
 13 files changed, 177 insertions(+), 413 deletions(-)

diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c 
b/drivers/net/ethernet/emulex/benet/be_cmds.c
index 02dd5246dfae..ec39363afd5f 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -15,6 +15,7 @@
  * Costa Mesa, CA 92626
  */
 
+#include 
 #include 
 #include "be.h"
 #include "be_cmds.h"
@@ -103,10 +104,9 @@ static struct be_cmd_priv_map cmd_priv_map[] = {
 static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem)
 {
int i;
-   int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
u32 cmd_privileges = adapter->cmd_privileges;
 
-   for (i = 0; i < num_entries; i++)
+   for (i = 0; i < ARRAY_SIZE(cmd_priv_map); i++)
if (opcode == cmd_priv_map[i].opcode &&
subsystem == cmd_priv_map[i].subsystem)
if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
diff --git a/drivers/net/ethernet/intel/i40e/i40e_adminq.h 
b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
index 2349fbe04bd2..892083b65b91 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_adminq.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
@@ -27,6 +27,7 @@
 #ifndef _I40E_ADMINQ_H_
 #define _I40E_ADMINQ_H_
 
+#include 
 #include "i40e_osdep.h"
 #include "i40e_status.h"
 #include "i40e_adminq_cmd.h"
@@ -143,7 +144,7 @@ static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
return -EAGAIN;
 
-   if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]
+   if (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix)))
return -ERANGE;
 
return aq_to_posix[aq_rc];
diff --git a/drivers/net/ethernet/intel/i40evf/i40e_adminq.h 
b/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
index e0bfaa3d4a21..5622a24cc74d 100644
--- a/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
+++ b/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
@@ -27,6 +27,7 @@
 #ifndef _I40E_ADMINQ_H_
 #define _I40E_ADMINQ_H_
 
+#include 
 #include "i40e_osdep.h"
 #include "i40e_status.h"
 #include "i40e_adminq_cmd.h"
@@ -143,7 +144,7 @@ static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
return -EAGAIN;
 
-   if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]
+   if (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix)))
return -ERANGE;
 
return aq_to_posix[aq_rc];
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c
index 19fbb2f28ea4..9cfc8601fb54 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 
 #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) {
diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.c 
b/drivers/net/ethernet/intel/ixgbevf/vf.c
index 0c25006ce9af..96bfef92fb4c 100644
--- a/drivers/net/ethernet/intel/ixgbevf/vf.c
+++ b/drivers/net/ethernet/intel/ixgbevf/vf.c

[PATCH 06/18] drm: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
 #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,
_count,
-   sizeof(unique_indices) / sizeof(int),
+   ARRAY_SIZE(unique_indices),
indirect_start_offsets,
_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] & 0x3);
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 
 #include 
 #include 
 #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,
_indirect_reg_count,
-   sizeof(unique_indirect_regs)/sizeof(int),
+   ARRAY_SIZE(unique_indirect_regs),
indirect_start_offsets,
_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] & 0x3);
WREG32(SOC15

[PATCH 06/18] drm: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
 #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,
_count,
-   sizeof(unique_indices) / sizeof(int),
+   ARRAY_SIZE(unique_indices),
indirect_start_offsets,
_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] & 0x3);
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 
 #include 
 #include 
 #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,
_indirect_reg_count,
-   sizeof(unique_indirect_regs)/sizeof(int),
+   ARRAY_SIZE(unique_indirect_regs),
indirect_start_offsets,
_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] & 0x3);
WREG32(SOC15_REG_OFFSET(GC, 0, mmRLC_SRM_INDEX_CNTL_DA

[PATCH 14/18] ipmi: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
+#include 
 
 #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



[PATCH 10/18] orangefs: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
 fs/orangefs/orangefs-debug.h | 4 +++-
 fs/orangefs/orangefs-utils.c | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/orangefs/orangefs-debug.h b/fs/orangefs/orangefs-debug.h
index 387db17cde2b..af1ec4e809e2 100644
--- a/fs/orangefs/orangefs-debug.h
+++ b/fs/orangefs/orangefs-debug.h
@@ -14,8 +14,10 @@
 
 #ifdef __KERNEL__
 #include 
+#include 
 #else
 #include 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
 #defineGOSSIP_NO_DEBUG (__u64)0
@@ -87,6 +89,6 @@ static struct __keyword_mask_s s_kmod_keyword_mask_map[] = {
 };
 
 static const int num_kmod_keyword_mask_map = (int)
-   (sizeof(s_kmod_keyword_mask_map) / sizeof(struct __keyword_mask_s));
+   (ARRAY_SIZE(s_kmod_keyword_mask_map));
 
 #endif /* __ORANGEFS_DEBUG_H */
diff --git a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c
index aab6f1842963..d1fe32e4ffb3 100644
--- a/fs/orangefs/orangefs-utils.c
+++ b/fs/orangefs/orangefs-utils.c
@@ -3,6 +3,7 @@
  *
  * See COPYING in top-level directory.
  */
+#include 
 #include "protocol.h"
 #include "orangefs-kernel.h"
 #include "orangefs-dev-proto.h"
@@ -605,7 +606,7 @@ int orangefs_normalize_to_errno(__s32 error_code)
/* Convert ORANGEFS encoded errno values into regular errno values. */
} else if ((-error_code) & ORANGEFS_ERROR_BIT) {
i = (-error_code) & 
~(ORANGEFS_ERROR_BIT|ORANGEFS_ERROR_CLASS_BITS);
-   if (i < sizeof(PINT_errno_mapping)/sizeof(*PINT_errno_mapping))
+   if (i < ARRAY_SIZE(PINT_errno_mapping))
error_code = -PINT_errno_mapping[i];
else
error_code = -EINVAL;
-- 
2.14.1



[PATCH 14/18] ipmi: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
+#include 
 
 #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



[PATCH 10/18] orangefs: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 fs/orangefs/orangefs-debug.h | 4 +++-
 fs/orangefs/orangefs-utils.c | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/orangefs/orangefs-debug.h b/fs/orangefs/orangefs-debug.h
index 387db17cde2b..af1ec4e809e2 100644
--- a/fs/orangefs/orangefs-debug.h
+++ b/fs/orangefs/orangefs-debug.h
@@ -14,8 +14,10 @@
 
 #ifdef __KERNEL__
 #include 
+#include 
 #else
 #include 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
 #defineGOSSIP_NO_DEBUG (__u64)0
@@ -87,6 +89,6 @@ static struct __keyword_mask_s s_kmod_keyword_mask_map[] = {
 };
 
 static const int num_kmod_keyword_mask_map = (int)
-   (sizeof(s_kmod_keyword_mask_map) / sizeof(struct __keyword_mask_s));
+   (ARRAY_SIZE(s_kmod_keyword_mask_map));
 
 #endif /* __ORANGEFS_DEBUG_H */
diff --git a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c
index aab6f1842963..d1fe32e4ffb3 100644
--- a/fs/orangefs/orangefs-utils.c
+++ b/fs/orangefs/orangefs-utils.c
@@ -3,6 +3,7 @@
  *
  * See COPYING in top-level directory.
  */
+#include 
 #include "protocol.h"
 #include "orangefs-kernel.h"
 #include "orangefs-dev-proto.h"
@@ -605,7 +606,7 @@ int orangefs_normalize_to_errno(__s32 error_code)
/* Convert ORANGEFS encoded errno values into regular errno values. */
} else if ((-error_code) & ORANGEFS_ERROR_BIT) {
i = (-error_code) & 
~(ORANGEFS_ERROR_BIT|ORANGEFS_ERROR_CLASS_BITS);
-   if (i < sizeof(PINT_errno_mapping)/sizeof(*PINT_errno_mapping))
+   if (i < ARRAY_SIZE(PINT_errno_mapping))
error_code = -PINT_errno_mapping[i];
else
error_code = -EINVAL;
-- 
2.14.1



[PATCH 08/18] ecryptfs: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
+#include 
 #include "ecryptfs_kernel.h"
 
 #define DECRYPT0
@@ -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



[PATCH 08/18] ecryptfs: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
+#include 
 #include "ecryptfs_kernel.h"
 
 #define DECRYPT0
@@ -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



[PATCH 13/18] tpm: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
 drivers/char/tpm/tpm_tis.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index ebd0e75a3e4d..e2d1055fb814 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
@@ -365,7 +366,7 @@ static struct pnp_driver tis_pnp_driver = {
},
 };
 
-#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
+#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 2)
 module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
-- 
2.14.1



[PATCH 15/18] acpi: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #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}
 };
 

[PATCH 13/18] tpm: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 drivers/char/tpm/tpm_tis.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index ebd0e75a3e4d..e2d1055fb814 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
@@ -365,7 +366,7 @@ static struct pnp_driver tis_pnp_driver = {
},
 };
 
-#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
+#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 2)
 module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
-- 
2.14.1



[PATCH 15/18] acpi: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #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 acp

[PATCH 12/18] x86: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
+#include 
 
 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



[PATCH 12/18] x86: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
+#include 
 
 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



[PATCH 07/18] scsi: bfa: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #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



[PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 
 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 
 
 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

[PATCH 17/18] staging: rtl8723bs: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c |  5 +-
 drivers/staging/rtl8723bs/core/rtw_rf.c   |  7 +--
 drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c  |  9 ++-
 drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c |  4 +-
 drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c  |  7 +--
 drivers/staging/rtl8723bs/hal/hal_com.c   |  4 +-
 drivers/staging/rtl8723bs/hal/hal_com_phycfg.c| 69 +++
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c| 11 ++--
 8 files changed, 68 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c 
b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 6c59fafeb769..d74159673b5e 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 static struct mlme_handler mlme_sta_tbl[] = {
@@ -562,7 +563,7 @@ void mgt_dispatcher(struct adapter *padapter, union 
recv_frame *precv_frame)
 
index = GetFrameSubType(pframe) >> 4;
 
-   if (index >= (sizeof(mlme_sta_tbl) / sizeof(struct mlme_handler))) {
+   if (index >= ARRAY_SIZE(mlme_sta_tbl)) {
RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do 
not support reserved sub-fr-type =%d\n", index));
return;
}
@@ -2227,7 +2228,7 @@ unsigned int OnAction(struct adapter *padapter, union 
recv_frame *precv_frame)
 
category = frame_body[0];
 
-   for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); 
i++) {
+   for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) {
ptable = _tbl[i];
 
if (category == ptable->num)
diff --git a/drivers/staging/rtl8723bs/core/rtw_rf.c 
b/drivers/staging/rtl8723bs/core/rtw_rf.c
index b87ea4e388c0..07f5577cc073 100644
--- a/drivers/staging/rtl8723bs/core/rtw_rf.c
+++ b/drivers/staging/rtl8723bs/core/rtw_rf.c
@@ -15,6 +15,7 @@
 #define _RTW_RF_C_
 
 #include 
+#include 
 
 
 struct ch_freq {
@@ -44,20 +45,18 @@ static struct ch_freq ch_freq_map[] = {
{216, 5080},/* Japan, means J16 */
 };
 
-static int ch_freq_map_num = (sizeof(ch_freq_map) / sizeof(struct ch_freq));
-
 u32 rtw_ch2freq(u32 channel)
 {
u8 i;
u32 freq = 0;
 
-   for (i = 0; i < ch_freq_map_num; i++) {
+   for (i = 0; i < ARRAY_SIZE(ch_freq_map); i++) {
if (channel == ch_freq_map[i].channel) {
freq = ch_freq_map[i].frequency;
break;
}
}
-   if (i == ch_freq_map_num)
+   if (i == ARRAY_SIZE(ch_freq_map))
freq = 2412;
 
return freq;
diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c 
b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
index 51d4219177d3..951585467ab1 100644
--- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
+++ b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
@@ -13,7 +13,7 @@
 *
 **/
 
-
+#include 
 #include "odm_precomp.h"
 
 static bool CheckPositive(
@@ -268,7 +268,7 @@ static u32 Array_MP_8723B_AGC_TAB[] = {
 void ODM_ReadAndConfig_MP_8723B_AGC_TAB(PDM_ODM_T pDM_Odm)
 {
u32 i = 0;
-   u32 ArrayLen = sizeof(Array_MP_8723B_AGC_TAB)/sizeof(u32);
+   u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_AGC_TAB);
u32 *Array = Array_MP_8723B_AGC_TAB;
 
ODM_RT_TRACE(
@@ -537,7 +537,7 @@ static u32 Array_MP_8723B_PHY_REG[] = {
 void ODM_ReadAndConfig_MP_8723B_PHY_REG(PDM_ODM_T pDM_Odm)
 {
u32 i = 0;
-   u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG)/sizeof(u32);
+   u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_PHY_REG);
u32 *Array = Array_MP_8723B_PHY_REG;
 
ODM_RT_TRACE(
@@ -617,7 +617,6 @@ static u32 Array_MP_8723B_PHY_REG_PG[] = {
 void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm)
 {
u32 i = 0;
-   u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG_PG)/sizeof(u32);
u32 *Array = Array_MP_8723B_PHY_REG_PG;
 
ODM_RT_TRACE(
@@ -630,7 +629,7 @@ void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T 
pDM_Odm)
pDM_Odm->PhyRegPgVersion = 1;
pDM_Odm->PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE;
 
-   for (i = 0; i < ArrayLen; i += 6) {
+   for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_PHY_REG_PG); i += 6) {
u32 v1 = Array[i];
u32 v2 = Array[i+1];
  

[PATCH 11/18] dm space map metadata: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@lse.epita.fr>
---
 drivers/md/persistent-data/dm-space-map-metadata.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c 
b/drivers/md/persistent-data/dm-space-map-metadata.c
index 4aed69d9dd17..aec449243966 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define DM_MSG_PREFIX "space map metadata"
 
@@ -111,7 +112,7 @@ static bool brb_empty(struct bop_ring_buffer *brb)
 static unsigned brb_next(struct bop_ring_buffer *brb, unsigned old)
 {
unsigned r = old + 1;
-   return (r >= (sizeof(brb->bops) / sizeof(*brb->bops))) ? 0 : r;
+   return r >= ARRAY_SIZE(brb->bops) ? 0 : r;
 }
 
 static int brb_push(struct bop_ring_buffer *brb,
-- 
2.14.1



[PATCH 07/18] scsi: bfa: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #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



[PATCH 18/18] staging: rtlwifi: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 
 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 
 
 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 
 
 static bool chec

[PATCH 11/18] dm space map metadata: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 drivers/md/persistent-data/dm-space-map-metadata.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c 
b/drivers/md/persistent-data/dm-space-map-metadata.c
index 4aed69d9dd17..aec449243966 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define DM_MSG_PREFIX "space map metadata"
 
@@ -111,7 +112,7 @@ static bool brb_empty(struct bop_ring_buffer *brb)
 static unsigned brb_next(struct bop_ring_buffer *brb, unsigned old)
 {
unsigned r = old + 1;
-   return (r >= (sizeof(brb->bops) / sizeof(*brb->bops))) ? 0 : r;
+   return r >= ARRAY_SIZE(brb->bops) ? 0 : r;
 }
 
 static int brb_push(struct bop_ring_buffer *brb,
-- 
2.14.1



[PATCH 17/18] staging: rtl8723bs: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c |  5 +-
 drivers/staging/rtl8723bs/core/rtw_rf.c   |  7 +--
 drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c  |  9 ++-
 drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c |  4 +-
 drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c  |  7 +--
 drivers/staging/rtl8723bs/hal/hal_com.c   |  4 +-
 drivers/staging/rtl8723bs/hal/hal_com_phycfg.c| 69 +++
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c| 11 ++--
 8 files changed, 68 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c 
b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 6c59fafeb769..d74159673b5e 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 static struct mlme_handler mlme_sta_tbl[] = {
@@ -562,7 +563,7 @@ void mgt_dispatcher(struct adapter *padapter, union 
recv_frame *precv_frame)
 
index = GetFrameSubType(pframe) >> 4;
 
-   if (index >= (sizeof(mlme_sta_tbl) / sizeof(struct mlme_handler))) {
+   if (index >= ARRAY_SIZE(mlme_sta_tbl)) {
RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do 
not support reserved sub-fr-type =%d\n", index));
return;
}
@@ -2227,7 +2228,7 @@ unsigned int OnAction(struct adapter *padapter, union 
recv_frame *precv_frame)
 
category = frame_body[0];
 
-   for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); 
i++) {
+   for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) {
ptable = _tbl[i];
 
if (category == ptable->num)
diff --git a/drivers/staging/rtl8723bs/core/rtw_rf.c 
b/drivers/staging/rtl8723bs/core/rtw_rf.c
index b87ea4e388c0..07f5577cc073 100644
--- a/drivers/staging/rtl8723bs/core/rtw_rf.c
+++ b/drivers/staging/rtl8723bs/core/rtw_rf.c
@@ -15,6 +15,7 @@
 #define _RTW_RF_C_
 
 #include 
+#include 
 
 
 struct ch_freq {
@@ -44,20 +45,18 @@ static struct ch_freq ch_freq_map[] = {
{216, 5080},/* Japan, means J16 */
 };
 
-static int ch_freq_map_num = (sizeof(ch_freq_map) / sizeof(struct ch_freq));
-
 u32 rtw_ch2freq(u32 channel)
 {
u8 i;
u32 freq = 0;
 
-   for (i = 0; i < ch_freq_map_num; i++) {
+   for (i = 0; i < ARRAY_SIZE(ch_freq_map); i++) {
if (channel == ch_freq_map[i].channel) {
freq = ch_freq_map[i].frequency;
break;
}
}
-   if (i == ch_freq_map_num)
+   if (i == ARRAY_SIZE(ch_freq_map))
freq = 2412;
 
return freq;
diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c 
b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
index 51d4219177d3..951585467ab1 100644
--- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
+++ b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
@@ -13,7 +13,7 @@
 *
 **/
 
-
+#include 
 #include "odm_precomp.h"
 
 static bool CheckPositive(
@@ -268,7 +268,7 @@ static u32 Array_MP_8723B_AGC_TAB[] = {
 void ODM_ReadAndConfig_MP_8723B_AGC_TAB(PDM_ODM_T pDM_Odm)
 {
u32 i = 0;
-   u32 ArrayLen = sizeof(Array_MP_8723B_AGC_TAB)/sizeof(u32);
+   u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_AGC_TAB);
u32 *Array = Array_MP_8723B_AGC_TAB;
 
ODM_RT_TRACE(
@@ -537,7 +537,7 @@ static u32 Array_MP_8723B_PHY_REG[] = {
 void ODM_ReadAndConfig_MP_8723B_PHY_REG(PDM_ODM_T pDM_Odm)
 {
u32 i = 0;
-   u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG)/sizeof(u32);
+   u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_PHY_REG);
u32 *Array = Array_MP_8723B_PHY_REG;
 
ODM_RT_TRACE(
@@ -617,7 +617,6 @@ static u32 Array_MP_8723B_PHY_REG_PG[] = {
 void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm)
 {
u32 i = 0;
-   u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG_PG)/sizeof(u32);
u32 *Array = Array_MP_8723B_PHY_REG_PG;
 
ODM_RT_TRACE(
@@ -630,7 +629,7 @@ void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T 
pDM_Odm)
pDM_Odm->PhyRegPgVersion = 1;
pDM_Odm->PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE;
 
-   for (i = 0; i < ArrayLen; i += 6) {
+   for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_PHY_REG_PG); i += 6) {
u32 v1 = Array[i];
u32 v2 = Array[i+1];
u32 v3 = Array[i+2];
diff --git a/d

[PATCH 03/18] media: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
+#include 
 
 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 
 #include 
 #include 
+#include 
 
 #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 
 #include 
+#include 
 
 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 = _standards[0],
-   .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+   .num_stds = ARRAY_SIZE(hexium_standards),
.std_callback = _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 
 #include 
+#include 
 
 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 = _standards[0],
-   .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+   .num_stds = ARRAY_SIZE(hexium_standards),
.std_callback = _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 
 #include 

[PATCH 09/18] nfsd: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
+#include 
 
 #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 = _ops[i];
if (!debugfs_create_file(op->file, mode, debug_dir, op, 
_nfsd))
goto fail;
-- 
2.14.1



[PATCH 09/18] nfsd: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
+#include 
 
 #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 = _ops[i];
if (!debugfs_create_file(op->file, mode, debug_dir, op, 
_nfsd))
goto fail;
-- 
2.14.1



[PATCH 03/18] media: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
+#include 
 
 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 
 #include 
 #include 
+#include 
 
 #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 
 #include 
+#include 
 
 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 = _standards[0],
-   .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+   .num_stds = ARRAY_SIZE(hexium_standards),
.std_callback = _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 
 #include 
+#include 
 
 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 = _standards[0],
-   .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
+   .num_stds = ARRAY_SIZE(hexium_standards),
.std_callback = _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 
 #include 
 #include 
+#include 
 
 #include &

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

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 /* HRT_GDC_N */
 #include "gdc_device.h"
+#include 
 
 /* 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



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

2017-10-01 Thread Jérémy Lefaure
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 
---
 .../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 
 /* HRT_GDC_N */
 #include "gdc_device.h"
+#include 
 
 /* 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



[PATCH 00/18] use ARRAY_SIZE macro

2017-10-01 Thread Jérémy Lefaure
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


[PATCH 00/18] use ARRAY_SIZE macro

2017-10-01 Thread Jérémy Lefaure
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


[PATCH 02/18] tracing/filter: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
+#include 
 
 #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 = _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



[PATCH 02/18] tracing/filter: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
+#include 
 
 #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 = _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



[PATCH 01/18] sound: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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.lefa...@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 
 #include 
 #include 
+#include 
 
 #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 
 #include 
 #include 
+#include 
 #include 
 #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



[PATCH 01/18] sound: use ARRAY_SIZE

2017-10-01 Thread Jérémy Lefaure
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 
---
 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 
 #include 
 #include 
+#include 
 
 #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 
 #include 
 #include 
+#include 
 #include 
 #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



[PATCH 1/1] Coccinelle: array_size: report even if include is missing

2017-09-13 Thread Jérémy Lefaure
Rule r does not depend on rule i (which is the include of
linux/kernel.h) so the output should not depend on i in
org and report mode.

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---

I have tested this patch in report mode on the file
drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c which does not
use ARRAY_SIZE and does not include linux/kernel.h.

 scripts/coccinelle/misc/array_size.cocci | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/coccinelle/misc/array_size.cocci 
b/scripts/coccinelle/misc/array_size.cocci
index 6ec05710b017..09520f0941f0 100644
--- a/scripts/coccinelle/misc/array_size.cocci
+++ b/scripts/coccinelle/misc/array_size.cocci
@@ -72,13 +72,13 @@ position p;
  (sizeof(E)@p /sizeof(T))
 )
 
-@script:python depends on i&@
+@script:python depends on org@
 p << r.p;
 @@
 
 coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
 
-@script:python depends on i&@
+@script:python depends on report@
 p << r.p;
 @@
 
-- 
2.14.1



[PATCH 1/1] Coccinelle: array_size: report even if include is missing

2017-09-13 Thread Jérémy Lefaure
Rule r does not depend on rule i (which is the include of
linux/kernel.h) so the output should not depend on i in
org and report mode.

Signed-off-by: Jérémy Lefaure 
---

I have tested this patch in report mode on the file
drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c which does not
use ARRAY_SIZE and does not include linux/kernel.h.

 scripts/coccinelle/misc/array_size.cocci | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/coccinelle/misc/array_size.cocci 
b/scripts/coccinelle/misc/array_size.cocci
index 6ec05710b017..09520f0941f0 100644
--- a/scripts/coccinelle/misc/array_size.cocci
+++ b/scripts/coccinelle/misc/array_size.cocci
@@ -72,13 +72,13 @@ position p;
  (sizeof(E)@p /sizeof(T))
 )
 
-@script:python depends on i&@
+@script:python depends on org@
 p << r.p;
 @@
 
 coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
 
-@script:python depends on i&@
+@script:python depends on report@
 p << r.p;
 @@
 
-- 
2.14.1



[RESEND PATCH] c6x: remove unused KTHREAD_SIZE definition

2017-09-04 Thread Jérémy Lefaure
KTHREAD_SIZE has never been used since it has been defined for c6x arch.
Let's remove this useless definition.

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
Acked-by: Mark Salter <msal...@redhat.com>
---
Hi,
I sent this patch in June. It was acked by Mark Salter but I don't see
it in the last kernel release so I resend it today.

 arch/c6x/kernel/asm-offsets.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/c6x/kernel/asm-offsets.c b/arch/c6x/kernel/asm-offsets.c
index 60f1e437745d..f8ededbfb63f 100644
--- a/arch/c6x/kernel/asm-offsets.c
+++ b/arch/c6x/kernel/asm-offsets.c
@@ -106,7 +106,6 @@ void foo(void)
/* These would be unneccessary if we ran asm files
 * through the preprocessor.
 */
-   DEFINE(KTHREAD_SIZE, THREAD_SIZE);
DEFINE(KTHREAD_SHIFT, THREAD_SHIFT);
DEFINE(KTHREAD_START_SP, THREAD_START_SP);
DEFINE(ENOSYS_, ENOSYS);
-- 
2.14.1



[RESEND PATCH] c6x: remove unused KTHREAD_SIZE definition

2017-09-04 Thread Jérémy Lefaure
KTHREAD_SIZE has never been used since it has been defined for c6x arch.
Let's remove this useless definition.

Signed-off-by: Jérémy Lefaure 
Acked-by: Mark Salter 
---
Hi,
I sent this patch in June. It was acked by Mark Salter but I don't see
it in the last kernel release so I resend it today.

 arch/c6x/kernel/asm-offsets.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/c6x/kernel/asm-offsets.c b/arch/c6x/kernel/asm-offsets.c
index 60f1e437745d..f8ededbfb63f 100644
--- a/arch/c6x/kernel/asm-offsets.c
+++ b/arch/c6x/kernel/asm-offsets.c
@@ -106,7 +106,6 @@ void foo(void)
/* These would be unneccessary if we ran asm files
 * through the preprocessor.
 */
-   DEFINE(KTHREAD_SIZE, THREAD_SIZE);
DEFINE(KTHREAD_SHIFT, THREAD_SHIFT);
DEFINE(KTHREAD_START_SP, THREAD_START_SP);
DEFINE(ENOSYS_, ENOSYS);
-- 
2.14.1



Re: [PATCH 21/22] fscache: fix fscache_objlist_show format processing

2017-09-04 Thread Jérémy Lefaure
> gcc points out a minor bug in the handling of unknown
> cookie types, which could result in a string overflow
> when the integer is copied into a 3-byte string:
> 
> fs/fscache/object-list.c: In function 'fscache_objlist_show':
> fs/fscache/object-list.c:265:19: error: 'sprintf' may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=] sprintf(_type, "%02u", cookie->def->type);
> ^~ fs/fscache/object-list.c:265:4: note: 'sprintf' output between
> 3 and 4 bytes into a destination of size 3
> 
> This is currently harmless as no code sets a type other
> than 0 or 1, but it makes sense to use snprintf() here
> to avoid overflowing the array if that changes.
> 
> Signed-off-by: Arnd Bergmann 
> ---
Hi,
I sent a patch to fix this issue in April [1]. It was accepted by David
Howells [2]. I don't know why it wasn't upstreamed.

>  fs/fscache/object-list.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
> index 67f940892ef8..b5ab06fabc60 100644
> --- a/fs/fscache/object-list.c
> +++ b/fs/fscache/object-list.c
> @@ -262,7 +262,8 @@ static int fscache_objlist_show(struct seq_file
> *m, void *v) type = "DT";
>   break;
>   default:
> - sprintf(_type, "%02u", cookie->def->type);
> + snprintf(_type, sizeof(_type), "%02u",
> +  cookie->def->type);
>   type = _type;
>   break;
>   }
In my patch I didn't use snprintf (which is fine) but I used the
hexadecimal value (as it is in the documentation [3]). Is it too late
to change this patch ? If it is, I can send a patch to use an hex value.

Thank you,
Jérémy

[1]: https://marc.info/?l=linux-kernel=149263432022839=4
[2]: https://marc.info/?l=linux-kernel=149330544916184=4
[3]: see Documentation/filesystems/caching/fscache.txt



Re: [PATCH 21/22] fscache: fix fscache_objlist_show format processing

2017-09-04 Thread Jérémy Lefaure
> gcc points out a minor bug in the handling of unknown
> cookie types, which could result in a string overflow
> when the integer is copied into a 3-byte string:
> 
> fs/fscache/object-list.c: In function 'fscache_objlist_show':
> fs/fscache/object-list.c:265:19: error: 'sprintf' may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=] sprintf(_type, "%02u", cookie->def->type);
> ^~ fs/fscache/object-list.c:265:4: note: 'sprintf' output between
> 3 and 4 bytes into a destination of size 3
> 
> This is currently harmless as no code sets a type other
> than 0 or 1, but it makes sense to use snprintf() here
> to avoid overflowing the array if that changes.
> 
> Signed-off-by: Arnd Bergmann 
> ---
Hi,
I sent a patch to fix this issue in April [1]. It was accepted by David
Howells [2]. I don't know why it wasn't upstreamed.

>  fs/fscache/object-list.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
> index 67f940892ef8..b5ab06fabc60 100644
> --- a/fs/fscache/object-list.c
> +++ b/fs/fscache/object-list.c
> @@ -262,7 +262,8 @@ static int fscache_objlist_show(struct seq_file
> *m, void *v) type = "DT";
>   break;
>   default:
> - sprintf(_type, "%02u", cookie->def->type);
> + snprintf(_type, sizeof(_type), "%02u",
> +  cookie->def->type);
>   type = _type;
>   break;
>   }
In my patch I didn't use snprintf (which is fine) but I used the
hexadecimal value (as it is in the documentation [3]). Is it too late
to change this patch ? If it is, I can send a patch to use an hex value.

Thank you,
Jérémy

[1]: https://marc.info/?l=linux-kernel=149263432022839=4
[2]: https://marc.info/?l=linux-kernel=149330544916184=4
[3]: see Documentation/filesystems/caching/fscache.txt



[PATCH v2] edac, i5000, i5400: fix definition of nrecmemb register

2017-06-28 Thread Jérémy Lefaure
In i5000 and i5400 edac drivers, the register nrecmemb is defined as a
16 bits value which result in wrong shifts in the code:
  CHECK   drivers/edac/i5000_edac.c
drivers/edac/i5000_edac.c:485:15: warning: right shift by bigger than
source value
drivers/edac/i5000_edac.c:580:23: warning: right shift by bigger than
source value
  CC  drivers/edac/i5000_edac.o
  CHECK   drivers/edac/i5400_edac.c
drivers/edac/i5400_edac.c:391:36: warning: right shift by bigger than
source value
drivers/edac/i5400_edac.c:401:37: warning: right shift by bigger than
source value
  CC  drivers/edac/i5400_edac.o

In the datasheets ([1], section 3.9.22.20 and [2], section 3.9.22.21),
this register is a 32 bits register. A u32 value for the register fixes
the wrong shifts warnings and matches the datasheet.

This patch also fixes the mask to access to the CAS bits [27:16] in
the i5000 edac driver.

[1]: 
https://www.intel.com/content/dam/doc/datasheet/5000p-5000v-5000z-chipset-memory-controller-hub-datasheet.pdf
[2]: 
https://www.intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---

I have found this error thanks to the sparse tool. Please note that this patch
hasn't been tested on real hardware.

v2:
* fix mask in NREC_CAS macro (0xFFF instead of 0x1FFF)
* fix bits description ("[27:16] instead of "[16 to 28]") in commit message


 drivers/edac/i5000_edac.c | 6 +++---
 drivers/edac/i5400_edac.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index f683919981b0..8f5a56e25bd2 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -227,7 +227,7 @@
 #defineNREC_RDWR(x)(((x)>>11) & 1)
 #defineNREC_RANK(x)(((x)>>8) & 0x7)
 #defineNRECMEMB0xC0
-#defineNREC_CAS(x) (((x)>>16) & 0xFF)
+#defineNREC_CAS(x) (((x)>>16) & 0xFFF)
 #defineNREC_RAS(x) ((x) & 0x7FFF)
 #defineNRECFGLOG   0xC4
 #defineNREEECFBDA  0xC8
@@ -371,7 +371,7 @@ struct i5000_error_info {
/* These registers are input ONLY if there was a
 * Non-Recoverable Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -407,7 +407,7 @@ static void i5000_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 37a9ba71da44..cd889edc8516 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -368,7 +368,7 @@ struct i5400_error_info {
 
/* These registers are input ONLY if there was a Non-Rec Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -458,7 +458,7 @@ static void i5400_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
-- 
2.13.2



[PATCH v2] edac, i5000, i5400: fix definition of nrecmemb register

2017-06-28 Thread Jérémy Lefaure
In i5000 and i5400 edac drivers, the register nrecmemb is defined as a
16 bits value which result in wrong shifts in the code:
  CHECK   drivers/edac/i5000_edac.c
drivers/edac/i5000_edac.c:485:15: warning: right shift by bigger than
source value
drivers/edac/i5000_edac.c:580:23: warning: right shift by bigger than
source value
  CC  drivers/edac/i5000_edac.o
  CHECK   drivers/edac/i5400_edac.c
drivers/edac/i5400_edac.c:391:36: warning: right shift by bigger than
source value
drivers/edac/i5400_edac.c:401:37: warning: right shift by bigger than
source value
  CC  drivers/edac/i5400_edac.o

In the datasheets ([1], section 3.9.22.20 and [2], section 3.9.22.21),
this register is a 32 bits register. A u32 value for the register fixes
the wrong shifts warnings and matches the datasheet.

This patch also fixes the mask to access to the CAS bits [27:16] in
the i5000 edac driver.

[1]: 
https://www.intel.com/content/dam/doc/datasheet/5000p-5000v-5000z-chipset-memory-controller-hub-datasheet.pdf
[2]: 
https://www.intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf

Signed-off-by: Jérémy Lefaure 
---

I have found this error thanks to the sparse tool. Please note that this patch
hasn't been tested on real hardware.

v2:
* fix mask in NREC_CAS macro (0xFFF instead of 0x1FFF)
* fix bits description ("[27:16] instead of "[16 to 28]") in commit message


 drivers/edac/i5000_edac.c | 6 +++---
 drivers/edac/i5400_edac.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index f683919981b0..8f5a56e25bd2 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -227,7 +227,7 @@
 #defineNREC_RDWR(x)(((x)>>11) & 1)
 #defineNREC_RANK(x)(((x)>>8) & 0x7)
 #defineNRECMEMB0xC0
-#defineNREC_CAS(x) (((x)>>16) & 0xFF)
+#defineNREC_CAS(x) (((x)>>16) & 0xFFF)
 #defineNREC_RAS(x) ((x) & 0x7FFF)
 #defineNRECFGLOG   0xC4
 #defineNREEECFBDA  0xC8
@@ -371,7 +371,7 @@ struct i5000_error_info {
/* These registers are input ONLY if there was a
 * Non-Recoverable Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -407,7 +407,7 @@ static void i5000_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 37a9ba71da44..cd889edc8516 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -368,7 +368,7 @@ struct i5400_error_info {
 
/* These registers are input ONLY if there was a Non-Rec Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -458,7 +458,7 @@ static void i5400_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
-- 
2.13.2



Re: [PATCH] edac, i5000, i5400: fix definition of nrecmemb register

2017-06-28 Thread Jérémy Lefaure
On Wed, 28 Jun 2017 18:08:51 +0200
Borislav Petkov <b...@alien8.de> wrote:

> On Mon, Jun 12, 2017 at 01:47:58PM -0400, Jérémy Lefaure wrote:
> > In i5000 and i5400 edac drivers, the register nrecmemb is defined as a
> > 16 bits value which result in wrong shifts in the code:
> >   CHECK   drivers/edac/i5000_edac.c
> > drivers/edac/i5000_edac.c:485:15: warning: right shift by bigger than
> > source value
> > drivers/edac/i5000_edac.c:580:23: warning: right shift by bigger than
> > source value
> >   CC  drivers/edac/i5000_edac.o
> >   CHECK   drivers/edac/i5400_edac.c
> > drivers/edac/i5400_edac.c:391:36: warning: right shift by bigger than
> > source value
> > drivers/edac/i5400_edac.c:401:37: warning: right shift by bigger than
> > source value
> >   CC  drivers/edac/i5400_edac.o
> > 
> > In the datasheets ([1], section 3.9.22.20 and [2], section 3.9.22.21),
> > this register is a 32 bits register. A u32 value for the register fixes
> > the wrong shifts warnings and matches the datasheet.
> > 
> > This patch also fixes the mask to access to the CAS bits [16 to 28] in
> > the i5000 edac driver.
> > 
> > [1]: 
> > https://www.intel.com/content/dam/doc/datasheet/5000p-5000v-5000z-chipset-memory-controller-hub-datasheet.pdf
> >   
> 
> Well, the CAS field length here is [27:16], see below.
> 
> > [2]: 
> > https://www.intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf
> >   
> 
> Here it is [28:16].
> 
> > Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
> > ---
> > 
> > I have found this error thanks to the sparse tool. Please note that this 
> > patch
> > hasn't been tested on real hardware.
> > 
> > 
> >  drivers/edac/i5000_edac.c | 6 +++---
> >  drivers/edac/i5400_edac.c | 4 ++--
> >  2 files changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
> > index f683919981b0..c79016ade51e 100644
> > --- a/drivers/edac/i5000_edac.c
> > +++ b/drivers/edac/i5000_edac.c
> > @@ -227,7 +227,7 @@
> >  #defineNREC_RDWR(x)(((x)>>11) & 1)
> >  #defineNREC_RANK(x)(((x)>>8) & 0x7)
> >  #defineNRECMEMB0xC0
> > -#defineNREC_CAS(x) (((x)>>16) & 0xFF)
> > +#defineNREC_CAS(x) (((x)>>16) & 0x1FFF)  
> 
> That is still incorrect. According to the 5000? datasheet above,
> NRECMEMB has the CAS field in bits [27:16]. That's 12 bits, so the mask
> should be 0xFFF. IOW,
> 
> #define   NREC_CAS(x) (((x)>>16) & 0xFFF)
> 
> The 0x1FFF mask is correct for the 5400 driver because the CAS field
> there is [28:16].
> 
> The fact that no one caught this by now goes to show how many people are
> actually using this thing. :-\
> 

You're right. I think that I inverted the 2 datasheets when I reread my
patch before sending it. Sorry about that. I will send a v2.

Jérémy


Re: [PATCH] edac, i5000, i5400: fix definition of nrecmemb register

2017-06-28 Thread Jérémy Lefaure
On Wed, 28 Jun 2017 18:08:51 +0200
Borislav Petkov  wrote:

> On Mon, Jun 12, 2017 at 01:47:58PM -0400, Jérémy Lefaure wrote:
> > In i5000 and i5400 edac drivers, the register nrecmemb is defined as a
> > 16 bits value which result in wrong shifts in the code:
> >   CHECK   drivers/edac/i5000_edac.c
> > drivers/edac/i5000_edac.c:485:15: warning: right shift by bigger than
> > source value
> > drivers/edac/i5000_edac.c:580:23: warning: right shift by bigger than
> > source value
> >   CC  drivers/edac/i5000_edac.o
> >   CHECK   drivers/edac/i5400_edac.c
> > drivers/edac/i5400_edac.c:391:36: warning: right shift by bigger than
> > source value
> > drivers/edac/i5400_edac.c:401:37: warning: right shift by bigger than
> > source value
> >   CC  drivers/edac/i5400_edac.o
> > 
> > In the datasheets ([1], section 3.9.22.20 and [2], section 3.9.22.21),
> > this register is a 32 bits register. A u32 value for the register fixes
> > the wrong shifts warnings and matches the datasheet.
> > 
> > This patch also fixes the mask to access to the CAS bits [16 to 28] in
> > the i5000 edac driver.
> > 
> > [1]: 
> > https://www.intel.com/content/dam/doc/datasheet/5000p-5000v-5000z-chipset-memory-controller-hub-datasheet.pdf
> >   
> 
> Well, the CAS field length here is [27:16], see below.
> 
> > [2]: 
> > https://www.intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf
> >   
> 
> Here it is [28:16].
> 
> > Signed-off-by: Jérémy Lefaure 
> > ---
> > 
> > I have found this error thanks to the sparse tool. Please note that this 
> > patch
> > hasn't been tested on real hardware.
> > 
> > 
> >  drivers/edac/i5000_edac.c | 6 +++---
> >  drivers/edac/i5400_edac.c | 4 ++--
> >  2 files changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
> > index f683919981b0..c79016ade51e 100644
> > --- a/drivers/edac/i5000_edac.c
> > +++ b/drivers/edac/i5000_edac.c
> > @@ -227,7 +227,7 @@
> >  #defineNREC_RDWR(x)(((x)>>11) & 1)
> >  #defineNREC_RANK(x)(((x)>>8) & 0x7)
> >  #defineNRECMEMB0xC0
> > -#defineNREC_CAS(x) (((x)>>16) & 0xFF)
> > +#defineNREC_CAS(x) (((x)>>16) & 0x1FFF)  
> 
> That is still incorrect. According to the 5000? datasheet above,
> NRECMEMB has the CAS field in bits [27:16]. That's 12 bits, so the mask
> should be 0xFFF. IOW,
> 
> #define   NREC_CAS(x) (((x)>>16) & 0xFFF)
> 
> The 0x1FFF mask is correct for the 5400 driver because the CAS field
> there is [28:16].
> 
> The fact that no one caught this by now goes to show how many people are
> actually using this thing. :-\
> 

You're right. I think that I inverted the 2 datasheets when I reread my
patch before sending it. Sorry about that. I will send a v2.

Jérémy


[PATCH] edac, i5000, i5400: fix definition of nrecmemb register

2017-06-12 Thread Jérémy Lefaure
In i5000 and i5400 edac drivers, the register nrecmemb is defined as a
16 bits value which result in wrong shifts in the code:
  CHECK   drivers/edac/i5000_edac.c
drivers/edac/i5000_edac.c:485:15: warning: right shift by bigger than
source value
drivers/edac/i5000_edac.c:580:23: warning: right shift by bigger than
source value
  CC  drivers/edac/i5000_edac.o
  CHECK   drivers/edac/i5400_edac.c
drivers/edac/i5400_edac.c:391:36: warning: right shift by bigger than
source value
drivers/edac/i5400_edac.c:401:37: warning: right shift by bigger than
source value
  CC  drivers/edac/i5400_edac.o

In the datasheets ([1], section 3.9.22.20 and [2], section 3.9.22.21),
this register is a 32 bits register. A u32 value for the register fixes
the wrong shifts warnings and matches the datasheet.

This patch also fixes the mask to access to the CAS bits [16 to 28] in
the i5000 edac driver.

[1]: 
https://www.intel.com/content/dam/doc/datasheet/5000p-5000v-5000z-chipset-memory-controller-hub-datasheet.pdf
[2]: 
https://www.intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---

I have found this error thanks to the sparse tool. Please note that this patch
hasn't been tested on real hardware.


 drivers/edac/i5000_edac.c | 6 +++---
 drivers/edac/i5400_edac.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index f683919981b0..c79016ade51e 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -227,7 +227,7 @@
 #defineNREC_RDWR(x)(((x)>>11) & 1)
 #defineNREC_RANK(x)(((x)>>8) & 0x7)
 #defineNRECMEMB0xC0
-#defineNREC_CAS(x) (((x)>>16) & 0xFF)
+#defineNREC_CAS(x) (((x)>>16) & 0x1FFF)
 #defineNREC_RAS(x) ((x) & 0x7FFF)
 #defineNRECFGLOG   0xC4
 #defineNREEECFBDA  0xC8
@@ -371,7 +371,7 @@ struct i5000_error_info {
/* These registers are input ONLY if there was a
 * Non-Recoverable Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -407,7 +407,7 @@ static void i5000_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 37a9ba71da44..cd889edc8516 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -368,7 +368,7 @@ struct i5400_error_info {
 
/* These registers are input ONLY if there was a Non-Rec Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -458,7 +458,7 @@ static void i5400_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
-- 
2.13.1



[PATCH] edac, i5000, i5400: fix definition of nrecmemb register

2017-06-12 Thread Jérémy Lefaure
In i5000 and i5400 edac drivers, the register nrecmemb is defined as a
16 bits value which result in wrong shifts in the code:
  CHECK   drivers/edac/i5000_edac.c
drivers/edac/i5000_edac.c:485:15: warning: right shift by bigger than
source value
drivers/edac/i5000_edac.c:580:23: warning: right shift by bigger than
source value
  CC  drivers/edac/i5000_edac.o
  CHECK   drivers/edac/i5400_edac.c
drivers/edac/i5400_edac.c:391:36: warning: right shift by bigger than
source value
drivers/edac/i5400_edac.c:401:37: warning: right shift by bigger than
source value
  CC  drivers/edac/i5400_edac.o

In the datasheets ([1], section 3.9.22.20 and [2], section 3.9.22.21),
this register is a 32 bits register. A u32 value for the register fixes
the wrong shifts warnings and matches the datasheet.

This patch also fixes the mask to access to the CAS bits [16 to 28] in
the i5000 edac driver.

[1]: 
https://www.intel.com/content/dam/doc/datasheet/5000p-5000v-5000z-chipset-memory-controller-hub-datasheet.pdf
[2]: 
https://www.intel.se/content/dam/doc/datasheet/5400-chipset-memory-controller-hub-datasheet.pdf

Signed-off-by: Jérémy Lefaure 
---

I have found this error thanks to the sparse tool. Please note that this patch
hasn't been tested on real hardware.


 drivers/edac/i5000_edac.c | 6 +++---
 drivers/edac/i5400_edac.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index f683919981b0..c79016ade51e 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -227,7 +227,7 @@
 #defineNREC_RDWR(x)(((x)>>11) & 1)
 #defineNREC_RANK(x)(((x)>>8) & 0x7)
 #defineNRECMEMB0xC0
-#defineNREC_CAS(x) (((x)>>16) & 0xFF)
+#defineNREC_CAS(x) (((x)>>16) & 0x1FFF)
 #defineNREC_RAS(x) ((x) & 0x7FFF)
 #defineNRECFGLOG   0xC4
 #defineNREEECFBDA  0xC8
@@ -371,7 +371,7 @@ struct i5000_error_info {
/* These registers are input ONLY if there was a
 * Non-Recoverable Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -407,7 +407,7 @@ static void i5000_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 37a9ba71da44..cd889edc8516 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -368,7 +368,7 @@ struct i5400_error_info {
 
/* These registers are input ONLY if there was a Non-Rec Error */
u16 nrecmema;   /* Non-Recoverable Mem log A */
-   u16 nrecmemb;   /* Non-Recoverable Mem log B */
+   u32 nrecmemb;   /* Non-Recoverable Mem log B */
 
 };
 
@@ -458,7 +458,7 @@ static void i5400_get_error_info(struct mem_ctl_info *mci,
NERR_FAT_FBD, >nerr_fat_fbd);
pci_read_config_word(pvt->branchmap_werrors,
NRECMEMA, >nrecmema);
-   pci_read_config_word(pvt->branchmap_werrors,
+   pci_read_config_dword(pvt->branchmap_werrors,
NRECMEMB, >nrecmemb);
 
/* Clear the error bits, by writing them back */
-- 
2.13.1



[PATCH 2/2] c6x: remove unused KTHREAD_SIZE definition

2017-06-12 Thread Jérémy Lefaure
KTHREAD_SIZE has never been used since it has been defined for c6x arch.
Let's remove this useless definition.

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
 arch/c6x/kernel/asm-offsets.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/c6x/kernel/asm-offsets.c b/arch/c6x/kernel/asm-offsets.c
index 60f1e437745d..f8ededbfb63f 100644
--- a/arch/c6x/kernel/asm-offsets.c
+++ b/arch/c6x/kernel/asm-offsets.c
@@ -106,7 +106,6 @@ void foo(void)
/* These would be unneccessary if we ran asm files
 * through the preprocessor.
 */
-   DEFINE(KTHREAD_SIZE, THREAD_SIZE);
DEFINE(KTHREAD_SHIFT, THREAD_SHIFT);
DEFINE(KTHREAD_START_SP, THREAD_START_SP);
DEFINE(ENOSYS_, ENOSYS);
-- 
2.13.1



[PATCH 2/2] c6x: remove unused KTHREAD_SIZE definition

2017-06-12 Thread Jérémy Lefaure
KTHREAD_SIZE has never been used since it has been defined for c6x arch.
Let's remove this useless definition.

Signed-off-by: Jérémy Lefaure 
---
 arch/c6x/kernel/asm-offsets.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/c6x/kernel/asm-offsets.c b/arch/c6x/kernel/asm-offsets.c
index 60f1e437745d..f8ededbfb63f 100644
--- a/arch/c6x/kernel/asm-offsets.c
+++ b/arch/c6x/kernel/asm-offsets.c
@@ -106,7 +106,6 @@ void foo(void)
/* These would be unneccessary if we ran asm files
 * through the preprocessor.
 */
-   DEFINE(KTHREAD_SIZE, THREAD_SIZE);
DEFINE(KTHREAD_SHIFT, THREAD_SHIFT);
DEFINE(KTHREAD_START_SP, THREAD_START_SP);
DEFINE(ENOSYS_, ENOSYS);
-- 
2.13.1



[PATCH 1/2] arm: nommu: remove unused KTHREAD_SIZE definition

2017-06-12 Thread Jérémy Lefaure
I didn't find any use of this macro in the current kernel tree (with git
grep). KTHREAD_SIZE is no longer used for a very very long time. So
let's remove this definition.

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
 arch/arm/include/asm/page-nommu.h | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/arm/include/asm/page-nommu.h 
b/arch/arm/include/asm/page-nommu.h
index 503f488053de..8f2c47bec375 100644
--- a/arch/arm/include/asm/page-nommu.h
+++ b/arch/arm/include/asm/page-nommu.h
@@ -11,12 +11,6 @@
 #ifndef _ASMARM_PAGE_NOMMU_H
 #define _ASMARM_PAGE_NOMMU_H
 
-#if !defined(CONFIG_SMALL_TASKS) && PAGE_SHIFT < 13
-#define KTHREAD_SIZE (8192)
-#else
-#define KTHREAD_SIZE PAGE_SIZE
-#endif
- 
 #define clear_page(page)   memset((page), 0, PAGE_SIZE)
 #define copy_page(to,from) memcpy((to), (from), PAGE_SIZE)
 
-- 
2.13.1



[PATCH 1/2] arm: nommu: remove unused KTHREAD_SIZE definition

2017-06-12 Thread Jérémy Lefaure
I didn't find any use of this macro in the current kernel tree (with git
grep). KTHREAD_SIZE is no longer used for a very very long time. So
let's remove this definition.

Signed-off-by: Jérémy Lefaure 
---
 arch/arm/include/asm/page-nommu.h | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/arm/include/asm/page-nommu.h 
b/arch/arm/include/asm/page-nommu.h
index 503f488053de..8f2c47bec375 100644
--- a/arch/arm/include/asm/page-nommu.h
+++ b/arch/arm/include/asm/page-nommu.h
@@ -11,12 +11,6 @@
 #ifndef _ASMARM_PAGE_NOMMU_H
 #define _ASMARM_PAGE_NOMMU_H
 
-#if !defined(CONFIG_SMALL_TASKS) && PAGE_SHIFT < 13
-#define KTHREAD_SIZE (8192)
-#else
-#define KTHREAD_SIZE PAGE_SIZE
-#endif
- 
 #define clear_page(page)   memset((page), 0, PAGE_SIZE)
 #define copy_page(to,from) memcpy((to), (from), PAGE_SIZE)
 
-- 
2.13.1



Re: [PATCH] FS-Cache: print hexadecimal value for special cookies type

2017-05-27 Thread Jérémy Lefaure
On Thu, 27 Apr 2017 16:03:45 +0100
David Howells <dhowe...@redhat.com> wrote:

> Jérémy Lefaure <jeremy.lefa...@lse.epita.fr> wrote:
> 
> > When building object-list.o, gcc 6 raises a warning on the sprintf call
> > in fscache_objlist_show:
> > 
> >   CC  fs/fscache/object-list.o
> > fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
> > fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
> > terminating nul past the end of the destination [-Wformat-overflow=]
> > sprintf(_type, "%02u", cookie->def->type);
> >^~
> > fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
> > bytes into a destination of size 3
> > sprintf(_type, "%02u", cookie->def->type);
> > ^
> > 
> > Moreover, the documentation says that we should have an hex value for
> > special cookies (see Documentation/filesystems/caching/fscache.txt).
> > 
> > Printing hexadecimal value for special cookies fixes the overflow
> > warning and complies with the documentation.  
> 
> Fine by me.  We don't actually handle special type cookies at the moment, so
> you're not going to see anything other than DT or IX for now anyway.
> 
> I'll push this in the next merge window if that's okay with you.
> 

Hi David,
I didn't clearly say that I'm okay about pushing this patch in my last
answer. I am okay with that.

I don't see this patch in v4.12-rc2. Is there an issue with this patch
or are you waiting for my answer ?

Thanks,
Jérémy


Re: [PATCH] FS-Cache: print hexadecimal value for special cookies type

2017-05-27 Thread Jérémy Lefaure
On Thu, 27 Apr 2017 16:03:45 +0100
David Howells  wrote:

> Jérémy Lefaure  wrote:
> 
> > When building object-list.o, gcc 6 raises a warning on the sprintf call
> > in fscache_objlist_show:
> > 
> >   CC  fs/fscache/object-list.o
> > fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
> > fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
> > terminating nul past the end of the destination [-Wformat-overflow=]
> > sprintf(_type, "%02u", cookie->def->type);
> >^~
> > fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
> > bytes into a destination of size 3
> > sprintf(_type, "%02u", cookie->def->type);
> > ^
> > 
> > Moreover, the documentation says that we should have an hex value for
> > special cookies (see Documentation/filesystems/caching/fscache.txt).
> > 
> > Printing hexadecimal value for special cookies fixes the overflow
> > warning and complies with the documentation.  
> 
> Fine by me.  We don't actually handle special type cookies at the moment, so
> you're not going to see anything other than DT or IX for now anyway.
> 
> I'll push this in the next merge window if that's okay with you.
> 

Hi David,
I didn't clearly say that I'm okay about pushing this patch in my last
answer. I am okay with that.

I don't see this patch in v4.12-rc2. Is there an issue with this patch
or are you waiting for my answer ?

Thanks,
Jérémy


Re: [PATCH] FS-Cache: print hexadecimal value for special cookies type

2017-04-27 Thread Jérémy Lefaure
On Thu, 27 Apr 2017 16:03:45 +0100
David Howells <dhowe...@redhat.com> wrote:

> Jérémy Lefaure <jeremy.lefa...@lse.epita.fr> wrote:
> 
> > When building object-list.o, gcc 6 raises a warning on the sprintf call
> > in fscache_objlist_show:
> > 
> >   CC  fs/fscache/object-list.o
> > fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
> > fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
> > terminating nul past the end of the destination [-Wformat-overflow=]
> > sprintf(_type, "%02u", cookie->def->type);
> >^~
> > fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
> > bytes into a destination of size 3
> > sprintf(_type, "%02u", cookie->def->type);
> > ^
> > 
> > Moreover, the documentation says that we should have an hex value for
> > special cookies (see Documentation/filesystems/caching/fscache.txt).
> > 
> > Printing hexadecimal value for special cookies fixes the overflow
> > warning and complies with the documentation.  
> 
> Fine by me.  We don't actually handle special type cookies at the moment, so
> you're not going to see anything other than DT or IX for now anyway.
> 
> I'll push this in the next merge window if that's okay with you.
> 
Did you see the v2 of my patch (in which I keep the decimal value but
fix the buffer size) ? If special type cookies aren't handled, I guess
that this v1 is better, isn't it ?


Re: [PATCH] FS-Cache: print hexadecimal value for special cookies type

2017-04-27 Thread Jérémy Lefaure
On Thu, 27 Apr 2017 16:03:45 +0100
David Howells  wrote:

> Jérémy Lefaure  wrote:
> 
> > When building object-list.o, gcc 6 raises a warning on the sprintf call
> > in fscache_objlist_show:
> > 
> >   CC  fs/fscache/object-list.o
> > fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
> > fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
> > terminating nul past the end of the destination [-Wformat-overflow=]
> > sprintf(_type, "%02u", cookie->def->type);
> >^~
> > fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
> > bytes into a destination of size 3
> > sprintf(_type, "%02u", cookie->def->type);
> > ^
> > 
> > Moreover, the documentation says that we should have an hex value for
> > special cookies (see Documentation/filesystems/caching/fscache.txt).
> > 
> > Printing hexadecimal value for special cookies fixes the overflow
> > warning and complies with the documentation.  
> 
> Fine by me.  We don't actually handle special type cookies at the moment, so
> you're not going to see anything other than DT or IX for now anyway.
> 
> I'll push this in the next merge window if that's okay with you.
> 
Did you see the v2 of my patch (in which I keep the decimal value but
fix the buffer size) ? If special type cookies aren't handled, I guess
that this v1 is better, isn't it ?


[PATCH v2] FS-Cache: fix buffer size for decimal value of special cookie type

2017-04-26 Thread Jérémy Lefaure
When building object-list.o, gcc (version 7) raises a warning on the
sprintf call in fscache_objlist_show:

  CC  fs/fscache/object-list.o
fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
terminating nul past the end of the destination [-Wformat-overflow=]
sprintf(_type, "%02u", cookie->def->type);
   ^~
fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
bytes into a destination of size 3
sprintf(_type, "%02u", cookie->def->type);
^

Moreover, the documentation says that value for special cookies is a
hexadecimal value (see Documentation/filesystems/caching/fscache.txt).

Increasing the buffer size to use a decimal value fixes the problem
without any effect on userland tools. Also, this patch updates the
documentation.

Signed-off-by: Jérémy Lefaure <jeremy.lefa...@lse.epita.fr>
---
v2:
_ keep decimal value
_ fix _type buffer size
_ fix documentation

I didn't have the time to test this patch yet but everything should be fine.


 Documentation/filesystems/caching/fscache.txt |  2 +-
 fs/fscache/object-list.c  | 10 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Documentation/filesystems/caching/fscache.txt 
b/Documentation/filesystems/caching/fscache.txt
index 50f0a5757f48..9c3df61b3c16 100644
--- a/Documentation/filesystems/caching/fscache.txt
+++ b/Documentation/filesystems/caching/fscache.txt
@@ -374,7 +374,7 @@ and the second set of columns describe the object's cookie, 
if present:
COLUMN  DESCRIPTION
=== ===
NETFS_COOKIE_DEF Name of netfs cookie definition
-   TY  Cookie type (IX - index, DT - data, hex - special)
+   TY  Cookie type (IX - index, DT - data, decimal - special)
FL  Cookie flags
NETFS_DATA  Netfs private data stored in the cookie
OBJECT_KEY  Object key  } 1 column, with separating comma
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index 67f940892ef8..3452d7dbf1e1 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -169,7 +169,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
struct fscache_object *obj = v;
struct fscache_cookie *cookie;
unsigned long config = data->config;
-   char _type[3], *type;
+   char _type[4], *type;
u8 *buf = data->buf, *p;
 
if ((unsigned long) v == 1) {
@@ -194,7 +194,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
if ((unsigned long) v == 2) {
seq_puts(m, "   = === === === == ="
 " == == == ="
-" |  == == ");
+" |  === == ");
if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
  FSCACHE_OBJLIST_CONFIG_AUX))
seq_puts(m, " ");
@@ -256,13 +256,13 @@ static int fscache_objlist_show(struct seq_file *m, void 
*v)
 
switch (cookie->def->type) {
case 0:
-   type = "IX";
+   type = " IX";
break;
case 1:
-   type = "DT";
+   type = " DT";
break;
default:
-   sprintf(_type, "%02u", cookie->def->type);
+   sprintf(_type, "%03u", cookie->def->type);
type = _type;
break;
}
-- 
2.12.2



[PATCH v2] FS-Cache: fix buffer size for decimal value of special cookie type

2017-04-26 Thread Jérémy Lefaure
When building object-list.o, gcc (version 7) raises a warning on the
sprintf call in fscache_objlist_show:

  CC  fs/fscache/object-list.o
fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
terminating nul past the end of the destination [-Wformat-overflow=]
sprintf(_type, "%02u", cookie->def->type);
   ^~
fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
bytes into a destination of size 3
sprintf(_type, "%02u", cookie->def->type);
^

Moreover, the documentation says that value for special cookies is a
hexadecimal value (see Documentation/filesystems/caching/fscache.txt).

Increasing the buffer size to use a decimal value fixes the problem
without any effect on userland tools. Also, this patch updates the
documentation.

Signed-off-by: Jérémy Lefaure 
---
v2:
_ keep decimal value
_ fix _type buffer size
_ fix documentation

I didn't have the time to test this patch yet but everything should be fine.


 Documentation/filesystems/caching/fscache.txt |  2 +-
 fs/fscache/object-list.c  | 10 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Documentation/filesystems/caching/fscache.txt 
b/Documentation/filesystems/caching/fscache.txt
index 50f0a5757f48..9c3df61b3c16 100644
--- a/Documentation/filesystems/caching/fscache.txt
+++ b/Documentation/filesystems/caching/fscache.txt
@@ -374,7 +374,7 @@ and the second set of columns describe the object's cookie, 
if present:
COLUMN  DESCRIPTION
=== ===
NETFS_COOKIE_DEF Name of netfs cookie definition
-   TY  Cookie type (IX - index, DT - data, hex - special)
+   TY  Cookie type (IX - index, DT - data, decimal - special)
FL  Cookie flags
NETFS_DATA  Netfs private data stored in the cookie
OBJECT_KEY  Object key  } 1 column, with separating comma
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index 67f940892ef8..3452d7dbf1e1 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -169,7 +169,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
struct fscache_object *obj = v;
struct fscache_cookie *cookie;
unsigned long config = data->config;
-   char _type[3], *type;
+   char _type[4], *type;
u8 *buf = data->buf, *p;
 
if ((unsigned long) v == 1) {
@@ -194,7 +194,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
if ((unsigned long) v == 2) {
seq_puts(m, "   = === === === == ="
 " == == == ="
-" |  == == ");
+" |  === == ");
if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
  FSCACHE_OBJLIST_CONFIG_AUX))
seq_puts(m, " ");
@@ -256,13 +256,13 @@ static int fscache_objlist_show(struct seq_file *m, void 
*v)
 
switch (cookie->def->type) {
case 0:
-   type = "IX";
+   type = " IX";
break;
case 1:
-   type = "DT";
+   type = " DT";
break;
default:
-   sprintf(_type, "%02u", cookie->def->type);
+   sprintf(_type, "%03u", cookie->def->type);
type = _type;
break;
}
-- 
2.12.2



Re: [PATCH] FS-Cache: print hexadecimal value for special cookies type

2017-04-25 Thread Jérémy Lefaure
On Tue, 25 Apr 2017 00:47:41 +0300
Andy Shevchenko <andy.shevche...@gmail.com> wrote:

> On Sat, Apr 22, 2017 at 2:09 AM, Jérémy Lefaure
> <jeremy.lefa...@lse.epita.fr> wrote:
> > On Fri, 21 Apr 2017 22:41:54 +0300
> > Andy Shevchenko <andy.shevche...@gmail.com> wrote:  
> >> On Wed, Apr 19, 2017 at 11:38 PM, Jérémy Lefaure
> >> <jeremy.lefa...@lse.epita.fr> wrote:  
> >> > When building object-list.o, gcc 6 raises a warning on the sprintf call
> >> > in fscache_objlist_show:
> >> >
> >> >   CC  fs/fscache/object-list.o
> >> > fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
> >> > fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
> >> > terminating nul past the end of the destination [-Wformat-overflow=]
> >> > sprintf(_type, "%02u", cookie->def->type);
> >> >^~
> >> > fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
> >> > bytes into a destination of size 3
> >> > sprintf(_type, "%02u", cookie->def->type);
> >> > ^
> >> >
> >> > Moreover, the documentation says that we should have an hex value for
> >> > special cookies (see Documentation/filesystems/caching/fscache.txt).
> >> >
> >> > Printing hexadecimal value for special cookies fixes the overflow
> >> > warning and complies with the documentation.  
> >>
> >> If this is used by some user space tool the safest fix is to print in
> >> BCD and fix documentation.
> >>  
> > Are you talking about the Binary Coded Decimal format ?  
> 
> Yes.
> 
> > I don't get why
> > it would be better. If we change the printed format, it would break
> > user space tool anyway, right ?  
> 
> If userspace tool is bound to the format it might go crazy about hex
> digits in the cookie.
> 
> Is that cookie important somehow? (for example, user space might
> request something based on it?) It might be a case when you got let
> say '75' and then ask for 117 (0x75), however real value is 75.
> 
Ok I get it. But changing the format can break the userland tool
anyway, can't it ? For example if a userland tool expects the value 75,
it won't read it properpy in BCD.

> So, if it's okay in this, perhaps paragraph explaining side effects in
> commit message would be good to have/
> 
Maybe the best fix would be to increase the size of the _type buffer to
4 so the unsigned byte can fit in it. And change the documentation to
decimal value. What do you think about this solution ?

Thanks,


Re: [PATCH] FS-Cache: print hexadecimal value for special cookies type

2017-04-25 Thread Jérémy Lefaure
On Tue, 25 Apr 2017 00:47:41 +0300
Andy Shevchenko  wrote:

> On Sat, Apr 22, 2017 at 2:09 AM, Jérémy Lefaure
>  wrote:
> > On Fri, 21 Apr 2017 22:41:54 +0300
> > Andy Shevchenko  wrote:  
> >> On Wed, Apr 19, 2017 at 11:38 PM, Jérémy Lefaure
> >>  wrote:  
> >> > When building object-list.o, gcc 6 raises a warning on the sprintf call
> >> > in fscache_objlist_show:
> >> >
> >> >   CC  fs/fscache/object-list.o
> >> > fs/fscache/object-list.c: In function ‘fscache_objlist_show’:
> >> > fs/fscache/object-list.c:265:19: warning: ‘sprintf’ may write a
> >> > terminating nul past the end of the destination [-Wformat-overflow=]
> >> > sprintf(_type, "%02u", cookie->def->type);
> >> >^~
> >> > fs/fscache/object-list.c:265:4: note: ‘sprintf’ output between 3 and 4
> >> > bytes into a destination of size 3
> >> > sprintf(_type, "%02u", cookie->def->type);
> >> > ^
> >> >
> >> > Moreover, the documentation says that we should have an hex value for
> >> > special cookies (see Documentation/filesystems/caching/fscache.txt).
> >> >
> >> > Printing hexadecimal value for special cookies fixes the overflow
> >> > warning and complies with the documentation.  
> >>
> >> If this is used by some user space tool the safest fix is to print in
> >> BCD and fix documentation.
> >>  
> > Are you talking about the Binary Coded Decimal format ?  
> 
> Yes.
> 
> > I don't get why
> > it would be better. If we change the printed format, it would break
> > user space tool anyway, right ?  
> 
> If userspace tool is bound to the format it might go crazy about hex
> digits in the cookie.
> 
> Is that cookie important somehow? (for example, user space might
> request something based on it?) It might be a case when you got let
> say '75' and then ask for 117 (0x75), however real value is 75.
> 
Ok I get it. But changing the format can break the userland tool
anyway, can't it ? For example if a userland tool expects the value 75,
it won't read it properpy in BCD.

> So, if it's okay in this, perhaps paragraph explaining side effects in
> commit message would be good to have/
> 
Maybe the best fix would be to increase the size of the _type buffer to
4 so the unsigned byte can fit in it. And change the documentation to
decimal value. What do you think about this solution ?

Thanks,


Re: [PATCH] platform/x86: asus-wmi: fix cpufv sysfs file permission

2017-04-24 Thread Jérémy Lefaure
On Mon, 24 Apr 2017 12:14:14 +0300
Andy Shevchenko <andy.shevche...@gmail.com> wrote:

> On Sat, Apr 22, 2017 at 5:19 AM, Jérémy Lefaure
> <jeremy.lefa...@lse.epita.fr> wrote:
> > The cpufv sysfs file is defined as readable by anyone even if the
> > attribute does not have a show function. The result of every read is an
> > IO error. This file should be write only.  
> 
> Per se patch looks good to me, though would be better to add show()
> hook as well?
> 
It depends if we want to keep it write-only as it is documented in
Documentation/ABI/testing/sysfs-platform-asus-wmi.

If we want to have this file read/write, I can send a v2 of this patch.


Re: [PATCH] platform/x86: asus-wmi: fix cpufv sysfs file permission

2017-04-24 Thread Jérémy Lefaure
On Mon, 24 Apr 2017 12:14:14 +0300
Andy Shevchenko  wrote:

> On Sat, Apr 22, 2017 at 5:19 AM, Jérémy Lefaure
>  wrote:
> > The cpufv sysfs file is defined as readable by anyone even if the
> > attribute does not have a show function. The result of every read is an
> > IO error. This file should be write only.  
> 
> Per se patch looks good to me, though would be better to add show()
> hook as well?
> 
It depends if we want to keep it write-only as it is documented in
Documentation/ABI/testing/sysfs-platform-asus-wmi.

If we want to have this file read/write, I can send a v2 of this patch.


  1   2   >