Skip to contentSkip to conversation

perf test: Use ARRAY_SIZE for array length

PATCH Applied Jiapeng Chong 2 participants 2 messages Sep 29, 2024 – Oct 1, 2024 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf test: Use ARRAY_SIZE for array length

Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability.

./tools/perf/tests/demangle-java-test.c:31:34-35: WARNING: Use ARRAY_SIZE.

---
Changes in v2:
-Modify the header file "kselftest.h" to "linux/kernel.h".

 tools/perf/tests/demangle-java-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/demangle-java-test.c +2 -1
index 44d1be303b67..93c94408bdc8 100644
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <linux/kernel.h>
 #include "tests.h"
 #include "session.h"
 #include "debug.h"
@@ -28,7 +29,7 @@ static int test__demangle_java(struct test_suite *test __maybe_unused, int subte
 		  "void java.lang.Object<init>()" },
 	};
 
-	for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
 		buf = java_demangle_sym(test_cases[i].mangled, 0);
 		if (strcmp(buf, test_cases[i].demangled)) {
 			pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
Signature · 1 line
2.32.0.3.g01195cf9f
maintainer Applied
#1 lore raw
Quoted 6 lines · Jiapeng Chong

Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability.

./tools/perf/tests/demangle-java-test.c:31:34-35: WARNING: Use ARRAY_SIZE.

Applied to perf-tools-next, thanks!

Best regards,
Namhyung