tools/testing/selftests/kselftest.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
ksft_print_dbg_msg() passes a va_list to ksft_print_msg() as a regular
variadic argument. As a result, format specifiers consume the va_list
representation instead of the caller's arguments and print garbage.
Add a va_list-based helper and use it from both message printing
functions. Also annotate ksft_print_dbg_msg() so the compiler can check
its format arguments.
Fixes: f2662ec26b26 ("selftests: kselftest: Create ksft_print_dbg_msg()")
Signed-off-by: ZhuangZhuang Wang <wzz_123123@163.com>
---
tools/testing/selftests/kselftest.h | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index ae18c491a..d815a8667 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -173,19 +173,25 @@ static inline void ksft_print_cnts(void)
ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
}
-static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...)
+static inline void ksft_vprint_msg(const char *msg, va_list args)
{
int saved_errno = errno;
- va_list args;
- va_start(args, msg);
printf("# ");
errno = saved_errno;
vprintf(msg, args);
+}
+
+static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...)
+{
+ va_list args;
+
+ va_start(args, msg);
+ ksft_vprint_msg(msg, args);
va_end(args);
}
-static inline void ksft_print_dbg_msg(const char *msg, ...)
+static inline __printf(1, 2) void ksft_print_dbg_msg(const char *msg, ...)
{
va_list args;
@@ -193,7 +199,7 @@ static inline void ksft_print_dbg_msg(const char *msg, ...)
return;
va_start(args, msg);
- ksft_print_msg(msg, args);
+ ksft_vprint_msg(msg, args);
va_end(args);
}
Em 16/09/2026 16:04, ZhuangZhuang Wang escreveu:
> ksft_print_dbg_msg() passes a va_list to ksft_print_msg() as a regular
> variadic argument. As a result, format specifiers consume the va_list
> representation instead of the caller's arguments and print garbage.
>
> Add a va_list-based helper and use it from both message printing
> functions. Also annotate ksft_print_dbg_msg() so the compiler can check
> its format arguments.
>
> Fixes: f2662ec26b26 ("selftests: kselftest: Create ksft_print_dbg_msg()")
> Signed-off-by: ZhuangZhuang Wang <wzz_123123@163.com>
Reviewed-by: André Almeida <andrealmeid@igalia.com>
© 2016 - 2026 Red Hat, Inc.