Skip to content

Commit 0cfe5b5

Browse files
Jérémy LefaureKAGA-KOKO
authored andcommitted
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.lefaure@lse.epita.fr> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: linux-video@atrey.karlin.mff.cuni.cz Cc: Martin Mares <mj@ucw.cz> Cc: Andy Lutomirski <luto@amacapital.net> Link: https://lkml.kernel.org/r/20171001193101.8898-13-jeremy.lefaure@lse.epita.fr
1 parent 33d930e commit 0cfe5b5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

arch/x86/boot/video-vga.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ static int vga_probe(void)
241241
vga_modes,
242242
};
243243
static int mode_count[] = {
244-
sizeof(cga_modes)/sizeof(struct mode_info),
245-
sizeof(ega_modes)/sizeof(struct mode_info),
246-
sizeof(vga_modes)/sizeof(struct mode_info),
244+
ARRAY_SIZE(cga_modes),
245+
ARRAY_SIZE(ega_modes),
246+
ARRAY_SIZE(vga_modes),
247247
};
248248

249249
struct biosregs ireg, oreg;

arch/x86/entry/vdso/vdso2c.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
#include <linux/elf.h>
6767
#include <linux/types.h>
68+
#include <linux/kernel.h>
6869

6970
const char *outfilename;
7071

@@ -151,7 +152,7 @@ extern void bad_put_le(void);
151152
PLE(x, val, 64, PLE(x, val, 32, PLE(x, val, 16, LAST_PLE(x, val))))
152153

153154

154-
#define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
155+
#define NSYMS ARRAY_SIZE(required_syms)
155156

156157
#define BITSFUNC3(name, bits, suffix) name##bits##suffix
157158
#define BITSFUNC2(name, bits, suffix) BITSFUNC3(name, bits, suffix)

arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ static struct platform_device pb_device = {
6262
static int __init pb_keys_init(void)
6363
{
6464
struct gpio_keys_button *gb = gpio_button;
65-
int i, num, good = 0;
65+
int i, good = 0;
6666

67-
num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
68-
for (i = 0; i < num; i++) {
67+
for (i = 0; i < ARRAY_SIZE(gpio_button); i++) {
6968
gb[i].gpio = get_gpio_by_name(gb[i].desc);
7069
pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
7170
gb[i].gpio);

0 commit comments

Comments
 (0)