Skip to contentSkip to conversation

selftests/x86/syscall: fix coccinelle WARNING recommending the use of ARRAY_SIZE()

PATCH Applied Mirsad Todorovac 4 participants 7 messages Nov 1, 2024 – Mar 3, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selftests/x86/syscall: fix coccinelle WARNING recommending the use of ARRAY_SIZE()

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/x86/syscall_numbering.c:316:35-36: WARNING: Use ARRAY_SIZE

Fixes 15c82d98a0f78 ("selftests/x86/syscall: Update and extend syscall_numbering_64")
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Shuah Khan <[email protected]>

---
v1: initial version.

 tools/testing/selftests/x86/syscall_numbering.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/syscall_numbering.c +2 -1
index 991591718bb0..41c42b7b54a6 100644
@@ -25,6 +25,7 @@
 #include <sys/mman.h>
 
 #include <linux/ptrace.h>
+#include "../kselftest.h"
 
 /* Common system call numbers */
 #define SYS_READ	  0
@@ -313,7 +314,7 @@ static void test_syscall_numbering(void)
 	 * The MSB is supposed to be ignored, so we loop over a few
 	 * to test that out.
 	 */
-	for (size_t i = 0; i < sizeof(msbs)/sizeof(msbs[0]); i++) {
+	for (size_t i = 0; i < ARRAY_SIZE(msbs); i++) {
 		int msb = msbs[i];
 		run("Checking system calls with msb = %d (0x%x)\n",
 		    msb, msb);
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 selftests/mm: fix coccinelle WARNING recommending the use of ARRAY_SIZE()

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/mm/uffd-unit-tests.c:1484:32-33: WARNING: Use ARRAY_SIZE ./tools/testing/selftests/mm/uffd-unit-tests.c:1485:30-31: WARNING: Use ARRAY_SIZE

Fixes 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
Cc Andrew Morton <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Peter Xu <[email protected]>

---
v1: initial version.

 tools/testing/selftests/mm/uffd-unit-tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/uffd-unit-tests.c +2 -2
index a2e71b1636e7..4f6a7440a9aa 100644
@@ -1481,8 +1481,8 @@ static void usage(const char *prog)
 
 int main(int argc, char *argv[])
 {
-	int n_tests = sizeof(uffd_tests) / sizeof(uffd_test_case_t);
-	int n_mems = sizeof(mem_types) / sizeof(mem_type_t);
+	int n_tests = ARRAY_SIZE(uffd_tests);
+	int n_mems = ARRAY_SIZE(mem_types);
 	const char *test_filter = NULL;
 	bool list_only = false;
 	uffd_test_case_t *test;
Signature · 1 line
2.43.0
reviewer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] selftests/mm: fix coccinelle WARNING recommending the use of ARRAY_SIZE()

Quoted 6 lines · Mirsad Todorovac

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/mm/uffd-unit-tests.c:1484:32-33: WARNING: Use ARRAY_SIZE ./tools/testing/selftests/mm/uffd-unit-tests.c:1485:30-31: WARNING: Use ARRAY_SIZE

Quoted 8 lines
Fixes 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
Cc Andrew Morton <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Peter Xu <[email protected]>
Signature · 1 line
Peter Xu
#3 lore raw

Re: [PATCH v1 2/2] selftests/mm: fix coccinelle WARNING recommending the use of ARRAY_SIZE()

Quoted 16 lines · Peter Xu
Quoted 6 lines · Mirsad Todorovac

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/mm/uffd-unit-tests.c:1484:32-33: WARNING: Use ARRAY_SIZE ./tools/testing/selftests/mm/uffd-unit-tests.c:1485:30-31: WARNING: Use ARRAY_SIZE

Quoted 8 lines
Fixes 16a45b57cbf2 ("selftests/mm: add framework for uffd-unit-test")
Cc Andrew Morton <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Peter Xu <[email protected]>
Quoted 1 line

Thanks for the quick review.

Best regards,
Mirsad

Reviewed-by on v1 1/2
#4 lore raw
In reply to Mirsad Todorovac
Quoted 5 lines · Mirsad Todorovac

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/x86/syscall_numbering.c:316:35-36: WARNING: Use ARRAY_SIZE

Quoted 11 lines
Fixes 15c82d98a0f78 ("selftests/x86/syscall: Update and extend syscall_numbering_64")
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Shuah Khan <[email protected]>
Quoted 27 lines

---
v1: initial version.

 tools/testing/selftests/x86/syscall_numbering.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/syscall_numbering.c +2 -1
index 991591718bb0..41c42b7b54a6 100644
@@ -25,6 +25,7 @@
 #include <sys/mman.h>
 
 #include <linux/ptrace.h>
+#include "../kselftest.h"
 
 /* Common system call numbers */
 #define SYS_READ	  0
@@ -313,7 +314,7 @@ static void test_syscall_numbering(void)
 	 * The MSB is supposed to be ignored, so we loop over a few
 	 * to test that out.
 	 */
-	for (size_t i = 0; i < sizeof(msbs)/sizeof(msbs[0]); i++) {
+	for (size_t i = 0; i < ARRAY_SIZE(msbs); i++) {
 		int msb = msbs[i];
 		run("Checking system calls with msb = %d (0x%x)\n",
 		    msb, msb);
Signature · 2 lines
BR,
Muhammad Usama Anjum
#5 lore raw
Quoted 18 lines · Muhammad Usama Anjum
Quoted 5 lines · Mirsad Todorovac

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/x86/syscall_numbering.c:316:35-36: WARNING: Use ARRAY_SIZE

Quoted 11 lines
Fixes 15c82d98a0f78 ("selftests/x86/syscall: Update and extend syscall_numbering_64")
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Shuah Khan <[email protected]>
Quoted 1 line

Dear Sir,

Thank you for your positive review of the patch.

There are much more suggestions by the coccinelle check, but that's a substantial work to do.

It would help to set some priorities in this by some more experienced developer.

Thank you.

Best regards,
Mirsad Todorovac

Quoted 28 lines
Quoted 27 lines

---
v1: initial version.

 tools/testing/selftests/x86/syscall_numbering.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/syscall_numbering.c +2 -1
index 991591718bb0..41c42b7b54a6 100644
@@ -25,6 +25,7 @@
 #include <sys/mman.h>
 
 #include <linux/ptrace.h>
+#include "../kselftest.h"
 
 /* Common system call numbers */
 #define SYS_READ	  0
@@ -313,7 +314,7 @@ static void test_syscall_numbering(void)
 	 * The MSB is supposed to be ignored, so we loop over a few
 	 * to test that out.
 	 */
-	for (size_t i = 0; i < sizeof(msbs)/sizeof(msbs[0]); i++) {
+	for (size_t i = 0; i < ARRAY_SIZE(msbs); i++) {
 		int msb = msbs[i];
 		run("Checking system calls with msb = %d (0x%x)\n",
 		    msb, msb);
#6 lore raw

[tip: x86/cleanups] selftests/x86/syscall: Fix coccinelle WARNING recommending the use of ARRAY_SIZE()

In reply to Mirsad Todorovac
The following commit has been merged into the x86/cleanups branch of tip:

The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     40fc7561013914ec08c200bb7a0805643a23e070
Gitweb:        https://git.kernel.org/tip/40fc7561013914ec08c200bb7a0805643a23e070
Author:        Mirsad Todorovac <[email protected]>
AuthorDate:    Fri, 01 Nov 2024 12:15:23 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Mon, 03 Mar 2025 12:38:49 +01:00

selftests/x86/syscall: Fix coccinelle WARNING recommending the use of ARRAY_SIZE()

Coccinelle gives WARNING recommending the use of ARRAY_SIZE() macro definition to improve the code readability:

./tools/testing/selftests/x86/syscall_numbering.c:316:35-36: WARNING: Use ARRAY_SIZE

Fixes 15c82d98a0f78 ("selftests/x86/syscall: Update and extend syscall_numbering_64")
---
 tools/testing/selftests/x86/syscall_numbering.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/syscall_numbering.c +2 -1
index 9915917..41c42b7 100644
@@ -25,6 +25,7 @@
 #include <sys/mman.h>
 
 #include <linux/ptrace.h>
+#include "../kselftest.h"
 
 /* Common system call numbers */
 #define SYS_READ	  0
@@ -313,7 +314,7 @@ static void test_syscall_numbering(void)
 	 * The MSB is supposed to be ignored, so we loop over a few
 	 * to test that out.
 	 */
-	for (size_t i = 0; i < sizeof(msbs)/sizeof(msbs[0]); i++) {
+	for (size_t i = 0; i < ARRAY_SIZE(msbs); i++) {
 		int msb = msbs[i];
 		run("Checking system calls with msb = %d (0x%x)\n",
 		    msb, msb);