mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 13:23:23 +01:00
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 <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Tamir Duberstein <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Petr Mladek <[email protected]>
This commit is contained in:
1 parent
bdfcca65e7
commit
9bfa52dac2
1 file changed
+11
-9
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user