Skip to contentSkip to conversation

selftests/pidfd: print time_t as long long

PATCH Applied Sasha Levin 3 participants 3 messages Nov 3 – Nov 18

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

PATCH 1/1 selftests/pidfd: print time_t as long long

On 32-bit architectures with a 64-bit time_t, such as armhf in Debian 13, printing the time_t values with %lu warns:

pidfd_test.c:523:50: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'time_t' {aka 'long long int'} [-Wformat=]

Cast them to long long and print them with %lld.

---
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/pidfd/pidfd_test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/pidfd/pidfd_test.c +3 -2
index 932cbd8caa770..a53e72cb256ce 100644
@@ -520,7 +520,7 @@ static void test_pidfd_poll_exec(int use_waitpid)
 
 	time_t prog_time = time(NULL) - prog_start;
 
-	ksft_print_msg("Time waited for child: %lu\n", prog_time);
+	ksft_print_msg("Time waited for child: %lld\n", (long long)prog_time);
 
 	close(pidfd);
 
@@ -599,7 +599,8 @@ static void test_pidfd_poll_leader_exit(int use_waitpid)
 
 	time_t since_child_exit = time(NULL) - *child_exit_secs;
 
-	ksft_print_msg("Time since child exit: %lu\n", since_child_exit);
+	ksft_print_msg("Time since child exit: %lld\n",
+		       (long long)since_child_exit);
 
 	close(pidfd);
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 8 lines · Sasha Levin

On 32-bit architectures with a 64-bit time_t, such as armhf in Debian 13, printing the time_t values with %lu warns:

pidfd_test.c:523:50: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'time_t' {aka 'long long int'} [-Wformat=]

Cast them to long long and print them with %lld.

[...]

Applied to the vfs-7.5.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.5.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.5.misc

[1/1] selftests/pidfd: print time_t as long long

      https://git.kernel.org/vfs/vfs/c/448c990ad379
#2 lore raw
In reply to Sasha Levin
Quoted 24 lines · On Tue, 3 Nov 2026 10:54:47 -0500 Sasha Levin <[email protected]> wrote:

On 32-bit architectures with a 64-bit time_t, such as armhf in Debian 13, printing the time_t values with %lu warns:

pidfd_test.c:523:50: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'time_t' {aka 'long long int'} [-Wformat=]

Cast them to long long and print them with %lld.

---
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/pidfd/pidfd_test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/pidfd/pidfd_test.c +0 -0
index 932cbd8caa770..a53e72cb256ce 100644

tools/testing/selftests/pidfd/pidfd_test.c static void test_pidfd_poll_exec(int use_waitpid) · line 521

Quoted 2 lines
tools/testing/selftests/pidfd/pidfd_test.c +0 -0
@@ -520,7 +520,7 @@ static void test_pidfd_poll_exec(int use_waitpid)
 
 	time_t prog_time = time(NULL) - prog_start;

Why not just change the type to 'unsigned int' and use "%u" ? It isn't as though the difference is going to be longer than 75 years.

David

Quoted 16 lines
tools/testing/selftests/pidfd/pidfd_test.c +3 -2
-	ksft_print_msg("Time waited for child: %lu\n", prog_time);
+	ksft_print_msg("Time waited for child: %lld\n", (long long)prog_time);
 
 	close(pidfd);
 
@@ -599,7 +599,8 @@ static void test_pidfd_poll_leader_exit(int use_waitpid)
 
 	time_t since_child_exit = time(NULL) - *child_exit_secs;
 
-	ksft_print_msg("Time since child exit: %lu\n", since_child_exit);
+	ksft_print_msg("Time since child exit: %lld\n",
+		       (long long)since_child_exit);
 
 	close(pidfd);