Skip to contentSkip to conversation

kunit: test: Avoid cast warning when adding kfree() as an action

PATCH In review Richard Fitzgerald 2 participants 2 messages Nov 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kunit: test: Avoid cast warning when adding kfree() as an action

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);

Quoted 1 line

565 kunit_add_action(test, (kunit_action_t *)kfree, full_log);

---
 lib/kunit/kunit-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/kunit-test.c +1 -1
index 99d2a3a528e1..de2113a58fa0 100644
@@ -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,
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Richard Fitzgerald

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]

Quoted 8 lines
   564          full_log = string_stream_get_string(test->log);
Quoted 1 line

565 kunit_add_action(test, (kunit_action_t *)kfree, full_log);

---

Looks good to me, thanks!

Cheers,
-- David