Skip to contentSkip to conversation

selftests/statmount: fix format warnings on 32-bit and s390

PATCH Applied Sasha Levin 2 participants 2 messages Nov 3 – Nov 5

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

PATCH 1/1 selftests/statmount: fix format warnings on 32-bit and s390

The f_type field of struct statfs is an int on i386 and armhf and an unsigned int on s390x, and the listmount() results are uint64_t, so printing them with %lx and %zi warns:

statmount_test_ns.c:243:56: warning: format '%zi' expects argument of type 'signed size_t', but argument 2 has type 'uint64_t' {aka 'long long unsigned int'} [-Wformat=]

Cast f_type to unsigned long, and print the listmount() results as unsigned long long.

On i386 and armhf the comparison next to it also sign-extends f_type to the 64-bit sb_magic, so a file system with the top bit set in its magic, such as btrfs, fails the test. Compare against the same cast.

---
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 and s390 builds show the same warnings. The changed files build without format warnings in the 32-bit builds now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

 .../testing/selftests/filesystems/statmount/statmount_test.c | 4 ++--
 .../selftests/filesystems/statmount/statmount_test_ns.c      | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +2 -2
index b237a95ec9fb3..8133a5841ac08 100644
@@ -335,10 +335,10 @@ static void test_statmount_sb_basic(void)
 		return;
 	}
 
-	if (sm.sb_magic != sf.f_type) {
+	if (sm.sb_magic != (unsigned long)sf.f_type) {
 		ksft_test_result_fail("unexpected sb magic: 0x%llx != 0x%lx\n",
 				      (unsigned long long) sm.sb_magic,
-				      sf.f_type);
+				      (unsigned long) sf.f_type);
 		return;
 	}
 
tools/testing/selftests/filesystems/statmount/statmount_test_ns.c +3 -2
index e500905e4c078..c9ef755ffaa72 100644
@@ -240,8 +240,9 @@ static int validate_external_listmount(pid_t pid, uint64_t child_nr_mounts)
 	}
 
 	if (nr_mounts != child_nr_mounts) {
-		ksft_print_msg("listmount results is %zi != %zi\n", nr_mounts,
-			       child_nr_mounts);
+		ksft_print_msg("listmount results is %llu != %llu\n",
+			       (unsigned long long)nr_mounts,
+			       (unsigned long long)child_nr_mounts);
 		return NSID_FAIL;
 	}
 
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Sasha Levin

The f_type field of struct statfs is an int on i386 and armhf and an unsigned int on s390x, and the listmount() results are uint64_t, so printing them with %lx and %zi warns:

statmount_test_ns.c:243:56: warning: format '%zi' expects argument of type 'signed size_t', but argument 2 has type 'uint64_t' {aka 'long long unsigned int'} [-Wformat=]

Cast f_type to unsigned long, and print the listmount() results as unsigned long long.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes 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.fixes

[1/1] selftests/statmount: fix format warnings on 32-bit and s390

      https://git.kernel.org/vfs/vfs/c/de48f2a93e4f