Skip to contentSkip to conversation

Fix compilation warnings in selftests

PATCH New Eva Kurchatova 1 participant 16 messages Apr 29

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

cover Fix compilation warnings in selftests

This patchset fixes several compilation warnings in selftests, related to unused or uninitialized variables and compiler analysis.

These warnings may be reproduced via GCC with -Wall -Wextra

Eva Kurchatova (4):
selftests/tcp_ao: fix -Wdiscarded-qualifiers under C23 selftests/iommu: suppress -Warray-bounds in _test_cmd_get_hw_info selftests/fchmodat2: suppress -Wunused-parameter selftests/openat2: suppress -Wsign-compare and -Wunused-parameter

Konstantin Khorenko (11):
selftests/uevent: fix -Wmaybe-uninitialized warning in
uevent_filtering
selftests/prctl: remove unused variable 'j' in set-process-name selftests/netfilter: remove unused variables in conntrack_dump_flush selftests/netfilter: remove unused variable 'plen' in
conntrack_reverse_clash
selftests/mqueue: fix warnings in mq_perf_tests selftests/mqueue: fix -Wunused-variable warning for 'usage' in
mq_open_tests
selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test selftests/memfd: remove unused variable 'sig' in fuse_test selftests/membarrier: remove unused variable 'i' selftests/epoll: remove unused variable 'pfd' in epoll59 test selftests/clone3: remove unused variables in
clone3_cap_checkpoint_restore

 .../selftests/clone3/clone3_cap_checkpoint_restore.c   |  4 ----
 tools/testing/selftests/fchmodat2/fchmodat2_test.c     |  2 +-
 .../selftests/filesystems/epoll/epoll_wakeup_test.c    |  1 -
 tools/testing/selftests/iommu/iommufd_utils.h          | 10 ++++++----
 .../membarrier/membarrier_test_multi_thread.c          |  1 -
 tools/testing/selftests/memfd/fuse_test.c              |  2 +-
 tools/testing/selftests/memfd/memfd_test.c             |  4 ++--
 tools/testing/selftests/mqueue/mq_open_tests.c         |  2 +-
 tools/testing/selftests/mqueue/mq_perf_tests.c         |  4 +---
 .../selftests/net/netfilter/conntrack_dump_flush.c     |  7 ++-----
 .../selftests/net/netfilter/conntrack_reverse_clash.c  |  1 -
 tools/testing/selftests/net/tcp_ao/lib/proc.c          |  2 +-
 tools/testing/selftests/openat2/openat2_test.c         | 10 +++++-----
 tools/testing/selftests/prctl/set-process-name.c       |  3 +--
 tools/testing/selftests/uevent/uevent_filtering.c      |  2 +-
 15 files changed, 22 insertions(+), 33 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/15 selftests/uevent: fix -Wmaybe-uninitialized warning in uevent_filtering

From: Konstantin Khorenko <[email protected]>

uevent_filtering.c: In function 'trigger_uevent':
uevent_filtering.c:217:16: warning: 'ret' may be used uninitialized [-Wmaybe-uninitialized]

    217 |         return ret;
        |                ^~~
  uevent_filtering.c:197:17: note: 'ret' was declared here
    197 |         int fd, ret;
        |                 ^~~

Initialize 'ret' to 0 in trigger_uevent(). If 'times' is 0, the for loop body is never entered and 'ret' would be returned uninitialized.

---
 tools/testing/selftests/uevent/uevent_filtering.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/uevent/uevent_filtering.c +1 -1
