diff options
| author | Tamir Duberstein <tamird@kernel.org> | 2026-01-21 11:10:08 -0500 |
|---|---|---|
| committer | Petr Mladek <pmladek@suse.com> | 2026-01-28 10:19:40 +0100 |
| commit | 9bfa52dac27a20b43bcb73e56dc45aba6b9aaff1 (patch) | |
| tree | 4f1c767df43cc96b8a6ddf0fef99c7e13a2891b2 /lib | |
| parent | bdfcca65e7a681f7511a5c15501a01dd855f6d23 (diff) | |
printf: convert test_hashed into macro
This allows the compiler to check the arguments against the __printf()
attribute on __test(). This produces better diagnostics when incorrect
inputs are passed.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202512061600.89CKQ3ag-lkp@intel.com/
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20260121-printf-kunit-printf-attr-v3-1-4144f337ec8b@kernel.org
Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tests/printf_kunit.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c index 7617e5b8b02c..f6f21b445ece 100644 --- a/lib/tests/printf_kunit.c +++ b/lib/tests/printf_kunit.c @@ -266,15 +266,17 @@ hash_pointer(struct kunit *kunittest) KUNIT_EXPECT_MEMNEQ(kunittest, buf, PTR_STR, PTR_WIDTH); } -static void -test_hashed(struct kunit *kunittest, const char *fmt, const void *p) -{ - char buf[PLAIN_BUF_SIZE]; - - plain_hash_to_buffer(kunittest, p, buf, PLAIN_BUF_SIZE); - - test(buf, fmt, p); -} +/* + * This is a macro so that the compiler can compare its arguments to the + * __printf() attribute on __test(). This cannot be a function with a __printf() + * attribute because GCC requires __printf() functions to be variadic. + */ +#define test_hashed(kunittest, fmt, p) \ + do { \ + char buf[PLAIN_BUF_SIZE]; \ + plain_hash_to_buffer(kunittest, p, buf, PLAIN_BUF_SIZE); \ + test(buf, fmt, p); \ + } while (0) /* * NULL pointers aren't hashed. |
