mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: net: fix format warnings on 32-bit architectures
@ 2026-11-03 15:55 Sasha Levin
  2026-11-03 17:59 ` Mohsin Bashir
  0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2026-11-03 15:55 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: Simon Horman, Shuah Khan, Jason Xing, netdev, linux-kselftest,
	linux-kernel

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.

Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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(-)

diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c
index 89c32c354c008..ba8c36a93f176 100644
--- a/tools/testing/selftests/net/ipsec.c
+++ b/tools/testing/selftests/net/ipsec.c
@@ -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;
 }
diff --git a/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c b/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
index 27403f8750547..cd93ff8965dda 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
@@ -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;
diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
index f7bdf30b78d9f..be1452d73b303 100644
--- a/tools/testing/selftests/net/txtimestamp.c
+++ b/tools/testing/selftests/net/txtimestamp.c
@@ -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) {
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: net: fix format warnings on 32-bit architectures
  2026-11-03 15:55 [PATCH] selftests: net: fix format warnings on 32-bit architectures Sasha Levin
@ 2026-11-03 17:59 ` Mohsin Bashir
  0 siblings, 0 replies; 2+ messages in thread
From: Mohsin Bashir @ 2026-11-03 17:59 UTC (permalink / raw)
  To: Sasha Levin, Steffen Klassert, Herbert Xu, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: Simon Horman, Shuah Khan, Jason Xing, netdev, linux-kselftest,
	linux-kernel



On 11/3/26 7:55 AM, Sasha Levin 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:
> 
>    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.
> 
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> 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(-)
> 
> diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c
> index 89c32c354c008..ba8c36a93f176 100644
> --- a/tools/testing/selftests/net/ipsec.c
> +++ b/tools/testing/selftests/net/ipsec.c
> @@ -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;
>   }
> diff --git a/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c b/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
> index 27403f8750547..cd93ff8965dda 100644
> --- a/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
> +++ b/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
> @@ -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;
> diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
> index f7bdf30b78d9f..be1452d73b303 100644
> --- a/tools/testing/selftests/net/txtimestamp.c
> +++ b/tools/testing/selftests/net/txtimestamp.c
> @@ -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) {

Reviewed-by: Mohsin Bashir <hmohsin@meta.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-03 17:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 15:55 [PATCH] selftests: net: fix format warnings on 32-bit architectures Sasha Levin
2026-11-03 17:59 ` Mohsin Bashir

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®