index 974b076f9235..e3cded66233d 100644
@@ -194,7 +194,7 @@ static int uevent_listener(unsigned long post_flags, bool expect_uevent,
 
 int trigger_uevent(unsigned int times)
 {
-	int fd, ret;
+	int fd, ret = 0;
 	unsigned int i;
 
 	fd = open(__DEV_FULL, O_RDWR | O_CLOEXEC);
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/15 selftests/prctl: remove unused variable 'j' in set-process-name

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

set-process-name.c: In function 'check_name':
set-process-name.c:61:13: warning: variable 'j' set but not used [-Wunused-but-set-variable]

     61 |         int j;
        |             ^

Remove unused 'j' to fix -Wunused-but-set-variable warning. The snprintf() return value is not needed here.

---
 tools/testing/selftests/prctl/set-process-name.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/prctl/set-process-name.c +1 -2
index 3f7b146d36df..3c5175f873ec 100644
@@ -58,9 +58,8 @@ int check_name(void)
 	char path[MAX_PATH_LEN] = {};
 	char name[TASK_COMM_LEN] = {};
 	char output[TASK_COMM_LEN] = {};
-	int j;
 
-	j = snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid);
+	snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid);
 	fptr = fopen(path, "r");
 	if (!fptr)
 		return -EIO;
Signature · 1 line
2.54.0
#3 lore raw

PATCH 3/15 selftests/netfilter: remove unused variables in conntrack_dump_flush

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

conntrack_dump_flush.c: In function 'conntrack_data_insert':
conntrack_dump_flush.c:105:26: warning: unused variable 'rplnlh' [-Wunused-variable]

    105 |         struct nlmsghdr *rplnlh;
        |                          ^~~~~~
  conntrack_dump_flush.c: In function 'conntracK_count_zone':
  conntrack_dump_flush.c:224:24: warning: unused variable 'nest'
  [-Wunused-variable]
    224 |         struct nlattr *nest;
        |                        ^~~~
  conntrack_dump_flush.c:222:32: warning: unused variable 'rplnlh'
  [-Wunused-variable]
    222 |         struct nlmsghdr *nlh, *rplnlh;
        |                                ^~~~~~
  conntrack_dump_flush.c: In function 'conntrack_flush_zone':
  conntrack_dump_flush.c:271:24: warning: unused variable 'nest'
  [-Wunused-variable]
    271 |         struct nlattr *nest;
        |                        ^~~~
  conntrack_dump_flush.c:269:32: warning: unused variable 'rplnlh'
  [-Wunused-variable]
    269 |         struct nlmsghdr *nlh, *rplnlh;
        |                                ^~~~~~

Remove unused 'rplnlh' and 'nest' variables from conntrack_data_insert(), conntracK_count_zone() and conntrack_flush_zone() to fix -Wunused-variable warnings.

---
 .../testing/selftests/net/netfilter/conntrack_dump_flush.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
