All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"Shuah Khan" <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] selftests: vDSO: print tv_sec as long long in vdso_test_getrandom
Date: Tue,  3 Nov 2026 10:55:14 -0500	[thread overview]
Message-ID: <20261103155514.535166-1-sashal@kernel.org> (raw)

On 32-bit architectures with a 64-bit time_t, such as armhf in Debian
13, tv_sec is a long long, and printing it with %lu warns:

  vdso_test_getrandom.c:184:40: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Cast it to long long and print it with %lld. 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.

 .../selftests/vDSO/vdso_test_getrandom.c       | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
index ef402001e8988..504b84d4cc53e 100644
--- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c
+++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
@@ -181,19 +181,22 @@ static void bench_single(void)
 	test_vdso_getrandom(NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   vdso: %u times in %lu.%09lu seconds\n", TRIALS, diff.tv_sec, diff.tv_nsec);
+	printf("   vdso: %u times in %lld.%09ld seconds\n", TRIALS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	test_libc_getrandom(NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   libc: %u times in %lu.%09lu seconds\n", TRIALS, diff.tv_sec, diff.tv_nsec);
+	printf("   libc: %u times in %lld.%09ld seconds\n", TRIALS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	test_syscall_getrandom(NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("syscall: %u times in %lu.%09lu seconds\n", TRIALS, diff.tv_sec, diff.tv_nsec);
+	printf("syscall: %u times in %lld.%09ld seconds\n", TRIALS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 }
 
 static void bench_multi(void)
@@ -208,7 +211,8 @@ static void bench_multi(void)
 		pthread_join(threads[i], NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   vdso: %u x %u times in %lu.%09lu seconds\n", TRIALS, THREADS, diff.tv_sec, diff.tv_nsec);
+	printf("   vdso: %u x %u times in %lld.%09ld seconds\n", TRIALS, THREADS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	for (size_t i = 0; i < THREADS; ++i)
@@ -217,7 +221,8 @@ static void bench_multi(void)
 		pthread_join(threads[i], NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   libc: %u x %u times in %lu.%09lu seconds\n", TRIALS, THREADS, diff.tv_sec, diff.tv_nsec);
+	printf("   libc: %u x %u times in %lld.%09ld seconds\n", TRIALS, THREADS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	for (size_t i = 0; i < THREADS; ++i)
@@ -226,7 +231,8 @@ static void bench_multi(void)
 		pthread_join(threads[i], NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   syscall: %u x %u times in %lu.%09lu seconds\n", TRIALS, THREADS, diff.tv_sec, diff.tv_nsec);
+	printf("   syscall: %u x %u times in %lld.%09ld seconds\n", TRIALS, THREADS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 }
 
 static void fill(void)
-- 
2.53.0


             reply	other threads:[~2026-11-03 15:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 15:55 Sasha Levin [this message]
2026-11-03 16:24 ` [PATCH] selftests: vDSO: print tv_sec as long long in vdso_test_getrandom Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103155514.535166-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.