[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABVgOSmtD3GRV3hDoMw9EgMG4DPFWWK1SEDJT_yGDs7-CnwveA@mail.gmail.com>
Date: Sun, 30 Oct 2022 11:20:32 +0800
From: David Gow <davidgow@...gle.com>
To: "YoungJun.park" <her0gyugyu@...il.com>
Cc: Brendan Higgins <brendan.higgins@...ux.dev>,
linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] kunit: alloc_string_stream_fragment error handling bug fix
On Fri, Oct 28, 2022 at 10:43 PM YoungJun.park <her0gyugyu@...il.com> wrote:
>
> When it fails to allocate fragment, it does not free and return error.
> And check the pointer inappropriately.
>
> Signed-off-by: YoungJun.park <her0gyugyu@...il.com>
> ---
Thanks! As MaĆra points out, the added kunit_kfree() call isn't
strictly necessary, though it definitely doesn't hurt (and it's
probably a nice thing to free memory early if we're already in a
pretty dire memory situation). So I think it's an improvement.
The IS_ERR check is definitely a fix, though.
Reviewed-by: David Gow <davidgow@...gle.com>
Cheers,
-- David
> 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
>
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@...glegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20221028144241.634012-1-her0gyugyu%40gmail.com.
Download attachment "smime.p7s" of type "application/pkcs7-signature" (4003 bytes)
Powered by blists - more mailing lists