Commit 9bfa52da authored by Tamir Duberstein's avatar Tamir Duberstein Committed by Petr Mladek
Browse files

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: default avatarkernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202512061600.89CKQ3ag-lkp@intel.com/


Signed-off-by: default avatarTamir Duberstein <tamird@kernel.org>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20260121-printf-kunit-printf-attr-v3-1-4144f337ec8b@kernel.org


Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
parent bdfcca65
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -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.