YoungJun.park
unread,Oct 28, 2022, 10:43:10 AM10/28/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Brendan Higgins, David Gow, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, YoungJun.park
When it fails to allocate fragment, it does not free and return error.
And check the pointer inappropriately.
Signed-off-by: YoungJun.park <
her0g...@gmail.com>
---
lib/kunit/string-stream.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c
index 72659a9773e3..0228fe814e96 100644
--- a/lib/kunit/string-stream.c
+++ b/lib/kunit/string-stream.c
@@ -23,8 +23,10 @@ static struct string_stream_fragment *alloc_string_stream_fragment(
return ERR_PTR(-ENOMEM);
frag->fragment = kunit_kmalloc(test, len, gfp);
- if (!frag->fragment)
+ if (!frag->fragment) {
+ kunit_kfree(test, frag);
return ERR_PTR(-ENOMEM);
+ }
return frag;
}
@@ -56,7 +58,7 @@ int string_stream_vadd(struct string_stream *stream,
frag_container = alloc_string_stream_fragment(stream->test,
len,
stream->gfp);
- if (!frag_container)
+ if (IS_ERR(frag_container))
return -ENOMEM;
len = vsnprintf(frag_container->fragment, len, fmt, args);
--
2.25.1