Skip to contentSkip to conversation

selftests: net: fix format warnings on 32-bit architectures

PATCH Applied Sasha Levin 4 participants 4 messages Nov 3 – Nov 6

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

PATCH 1/1 selftests: net: fix format warnings on 32-bit architectures

On 32-bit architectures ssize_t is an int, tv_sec is a long long with a 64-bit time_t, and uint64_t is not a size_t, so ipsec, txtimestamp and the tcp_ao library warn when printing them with %ld, %lu and %zu:

txtimestamp.c:191:42: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Print ssize_t with %zd, tv_sec as long long, and the net namespace cookies with PRIu64 as the rest of ftrace-tcp.c already does. While at it, print tv_nsec, a long, with %ld instead of %lu, and cast it to long, as it is a long long on x32.

---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16 and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without format warnings there now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

 tools/testing/selftests/net/ipsec.c                 | 2 +-
 tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c | 2 +-
 tools/testing/selftests/net/txtimestamp.c           | 9 +++++----
 3 files changed, 7 insertions(+), 6 deletions(-)
tools/testing/selftests/net/ipsec.c +1 -1
index 89c32c354c008..ba8c36a93f176 100644
@@ -2030,7 +2030,7 @@ static int __write_desc(int test_desc_fd, struct xfrm_desc *desc)
 	if (ret == sizeof(*desc))
 		return 0;
 
-	pr_err("Writing test's desc failed %ld", ret);
+	pr_err("Writing test's desc failed %zd", ret);
 
 	return -1;
 }
tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c +1 -1
index 27403f8750547..cd93ff8965dda 100644
@@ -504,7 +504,7 @@ static int setup_tcp_trace_events(struct test_ftracer *tracer)
 	size_t i;
 	int ret;
 
-	filter = test_sprintf("net_cookie == %zu || net_cookie == %zu",
+	filter = test_sprintf("net_cookie == %" PRIu64 " || net_cookie == %" PRIu64,
 			      ns_cookie1, ns_cookie2);
 	if (!filter)
 		return -ENOMEM;
tools/testing/selftests/net/txtimestamp.c +5 -4
index f7bdf30b78d9f..be1452d73b303 100644
@@ -188,12 +188,13 @@ static void __print_timestamp(const char *name, struct timespec *cur,
 		return;
 
 	if (cfg_print_nsec)
-		fprintf(stderr, "  %s: %lu s %lu ns (seq=%u, len=%u)",
-				name, cur->tv_sec, cur->tv_nsec,
+		fprintf(stderr, "  %s: %lld s %ld ns (seq=%u, len=%u)",
+				name, (long long)cur->tv_sec, (long)cur->tv_nsec,
 				key, payload_len);
 	else
-		fprintf(stderr, "  %s: %lu s %lu us (seq=%u, len=%u)",
-				name, cur->tv_sec, cur->tv_nsec / NSEC_PER_USEC,
+		fprintf(stderr, "  %s: %lld s %ld us (seq=%u, len=%u)",
+				name, (long long)cur->tv_sec,
+				(long)(cur->tv_nsec / NSEC_PER_USEC),
 				key, payload_len);
 
 	if (cur != &ts_usr) {
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 63 lines · Sasha Levin

On 32-bit architectures ssize_t is an int, tv_sec is a long long with a 64-bit time_t, and uint64_t is not a size_t, so ipsec, txtimestamp and the tcp_ao library warn when printing them with %ld, %lu and %zu:

txtimestamp.c:191:42: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Print ssize_t with %zd, tv_sec as long long, and the net namespace cookies with PRIu64 as the rest of ftrace-tcp.c already does. While at it, print tv_nsec, a long, with %ld instead of %lu, and cast it to long, as it is a long long on x32.

---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16 and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without format warnings there now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

  tools/testing/selftests/net/ipsec.c                 | 2 +-
  tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c | 2 +-
  tools/testing/selftests/net/txtimestamp.c           | 9 +++++----
  3 files changed, 7 insertions(+), 6 deletions(-)
tools/testing/selftests/net/ipsec.c +1 -1
index 89c32c354c008..ba8c36a93f176 100644
@@ -2030,7 +2030,7 @@ static int __write_desc(int test_desc_fd, struct xfrm_desc *desc)
  	if (ret == sizeof(*desc))
  		return 0;
 
-	pr_err("Writing test's desc failed %ld", ret);
+	pr_err("Writing test's desc failed %zd", ret);
 
  	return -1;
  }
tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c +1 -1
index 27403f8750547..cd93ff8965dda 100644
@@ -504,7 +504,7 @@ static int setup_tcp_trace_events(struct test_ftracer *tracer)
  	size_t i;
  	int ret;
 
-	filter = test_sprintf("net_cookie == %zu || net_cookie == %zu",
+	filter = test_sprintf("net_cookie == %" PRIu64 " || net_cookie == %" PRIu64,
  			      ns_cookie1, ns_cookie2);
  	if (!filter)
  		return -ENOMEM;
tools/testing/selftests/net/txtimestamp.c +2 -2
index f7bdf30b78d9f..be1452d73b303 100644
@@ -188,12 +188,13 @@ static void __print_timestamp(const char *name, struct timespec *cur,
  		return;
 
  	if (cfg_print_nsec)
-		fprintf(stderr, "  %s: %lu s %lu ns (seq=%u, len=%u)",
-				name, cur->tv_sec, cur->tv_nsec,
+		fprintf(stderr, "  %s: %lld s %ld ns (seq=%u, len=%u)",
+				name, (long long)cur->tv_sec, (long)cur->tv_nsec,

tools/testing/selftests/net/txtimestamp.c static void __print_timestamp(const char *name, struct timespec *cur, · line 200

Quoted 10 lines
tools/testing/selftests/net/txtimestamp.c +3 -2
  				key, payload_len);
  	else
-		fprintf(stderr, "  %s: %lu s %lu us (seq=%u, len=%u)",
-				name, cur->tv_sec, cur->tv_nsec / NSEC_PER_USEC,
+		fprintf(stderr, "  %s: %lld s %ld us (seq=%u, len=%u)",
+				name, (long long)cur->tv_sec,
+				(long)(cur->tv_nsec / NSEC_PER_USEC),
  				key, payload_len);
 
  	if (cur != &ts_usr) {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Sasha Levin
Quoted 76 lines · Sasha Levin

On 32-bit architectures ssize_t is an int, tv_sec is a long long with a 64-bit time_t, and uint64_t is not a size_t, so ipsec, txtimestamp and the tcp_ao library warn when printing them with %ld, %lu and %zu:

txtimestamp.c:191:42: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Print ssize_t with %zd, tv_sec as long long, and the net namespace cookies with PRIu64 as the rest of ftrace-tcp.c already does. While at it, print tv_nsec, a long, with %ld instead of %lu, and cast it to long, as it is a long long on x32.

---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16 and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without format warnings there now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

 tools/testing/selftests/net/ipsec.c                 | 2 +-
 tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c | 2 +-
 tools/testing/selftests/net/txtimestamp.c           | 9 +++++----
 3 files changed, 7 insertions(+), 6 deletions(-)
tools/testing/selftests/net/ipsec.c +1 -1
index 89c32c354c008..ba8c36a93f176 100644
@@ -2030,7 +2030,7 @@ static int __write_desc(int test_desc_fd, struct xfrm_desc *desc)
 	if (ret == sizeof(*desc))
 		return 0;
 
-	pr_err("Writing test's desc failed %ld", ret);
+	pr_err("Writing test's desc failed %zd", ret);
 
 	return -1;
 }
tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c +1 -1
index 27403f8750547..cd93ff8965dda 100644
@@ -504,7 +504,7 @@ static int setup_tcp_trace_events(struct test_ftracer *tracer)
 	size_t i;
 	int ret;
 
-	filter = test_sprintf("net_cookie == %zu || net_cookie == %zu",
+	filter = test_sprintf("net_cookie == %" PRIu64 " || net_cookie == %" PRIu64,
 			      ns_cookie1, ns_cookie2);
 	if (!filter)
 		return -ENOMEM;
tools/testing/selftests/net/txtimestamp.c +5 -4
index f7bdf30b78d9f..be1452d73b303 100644
@@ -188,12 +188,13 @@ static void __print_timestamp(const char *name, struct timespec *cur,
 		return;
 
 	if (cfg_print_nsec)
-		fprintf(stderr, "  %s: %lu s %lu ns (seq=%u, len=%u)",
-				name, cur->tv_sec, cur->tv_nsec,
+		fprintf(stderr, "  %s: %lld s %ld ns (seq=%u, len=%u)",
+				name, (long long)cur->tv_sec, (long)cur->tv_nsec,
 				key, payload_len);
 	else
-		fprintf(stderr, "  %s: %lu s %lu us (seq=%u, len=%u)",
-				name, cur->tv_sec, cur->tv_nsec / NSEC_PER_USEC,
+		fprintf(stderr, "  %s: %lld s %ld us (seq=%u, len=%u)",
+				name, (long long)cur->tv_sec,
+				(long)(cur->tv_nsec / NSEC_PER_USEC),
 				key, payload_len);
 
 	if (cur != &ts_usr) {
Signature · 1 line
2.53.0
#3 lore raw
In reply to Sasha Levin
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 4 lines · On Tue, 3 Nov 2026 10:55:03 -0500 you wrote:

On 32-bit architectures ssize_t is an int, tv_sec is a long long with a 64-bit time_t, and uint64_t is not a size_t, so ipsec, txtimestamp and the tcp_ao library warn when printing them with %ld, %lu and %zu:

Quoted 8 lines

txtimestamp.c:191:42: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Print ssize_t with %zd, tv_sec as long long, and the net namespace cookies with PRIu64 as the rest of ftrace-tcp.c already does. While at it, print tv_nsec, a long, with %ld instead of %lu, and cast it to long, as it is a long long on x32.

[...]

Here is the summary with links:
- selftests: net: fix format warnings on 32-bit architectures

    https://git.kernel.org/netdev/net-next/c/205f10778a94

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html