tools/testing/selftests/net/netfilter/conntrack_dump_flush.c +2 -5
index 5cecb8a1bc94..c8e4794ec5cb 100644
@@ -102,7 +102,6 @@ static int conntrack_data_insert(struct mnl_socket *sock, struct nlmsghdr *nlh,
 				 uint16_t zone)
 {
 	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlmsghdr *rplnlh;
 	unsigned int portid;
 	int ret;
 
@@ -219,9 +218,8 @@ static int count_entries(const struct nlmsghdr *nlh, void *data)
 static int conntracK_count_zone(struct mnl_socket *sock, uint16_t zone)
 {
 	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlmsghdr *nlh, *rplnlh;
+	struct nlmsghdr *nlh;
 	struct nfgenmsg *nfh;
-	struct nlattr *nest;
 	unsigned int portid;
 	int ret;
 
@@ -266,9 +264,8 @@ static int conntracK_count_zone(struct mnl_socket *sock, uint16_t zone)
 static int conntrack_flush_zone(struct mnl_socket *sock, uint16_t zone)
 {
 	char buf[MNL_SOCKET_BUFFER_SIZE];
-	struct nlmsghdr *nlh, *rplnlh;
+	struct nlmsghdr *nlh;
 	struct nfgenmsg *nfh;
-	struct nlattr *nest;
 	unsigned int portid;
 	int ret;
 
Signature · 1 line
2.54.0
#4 lore raw

PATCH 4/15 selftests/netfilter: remove unused variable 'plen' in conntrack_reverse_clash

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

conntrack_reverse_clash.c: In function 'main':
conntrack_reverse_clash.c:66:19: warning: unused variable 'plen' [-Wunused-variable]

     66 |         socklen_t plen;
        |                   ^~~~

Remove unused 'plen' to fix -Wunused-variable warning.

---
 tools/testing/selftests/net/netfilter/conntrack_reverse_clash.c | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/net/netfilter/conntrack_reverse_clash.c +0 -1
index 462d628cc3bd..441ac9a93eac 100644
@@ -68,7 +68,6 @@ int main(int argc, char *argv[])
 	};
 	int s1, s2, status;
 	time_t end, now;
-	socklen_t plen;
 	char buf[LEN];
 	bool child;
 
Signature · 1 line
2.54.0
#5 lore raw

PATCH 5/15 selftests/mqueue: fix warnings in mq_perf_tests

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

mq_perf_tests.c: In function 'perf_test_thread':
mq_perf_tests.c:433:20: warning: variable 't' set but not used [-Wunused-but-set-variable]

    433 |         pthread_t *t;
        |                    ^

mq_perf_tests.c: At top level:
mq_perf_tests.c:45:14: warning: 'usage' defined but not used [-Wunused-variable]
45 | static char *usage =
| ^~~~~

- Mark 'usage' with __attribute__((unused)) to fix -Wunused-variable.
- Remove unused variable 't' to fix -Wunused-but-set-variable.

---
 tools/testing/selftests/mqueue/mq_perf_tests.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
tools/testing/selftests/mqueue/mq_perf_tests.c +1 -3
index 303c46eebd94..a13378464551 100644
@@ -42,7 +42,7 @@
 
 #include "kselftest.h"
 
-static char *usage =
+static char __attribute__((unused)) *usage =
 "Usage:\n"
 "  %s [-c #[,#..] -f] path\n"
 "\n"
@@ -430,12 +430,10 @@ void *perf_test_thread(void *arg)
 	unsigned int prio_in;
 	int i;
 	clockid_t clock;
-	pthread_t *t;
 	struct timespec res, start, middle, end, send_total, recv_total;
 	unsigned long long nsec;
 	struct test *cur_test;
 
-	t = &cpu_threads[0];
 	printf("\n\tStarted mqueue performance test thread on CPU %d\n",
 	       cpus_to_pin[0]);
 	mq_prio_max = sysconf(_SC_MQ_PRIO_MAX);
Signature · 1 line
2.54.0
#6 lore raw

PATCH 6/15 selftests/mqueue: fix -Wunused-variable warning for 'usage' in mq_open_tests

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

mq_open_tests.c:38:14: warning: 'usage' defined but not used [-Wunused-variable]
38 | static char *usage =
| ^~~~~

Mark 'usage' with __attribute__((unused)) to fix the warning. The variable is kept for documentation purposes.

---
 tools/testing/selftests/mqueue/mq_open_tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mqueue/mq_open_tests.c +1 -1
index b16029c40c0f..f7955507917b 100644
@@ -35,7 +35,7 @@
 
 #include "kselftest.h"
 
-static char *usage =
+static char __attribute__((unused)) *usage =
 "Usage:\n"
 "  %s path\n"
 "\n"
Signature · 1 line
2.54.0
#7 lore raw

PATCH 7/15 selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

memfd_test.c: In function 'mfd_fail_grow_write.part.0':
memfd_test.c:685:13: warning: '<unknown>' may be used uninitialized [-Wmaybe-uninitialized]

    685 |         l = pwrite(fd, buf, mfd_def_size * 8, 0);
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pwrite() is declared with attribute 'access (read_only, 2, 3)', so GCC knows it reads from the buffer. malloc() returns uninitialized memory, hence the warning. Use calloc() to zero-initialize the buffer. The actual contents don't matter here since the test verifies that pwrite() fails on a sealed memfd.

---
 tools/testing/selftests/memfd/memfd_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/memfd/memfd_test.c +2 -2
index 2ca07ea7202a..cdab3a837624 100644
@@ -688,9 +688,9 @@ static void mfd_assert_grow_write(int fd)
 	if (hugetlbfs_test)
 		return;
 
-	buf = malloc(mfd_def_size * 8);
+	buf = calloc(1, mfd_def_size * 8);
 	if (!buf) {
-		printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
+		printf("calloc(1, %zu) failed: %m\n", mfd_def_size * 8);
 		abort();
 	}
 
Signature · 1 line
2.54.0
#8 lore raw

PATCH 8/15 selftests/memfd: remove unused variable 'sig' in fuse_test

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

fuse_test.c: In function 'sealing_thread_fn':
fuse_test.c:165:13: warning: unused variable 'sig' [-Wunused-variable]

    165 |         int sig, r;
        |             ^~~

Remove unused 'sig' to fix -Wunused-variable warning.

---
 tools/testing/selftests/memfd/fuse_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/memfd/fuse_test.c +1 -1
index dbc171a3806d..510056c1b0d0 100644
@@ -162,7 +162,7 @@ static void *global_p = NULL;
 
 static int sealing_thread_fn(void *arg)
 {
-	int sig, r;
+	int r;
 
 	/*
 	 * This thread first waits 200ms so any pending operation in the parent
Signature · 1 line
2.54.0
#9 lore raw

PATCH 9/15 selftests/membarrier: remove unused variable 'i'

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

membarrier_test_multi_thread.c: In function 'test_mt_membarrier':
membarrier_test_multi_thread.c:36:13: warning: unused variable 'i' [-Wunused-variable]

     36 |         int i;
        |             ^

Remove unused 'i' to fix -Wunused-variable warning.

---
 .../testing/selftests/membarrier/membarrier_test_multi_thread.c  | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/membarrier/membarrier_test_multi_thread.c +0 -1
index 4e14dba81234..3dbaf1541058 100644
@@ -33,7 +33,6 @@ void *test_membarrier_thread(void *arg)
 
 static int test_mt_membarrier(void)
 {
-	int i;
 	pthread_t test_thread;
 
 	pthread_create(&test_thread, NULL,
Signature · 1 line
2.54.0
#10 lore raw

PATCH 10/15 selftests/epoll: remove unused variable 'pfd' in epoll59 test

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

epoll_wakeup_test.c: In function 'epoll59':
epoll_wakeup_test.c:3121:23: warning: unused variable 'pfd' [-Wunused-variable]
3121 | struct pollfd pfd;
| ^~~

Remove unused 'struct pollfd pfd' to fix -Wunused-variable warning.

---
 tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c +0 -1
index 8bc57a2ef966..bb20da2ce60d 100644
@@ -3118,7 +3118,6 @@ static void *epoll59_thread(void *ctx_)
 TEST(epoll59)
 {
 	pthread_t emitter;
-	struct pollfd pfd;
 	struct epoll_event e;
 	struct epoll_mtcontext ctx = { 0 };
 	int i, ret;
Signature · 1 line
2.54.0
#11 lore raw

PATCH 11/15 selftests/clone3: remove unused variables in clone3_cap_checkpoint_restore

In reply to Eva Kurchatova

From: Konstantin Khorenko <[email protected]>

clone3_cap_checkpoint_restore.c: In function 'call_clone3_set_tid':
clone3_cap_checkpoint_restore.c:57:22: warning: unused variable 'tmp' [-Wunused-variable]

     57 |                 char tmp = 0;
        |                      ^~~
  clone3_cap_checkpoint_restore.c:56:21: warning: unused variable 'ret'
  [-Wunused-variable]
     56 |                 int ret;
        |                     ^~~
  clone3_cap_checkpoint_restore.c: In function 'clone3_cap_checkpoint_restore':
  clone3_cap_checkpoint_restore.c:138:13: warning: unused variable 'ret'
  [-Wunused-variable]
    138 |         int ret = 0;
        |             ^~~

Remove unused variables 'ret' and 'tmp' to fix -Wunused-variable warnings.

---
 .../testing/selftests/clone3/clone3_cap_checkpoint_restore.c  | 4 ----
 1 file changed, 4 deletions(-)
tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c +0 -4
index e82281efa273..fd4baa0695fa 100644
@@ -53,9 +53,6 @@ static int call_clone3_set_tid(struct __test_metadata *_metadata,
 	}
 
 	if (pid == 0) {
-		int ret;
-		char tmp = 0;
-
 		TH_LOG("I am the child, my PID is %d (expected %d)", getpid(), set_tid[0]);
 
 		if (set_tid[0] != getpid())
@@ -135,7 +132,6 @@ TEST(clone3_cap_checkpoint_restore)
 {
 	pid_t pid;
 	int status;
-	int ret = 0;
 	pid_t set_tid[1];
 
 	test_clone3_supported();
Signature · 1 line
2.54.0
#12 lore raw

PATCH 12/15 selftests/tcp_ao: fix -Wdiscarded-qualifiers under C23

In reply to Eva Kurchatova

glibc ≥ 2.42 (GCC 15) defaults to -std=gnu23, which promotes -Wdiscarded-qualifiers to an error.

In C23, strstr() and strchr() return "const char *".

Change variable types to const char * where the pointers are never modified (column)

---
 tools/testing/selftests/net/tcp_ao/lib/proc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/tcp_ao/lib/proc.c +1 -1
index 8b984fa04286..50062b527a39 100644
@@ -56,7 +56,7 @@ static struct netstat *lookup_get(struct netstat *ns,
 
 static struct netstat *lookup_get_column(struct netstat *ns, const char *line)
 {
-	char *column;
+	const char *column;
 
 	column = strchr(line, ':');
 	if (!column)
Signature · 1 line
2.54.0
#13 lore raw

PATCH 13/15 selftests/iommu: suppress -Warray-bounds in _test_cmd_get_hw_info

In reply to Eva Kurchatova

In function '_test_cmd_get_hw_info',
inlined from 'iommufd_ioas_get_hw_info' at iommufd.c:614:3, inlined from 'wrapper_iommufd_ioas_get_hw_info' at iommufd.c:589:1:
iommufd_utils.h:683:37: warning: array subscript 'struct iommu_test_hw_info[0]' is partly outside array bounds of 'struct iommu_test_hw_info_buffer_smaller[1]' [-Warray-bounds=]

    683 |                         assert(!info->flags);
        |                                 ~~~~^~~~~~~

The test intentionally passes a smaller buffer to exercise the kernel's handling of undersized user buffers. Runtime data_len checks make the access safe, but GCC cannot prove this statically. Suppress the warning locally via copying into properly-sized temporary structure.

---
 tools/testing/selftests/iommu/iommufd_utils.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/testing/selftests/iommu/iommufd_utils.h +6 -4
index 5502751d500c..ca978b8b796d 100644
@@ -5,6 +5,7 @@
 
 #include <unistd.h>
 #include <stddef.h>
+#include <string.h>
 #include <sys/fcntl.h>
 #include <sys/ioctl.h>
 #include <stdint.h>
@@ -826,7 +827,6 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
 				 void *data, size_t data_len,
 				 uint32_t *capabilities, uint8_t *max_pasid)
 {
-	struct iommu_test_hw_info *info = (struct iommu_test_hw_info *)data;
 	struct iommu_hw_info cmd = {
 		.size = sizeof(cmd),
 		.dev_id = device_id,
@@ -866,11 +866,13 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
 		}
 	}
 
-	if (info) {
+	if (data) {
+		struct iommu_test_hw_info info = {0};
+		memcpy(&info, data, data_len);
 		if (data_len >= offsetofend(struct iommu_test_hw_info, test_reg))
-			assert(info->test_reg == IOMMU_HW_INFO_SELFTEST_REGVAL);
+			assert(info.test_reg == IOMMU_HW_INFO_SELFTEST_REGVAL);
 		if (data_len >= offsetofend(struct iommu_test_hw_info, flags))
-			assert(!info->flags);
+			assert(!info.flags);
 	}
 
 	if (max_pasid)
Signature · 1 line
2.54.0
#14 lore raw

PATCH 14/15 selftests/fchmodat2: suppress -Wunused-parameter

In reply to Eva Kurchatova

fchmodat2_test.c: In function ‘main’:
fchmodat2_test.c:191:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
191 | int main(int argc, char **argv)

      |          ~~~~^~~~
fchmodat2_test.c:191:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
  191 | int main(int argc, char **argv)
      |                    ~~~~~~~^~~~

Remove unused argc & argv parameters to fix -Wunused-parameter warnings

---
 tools/testing/selftests/fchmodat2/fchmodat2_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/fchmodat2/fchmodat2_test.c +1 -1
index 8e1b6384b319..409cca0dce7c 100644
@@ -188,7 +188,7 @@ void test_symlink(void)
 
 #define NUM_TESTS 2
 
-int main(int argc, char **argv)
+int main()
 {
 	ksft_print_header();
 	ksft_set_plan(NUM_TESTS);
Signature · 1 line
2.54.0
#15 lore raw

PATCH 15/15 selftests/openat2: suppress -Wsign-compare and -Wunused-parameter

In reply to Eva Kurchatova

openat2_test.c: In function ‘test_openat2_struct’:
openat2_test.c:89:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
89 | for (int i = 0; i < ARRAY_LEN(tests); i++) {
| ^
openat2_test.c:93:35: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
93 | for (int j = 0; j < ARRAY_LEN(misalignments); j++) {
| ^
openat2_test.c: In function ‘test_openat2_flags’:
openat2_test.c:246:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
246 | for (int i = 0; i < ARRAY_LEN(tests); i++) {
| ^
openat2_test.c:296:44: warning: comparison of integer expressions of different
signedness: ‘int’ and ‘__u64’ {aka ‘long long unsigned int’} [-Wsign-compare]
296 | failed |= (fdflags != test->how.flags);
| ^~
openat2_test.c: In function ‘main’:
openat2_test.c:326:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
326 | int main(int argc, char **argv)

      |          ~~~~^~~~
openat2_test.c:326:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
  326 | int main(int argc, char **argv)
      |                    ~~~~~~~^~~~

Use size_t for array loop iterator, explicitly cast open_how flags field to fix -Wsign-compare warnings

Remove unused argc & argv parameters to fix -Wunused-parameter warnings

---
 tools/testing/selftests/openat2/openat2_test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/openat2/openat2_test.c +5 -5
index 0e161ef9e9e4..a8b73b62c7c5 100644
@@ -86,11 +86,11 @@ void test_openat2_struct(void)
 	BUILD_BUG_ON(ARRAY_LEN(misalignments) != NUM_OPENAT2_STRUCT_VARIATIONS);
 	BUILD_BUG_ON(ARRAY_LEN(tests) != NUM_OPENAT2_STRUCT_TESTS);
 
-	for (int i = 0; i < ARRAY_LEN(tests); i++) {
+	for (size_t i = 0; i < ARRAY_LEN(tests); i++) {
 		struct struct_test *test = &tests[i];
 		struct open_how_ext how_ext = test->arg;
 
-		for (int j = 0; j < ARRAY_LEN(misalignments); j++) {
+		for (size_t j = 0; j < ARRAY_LEN(misalignments); j++) {
 			int fd, misalign = misalignments[j];
 			char *fdpath = NULL;
 			bool failed;
@@ -243,7 +243,7 @@ void test_openat2_flags(void)
 
 	BUILD_BUG_ON(ARRAY_LEN(tests) != NUM_OPENAT2_FLAG_TESTS);
 
-	for (int i = 0; i < ARRAY_LEN(tests); i++) {
+	for (size_t i = 0; i < ARRAY_LEN(tests); i++) {
 		int fd, fdflags = -1;
 		char *path, *fdpath = NULL;
 		bool failed = false;
@@ -293,7 +293,7 @@ void test_openat2_flags(void)
 				fdflags |= O_CREAT;
 			if (!(test->how.flags & O_LARGEFILE))
 				fdflags &= ~O_LARGEFILE;
-			failed |= (fdflags != test->how.flags);
+			failed |= (fdflags != (int)test->how.flags);
 		}
 
 		if (failed) {
@@ -323,7 +323,7 @@ void test_openat2_flags(void)
 #define NUM_TESTS (NUM_OPENAT2_STRUCT_VARIATIONS * NUM_OPENAT2_STRUCT_TESTS + \
 		   NUM_OPENAT2_FLAG_TESTS)
 
-int main(int argc, char **argv)
+int main()
 {
 	ksft_print_header();
 	ksft_set_plan(NUM_TESTS);
Signature · 1 line
2.54.0