kunit: test: Avoid cast warning when adding kfree() as an action
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Mon, 6 Nov 2023 17:25:57 +0000 (17:25 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 14 Nov 2023 20:01:57 +0000 (13:01 -0700)
In kunit_log_test() pass the kfree_wrapper() function to kunit_add_action()
instead of directly passing kfree().

This prevents a cast warning:

lib/kunit/kunit-test.c:565:25: warning: cast from 'void (*)(const void *)'
to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible
function type [-Wcast-function-type-strict]

   564 full_log = string_stream_get_string(test->log);
 > 565 kunit_add_action(test, (kunit_action_t *)kfree, full_log);

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311070041.kWVYx7YP-lkp@intel.com/
Fixes: 05e2006ce493 ("kunit: Use string_stream for test log")
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/kunit-test.c

index 99d2a3a528e1ed31f118fb1ec799ce197f42fb1d..de2113a58fa034f4da20e4ee2b9734c3092b1017 100644 (file)
@@ -562,7 +562,7 @@ static void kunit_log_test(struct kunit *test)
        KUNIT_EXPECT_TRUE(test, test->log->append_newlines);
 
        full_log = string_stream_get_string(test->log);
-       kunit_add_action(test, (kunit_action_t *)kfree, full_log);
+       kunit_add_action(test, kfree_wrapper, full_log);
        KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
                                     strstr(full_log, "put this in log."));
        KUNIT_EXPECT_NOT_ERR_OR_NULL(test,