Re: [PATCH] selftests/mm: fix format warnings on 32-bit architectures
From: Zi Yan
Date: Tue Nov 03 2026 - 11:47:24 EST
On 3 Nov 2026, at 10:54, Sasha Levin wrote:
> On 32-bit architectures size_t and uintptr_t are unsigned int and
> ssize_t is int, and with _FILE_OFFSET_BITS=64 off_t is long long, so
> printing them with %ld, %lu or %lx, or scanning /proc/self/maps into
> uintptr_t variables with %lx, warns:
>
> hugetlb-read-hwpoison.c:32:58: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
>
> Print size_t with %zu and %zx, casting the nonnegative ssize_t read
> totals to size_t, print off_t as unsigned long long, and scan the
> addresses into unsigned long variables.
>
> split_huge_page_test also builds its debugfs commands from uint64_t
> addresses with %lx. write_debugfs() has no format attribute, so nothing
> warned, but on 32-bit the commands get the wrong addresses. Print them
> with PRIx64, add the attribute, and cast the pointers through uintptr_t,
> as casting them straight to uint64_t warns on 32-bit too.
>
> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
> ---
> 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/mm/hugetlb-read-hwpoison.c | 25 +++++++-------
> .../selftests/mm/hugetlb-soft-offline.c | 2 +-
> tools/testing/selftests/mm/mseal_test.c | 2 +-
> .../selftests/mm/split_huge_page_test.c | 34 +++++++++----------
> 4 files changed, 32 insertions(+), 31 deletions(-)
>
<snip>
> @@ -70,7 +70,7 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
> return status;
> }
>
> -static void write_debugfs(const char *fmt, ...)
> +static __printf(1, 2) void write_debugfs(const char *fmt, ...)
TIL, __printf() tells the compiler that write_debugfs() is doing
printf_style arguments and the compiler will do the corresponding
checks.
LGTM. Thanks.
Acked-by: Zi Yan <ziy@xxxxxxxxxx>
Best Regards,
Yan, Zi