Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ARRAY_SIZE() #1

Open
GustavoARSilva opened this issue Jan 5, 2022 · 0 comments
Open

Use ARRAY_SIZE() #1

GustavoARSilva opened this issue Jan 5, 2022 · 0 comments

Comments

@GustavoARSilva
Copy link
Owner

GustavoARSilva commented Jan 5, 2022

If you send a proper patch for this CC me: Gustavo A. R. Silva <[email protected]>

linux-next-20220104$ time make coccicheck -j 128 COCCI=scripts/coccinelle/misc/array_size.cocci MODE=patch 2>&1 | tee array_size.patch

Please check for false positives in the output before submitting a patch.
When using "patch" mode, carefully review the patch before submitting it.

/usr/local/bin/spatch -D patch --very-quiet --cocci-file scripts/coccinelle/misc/array_size.cocci --no-includes --include-headers --dir . -I ./arch/x86/include -I ./arch/x86/include/generated -I ./include -I ./arch/x86/include/uapi -I ./arch/x86/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi --include ./include/linux/compiler-version.h --include ./include/linux/kconfig.h --jobs 64 --chunksize 1
6041 files match
diff -u -p a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c
--- a/tools/perf/arch/x86/util/dwarf-regs.c
+++ b/tools/perf/arch/x86/util/dwarf-regs.c
@@ -89,7 +89,7 @@ static const struct pt_regs_offset x86_6
 #endif
 
 /* Minus 1 for the ending REG_OFFSET_END */
-#define ARCH_MAX_REGS ((sizeof(regoffset_table) / sizeof(regoffset_table[0])) - 1)
+#define ARCH_MAX_REGS (ARRAY_SIZE(regoffset_table) - 1)
 
 /* Return architecture dependent register string (for kprobe-tracer) */
 const char *get_arch_regstr(unsigned int n)
diff -u -p a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -481,8 +481,8 @@ static int xsk_load_xdp_prog(struct xsk_
 		BPF_EMIT_CALL(BPF_FUNC_redirect_map),
 		BPF_EXIT_INSN(),
 	};
-	size_t insns_cnt[] = {sizeof(prog) / sizeof(struct bpf_insn),
-			      sizeof(prog_redirect_flags) / sizeof(struct bpf_insn),
+	size_t insns_cnt[] = {ARRAY_SIZE(prog),
+			      ARRAY_SIZE(prog_redirect_flags),
 	};
 	struct bpf_insn *progs[] = {prog, prog_redirect_flags};
 	enum xsk_prog option = get_xsk_prog();
diff -u -p a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
--- a/arch/powerpc/xmon/ppc-opc.c
+++ b/arch/powerpc/xmon/ppc-opc.c
@@ -954,8 +954,7 @@ const struct powerpc_operand powerpc_ope
   { 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
 };
 
-const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
-					   / sizeof (powerpc_operands[0]));
+const unsigned int num_powerpc_operands = ARRAY_SIZE(powerpc_operands);
 
 /* The functions used to insert and extract complicated operands.  */
 
@@ -6969,7 +6968,7 @@ const struct powerpc_opcode powerpc_opco
 };
 
 const int powerpc_num_opcodes =
-  sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
+  ARRAY_SIZE(powerpc_opcodes);
 

 /* The VLE opcode table.
 
@@ -7208,7 +7207,7 @@ const struct powerpc_opcode vle_opcodes[
 };
 
 const int vle_num_opcodes =
-  sizeof (vle_opcodes) / sizeof (vle_opcodes[0]);
+  ARRAY_SIZE(vle_opcodes);
 

 /* The macro table.  This is only used by the assembler.  */
 
@@ -7277,4 +7276,4 @@ const struct powerpc_macro powerpc_macro
 };
 
 const int powerpc_num_macros =
-  sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
+  ARRAY_SIZE(powerpc_macros);

real	0m24.312s
user	19m2.785s
sys	0m23.889s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant