Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Jérémy Lefaure and committed by
Thomas Gleixner
0cfe5b5f 33d930e5

+7 -7
+3 -3
arch/x86/boot/video-vga.c
··· 241 241 vga_modes, 242 242 }; 243 243 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), 247 247 }; 248 248 249 249 struct biosregs ireg, oreg;
+2 -1
arch/x86/entry/vdso/vdso2c.c
··· 65 65 66 66 #include <linux/elf.h> 67 67 #include <linux/types.h> 68 + #include <linux/kernel.h> 68 69 69 70 const char *outfilename; 70 71 ··· 152 151 PLE(x, val, 64, PLE(x, val, 32, PLE(x, val, 16, LAST_PLE(x, val)))) 153 152 154 153 155 - #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0])) 154 + #define NSYMS ARRAY_SIZE(required_syms) 156 155 157 156 #define BITSFUNC3(name, bits, suffix) name##bits##suffix 158 157 #define BITSFUNC2(name, bits, suffix) BITSFUNC3(name, bits, suffix)
+2 -3
arch/x86/platform/intel-mid/device_libs/platform_gpio_keys.c
··· 62 62 static int __init pb_keys_init(void) 63 63 { 64 64 struct gpio_keys_button *gb = gpio_button; 65 - int i, num, good = 0; 65 + int i, good = 0; 66 66 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++) { 69 68 gb[i].gpio = get_gpio_by_name(gb[i].desc); 70 69 pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, 71 70 gb[i].gpio);