Skip to contentSkip to conversation

kunit: string-stream-test: use KUNIT_DEFINE_ACTION_WRAPPER

PATCH In review Ivan Orlov 3 participants 3 messages Apr 23, 2024 – Apr 24, 2024

Subsystems (2)
lore
Share & tools
lore

Ivan Orlov

author
#0 lore raw

PATCH 1/1 kunit: string-stream-test: use KUNIT_DEFINE_ACTION_WRAPPER

Use KUNIT_DEFINE_ACTION_WRAPPER macro to define the 'kfree' and 'string_stream_destroy' wrappers for kunit_add_action.

---
 lib/kunit/string-stream-test.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
lib/kunit/string-stream-test.c +2 -10
index 03fb511826f7..7511442ea98f 100644
@@ -22,18 +22,10 @@ struct string_stream_test_priv {
 };
 
 /* Avoids a cast warning if kfree() is passed direct to kunit_add_action(). */
-static void kfree_wrapper(void *p)
-{
-	kfree(p);
-}
+KUNIT_DEFINE_ACTION_WRAPPER(kfree_wrapper, kfree, const void *);
 
 /* Avoids a cast warning if string_stream_destroy() is passed direct to kunit_add_action(). */
-static void cleanup_raw_stream(void *p)
-{
-	struct string_stream *stream = p;
-
-	string_stream_destroy(stream);
-}
+KUNIT_DEFINE_ACTION_WRAPPER(cleanup_raw_stream, string_stream_destroy, struct string_stream *);
 
 static char *get_concatenated_string(struct kunit *test, struct string_stream *stream)
 {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Ivan Orlov

Use KUNIT_DEFINE_ACTION_WRAPPER macro to define the 'kfree' and 'string_stream_destroy' wrappers for kunit_add_action.

Hello!

This looks like a good use of the macro. Thanks!

Thanks!
-Rae

Quoted 32 lines
---
 lib/kunit/string-stream-test.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
lib/kunit/string-stream-test.c +2 -11
index 03fb511826f7..7511442ea98f 100644
@@ -22,18 +22,10 @@ struct string_stream_test_priv {
 };
 
 /* Avoids a cast warning if kfree() is passed direct to kunit_add_action(). */
-static void kfree_wrapper(void *p)
-{
-       kfree(p);
-}
+KUNIT_DEFINE_ACTION_WRAPPER(kfree_wrapper, kfree, const void *);
 
 /* Avoids a cast warning if string_stream_destroy() is passed direct to kunit_add_action(). */
-static void cleanup_raw_stream(void *p)
-{
-       struct string_stream *stream = p;
-
-       string_stream_destroy(stream);
-}
+KUNIT_DEFINE_ACTION_WRAPPER(cleanup_raw_stream, string_stream_destroy, struct string_stream *);
 
 static char *get_concatenated_string(struct kunit *test, struct string_stream *stream)
 {
--

2.34.1