linux-stable/Documentation/dev-tools
David Gow 7cca68f666 kunit: Add a macro to wrap a deferred action function
commit 56778b49c9 upstream.

KUnit's deferred action API accepts a void(*)(void *) function pointer
which is called when the test is exited. However, we very frequently
want to use existing functions which accept a single pointer, but which
may not be of type void*. While this is probably dodgy enough to be on
the wrong side of the C standard, it's been often used for similar
callbacks, and gcc's -Wcast-function-type seems to ignore cases where
the only difference is the type of the argument, assuming it's
compatible (i.e., they're both pointers to data).

However, clang 16 has introduced -Wcast-function-type-strict, which no
longer permits any deviation in function pointer type. This seems to be
because it'd break CFI, which validates the type of function calls.

This rather ruins our attempts to cast functions to defer them, and
leaves us with a few options. The one we've chosen is to implement a
macro which will generate a wrapper function which accepts a void*, and
casts the argument to the appropriate type.

For example, if you were trying to wrap:
void foo_close(struct foo *handle);
you could use:
KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_foo_close,
			    foo_close,
			    struct foo *);

This would create a new kunit_action_foo_close() function, of type
kunit_action_t, which could be passed into kunit_add_action() and
similar functions.

In addition to defining this macro, update KUnit and its tests to use
it.

Link: https://github.com/ClangBuiltLinux/linux/issues/1750
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-03-01 13:41:44 +01:00
..
kunit kunit: Add a macro to wrap a deferred action function 2024-03-01 13:41:44 +01:00
checkpatch.rst checkpatch: warn for non-standard fixes tag style 2022-10-03 14:21:44 -07:00
coccinelle.rst Documentation: coccinelle: Escape --options to fix Sphinx output 2023-01-31 13:55:44 -07:00
gcov.rst
gdb-kernel-debugging.rst docs/scripts/gdb: add necessary make scripts_gdb step 2023-01-26 11:21:05 -07:00
index.rst kmsan: add ReST documentation 2022-10-03 14:03:18 -07:00
kasan.rst Documentation: *san: drop "the" from article titles 2023-10-18 14:34:15 -07:00
kcov.rst kcov: improve documentation 2023-04-08 13:45:36 -07:00
kcsan.rst Documentation: *san: drop "the" from article titles 2023-10-18 14:34:15 -07:00
kfence.rst kfence: allow use of a deferrable timer 2022-03-22 15:57:11 -07:00
kgdb.rst Documentation: kgdb: Replace deprecated remotebaud 2022-01-07 09:33:13 -07:00
kmemleak.rst docs: kmemleak: adjust to config renaming 2023-04-20 17:53:38 -06:00
kmsan.rst Documentation: *san: drop "the" from article titles 2023-10-18 14:34:15 -07:00
kselftest.rst Documentation: kselftests: Remove references to bpf tests 2023-10-09 14:06:17 -06:00
ktap.rst Documentation: dev-tools: Clarify requirements for result description 2022-12-12 14:13:48 -07:00
sparse.rst Documentation/sparse: add hints about __CHECKER__ 2022-03-23 19:00:33 -07:00
testing-overview.rst Documentation: dev-tools: Enhance static analysis section with discussion 2022-04-05 09:48:25 -06:00
ubsan.rst Documentation: ubsan: drop "the" from article title 2023-11-01 12:38:35 -07:00