Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "YoungJun.park" <her0gyugyu@gmail.com>
To: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org,
	"YoungJun.park" <her0gyugyu@gmail.com>
Subject: [PATCH] kunit: alloc_string_stream_fragment error handling bug fix
Date: Fri, 28 Oct 2022 07:42:41 -0700	[thread overview]
Message-ID: <20221028144241.634012-1-her0gyugyu@gmail.com> (raw)

When it fails to allocate fragment, it does not free and return error.
And check the pointer inappropriately.

Signed-off-by: YoungJun.park <her0gyugyu@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


             reply	other threads:[~2022-10-28 14:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 14:42 YoungJun.park [this message]
2022-10-29 10:35 ` [PATCH] kunit: alloc_string_stream_fragment error handling bug fix Maíra Canal
2022-10-30  3:20 ` David Gow
2022-10-31 20:47   ` Daniel Latypov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221028144241.634012-1-her0gyugyu@gmail.com \
    --to=her0gyugyu@gmail.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox