Skip to contentSkip to conversation

selftests/net: initialize char variable to null

PATCH Superseded Ankit Khushwaha 2 participants 7 messages Nov 24, 2025 – Nov 25, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/net: initialize char variable to null

char variable in 'so_txtime.c' & 'txtimestamp.c' left uninitilized by when switch default case taken. raises following warning.

txtimestamp.c:240:2: warning: variable 'tsname' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

initialize these variables to NULL to fix this.

---
 tools/testing/selftests/net/so_txtime.c   | 2 +-
 tools/testing/selftests/net/txtimestamp.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/so_txtime.c +1 -1
index 8457b7ccbc09..b76df1efc2ef 100644
@@ -174,7 +174,7 @@ static int do_recv_errqueue_timeout(int fdt)
 	msg.msg_controllen = sizeof(control);
 
 	while (1) {
-		const char *reason;
+		const char *reason = NULL;
 
 		ret = recvmsg(fdt, &msg, MSG_ERRQUEUE);
 		if (ret == -1 && errno == EAGAIN)
tools/testing/selftests/net/txtimestamp.c +1 -1
index dae91eb97d69..bcc14688661d 100644
@@ -217,7 +217,7 @@ static void print_timestamp_usr(void)
 static void print_timestamp(struct scm_timestamping *tss, int tstype,
 			    int tskey, int payload_len)
 {
-	const char *tsname;
+	const char *tsname = NULL;
 
 	validate_key(tskey, tstype);
 

--
2.52.0

maintainer
#1 lore raw
Quoted 6 lines · Ankit Khushwaha

char variable in 'so_txtime.c' & 'txtimestamp.c' left uninitilized by when switch default case taken. raises following warning.

txtimestamp.c:240:2: warning: variable 'tsname' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

Quoted 6 lines

so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

initialize these variables to NULL to fix this.

These are false positives as the default branches in both cases exit the program with error(..).

Since we do not observe these in normal kernel compilations: are you enabling non-standard warnings?

Quoted 34 lines
---
 tools/testing/selftests/net/so_txtime.c   | 2 +-
 tools/testing/selftests/net/txtimestamp.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/so_txtime.c +1 -1
index 8457b7ccbc09..b76df1efc2ef 100644
@@ -174,7 +174,7 @@ static int do_recv_errqueue_timeout(int fdt)
 	msg.msg_controllen = sizeof(control);
 
 	while (1) {
-		const char *reason;
+		const char *reason = NULL;
 
 		ret = recvmsg(fdt, &msg, MSG_ERRQUEUE);
 		if (ret == -1 && errno == EAGAIN)
tools/testing/selftests/net/txtimestamp.c +1 -2
index dae91eb97d69..bcc14688661d 100644
@@ -217,7 +217,7 @@ static void print_timestamp_usr(void)
 static void print_timestamp(struct scm_timestamping *tss, int tstype,
 			    int tskey, int payload_len)
 {
-	const char *tsname;
+	const char *tsname = NULL;
 
 	validate_key(tskey, tstype);
 
--

2.52.0

#2 lore raw
Quoted 12 lines · Willem de Bruijn
Quoted 11 lines · Ankit Khushwaha

char variable in 'so_txtime.c' & 'txtimestamp.c' left uninitilized by when switch default case taken. raises following warning.

txtimestamp.c:240:2: warning: variable 'tsname' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

initialize these variables to NULL to fix this.

Quoted 7 lines
Quoted 1 line

These are false positives as the default branches in both cases exit the program with error(..).

Since we do not observe these in normal kernel compilations: are you enabling non-standard warnings?

Hi Willem,

this warning appeared while building the 'tools/testing/selftests/net' multiple times.
Cmd used to build
make -C tools/testing/selftests/net CC=clang V=1 -j8

while test building by "make -C tools/testing/selftests/ CC=clang V=1 -j8" doesn't raises these warning.

Thanks,
-- Ankit

maintainer
#3 lore raw
Quoted 23 lines · Ankit Khushwaha
Quoted 12 lines · Willem de Bruijn
Quoted 11 lines · Ankit Khushwaha

char variable in 'so_txtime.c' & 'txtimestamp.c' left uninitilized by when switch default case taken. raises following warning.

txtimestamp.c:240:2: warning: variable 'tsname' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

so_txtime.c:210:3: warning: variable 'reason' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

initialize these variables to NULL to fix this.

Quoted 7 lines
Quoted 1 line

These are false positives as the default branches in both cases exit the program with error(..).

Since we do not observe these in normal kernel compilations: are you enabling non-standard warnings?

Hi Willem,

Quoted 7 lines

this warning appeared while building the 'tools/testing/selftests/net' multiple times.
Cmd used to build
make -C tools/testing/selftests/net CC=clang V=1 -j8

while test building by "make -C tools/testing/selftests/ CC=clang V=1 -j8" doesn't raises these warning.

This does not reproduce for me.

Can you share the full clang command that V=1 outputs, as well as the output oof clang --version.

maintainer Reviewed-by
#5 lore raw
Quoted 6 lines · Ankit Khushwaha
Quoted 4 lines · Willem de Bruijn

This does not reproduce for me.

Can you share the full clang command that V=1 outputs, as well as the output oof clang --version.

Quoted 6 lines

Hi Willem,
I have added clang output in
https://gist.github.com/ankitkhushwaha/8e93e3d37917b3571a7ce0e9c9806f18

Thanks,
Ankit

I see. This is with clang-21. It did not trigger for me with clang-19.

I was able to reproduce with Ubuntu 25.10.

Okay, good to suppress these false positives with normal builds.

maintainer
#6 lore raw
Quoted 14 lines · Willem de Bruijn
Quoted 6 lines · Ankit Khushwaha
Quoted 4 lines · Willem de Bruijn

This does not reproduce for me.

Can you share the full clang command that V=1 outputs, as well as the output oof clang --version.

Quoted 6 lines

Hi Willem,
I have added clang output in
https://gist.github.com/ankitkhushwaha/8e93e3d37917b3571a7ce0e9c9806f18

Thanks,
Ankit

Quoted 8 lines

I see. This is with clang-21. It did not trigger for me with clang-19.

I was able to reproduce with Ubuntu 25.10.

Okay, good to suppress these false positives with normal builds.

The patch status is already changes requested.

Please resubmit and target [PATCH net-next]