public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()
@ 2023-10-30 10:47 Richard Fitzgerald
  2023-11-30 20:51 ` Rae Moar
  2023-12-01  3:34 ` David Gow
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2023-10-30 10:47 UTC (permalink / raw)
  To: brendan.higgins, davidgow, rmoar
  Cc: linux-kselftest, kunit-dev, linux-kernel, patches,
	Richard Fitzgerald

Check the stream pointer passed to string_stream_destroy() for
IS_ERR_OR_NULL() instead of only NULL.

Whatever alloc_string_stream() returns should be safe to pass
to string_stream_destroy(), and that will be an ERR_PTR.

It's obviously good practise and generally helpful to also check
for NULL pointers so that client cleanup code can call
string_stream_destroy() unconditionally - which could include
pointers that have never been set to anything and so are NULL.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 lib/kunit/string-stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c
index a6f3616c2048..54f4fdcbfac8 100644
--- a/lib/kunit/string-stream.c
+++ b/lib/kunit/string-stream.c
@@ -173,7 +173,7 @@ void string_stream_destroy(struct string_stream *stream)
 {
 	KUNIT_STATIC_STUB_REDIRECT(string_stream_destroy, stream);
 
-	if (!stream)
+	if (IS_ERR_OR_NULL(stream))
 		return;
 
 	string_stream_clear(stream);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()
  2023-10-30 10:47 [PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy() Richard Fitzgerald
@ 2023-11-30 20:51 ` Rae Moar
  2023-12-01  3:34 ` David Gow
  1 sibling, 0 replies; 3+ messages in thread
From: Rae Moar @ 2023-11-30 20:51 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: brendan.higgins, davidgow, linux-kselftest, kunit-dev,
	linux-kernel, patches

On Mon, Oct 30, 2023 at 6:47 AM Richard Fitzgerald
<rf@opensource.cirrus.com> wrote:
>
> Check the stream pointer passed to string_stream_destroy() for
> IS_ERR_OR_NULL() instead of only NULL.
>
> Whatever alloc_string_stream() returns should be safe to pass
> to string_stream_destroy(), and that will be an ERR_PTR.
>
> It's obviously good practise and generally helpful to also check
> for NULL pointers so that client cleanup code can call
> string_stream_destroy() unconditionally - which could include
> pointers that have never been set to anything and so are NULL.
>
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>

Hello!

Sorry for the delay in reviewing this patch but this looks good to me!

Reviewed-by: Rae Moar <rmoar@google.com>

Thanks!
-Rae

> ---
>  lib/kunit/string-stream.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c
> index a6f3616c2048..54f4fdcbfac8 100644
> --- a/lib/kunit/string-stream.c
> +++ b/lib/kunit/string-stream.c
> @@ -173,7 +173,7 @@ void string_stream_destroy(struct string_stream *stream)
>  {
>         KUNIT_STATIC_STUB_REDIRECT(string_stream_destroy, stream);
>
> -       if (!stream)
> +       if (IS_ERR_OR_NULL(stream))
>                 return;
>
>         string_stream_clear(stream);
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()
  2023-10-30 10:47 [PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy() Richard Fitzgerald
  2023-11-30 20:51 ` Rae Moar
@ 2023-12-01  3:34 ` David Gow
  1 sibling, 0 replies; 3+ messages in thread
From: David Gow @ 2023-12-01  3:34 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: brendan.higgins, rmoar, linux-kselftest, kunit-dev, linux-kernel,
	patches

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

On Mon, 30 Oct 2023 at 18:47, Richard Fitzgerald
<rf@opensource.cirrus.com> wrote:
>
> Check the stream pointer passed to string_stream_destroy() for
> IS_ERR_OR_NULL() instead of only NULL.
>
> Whatever alloc_string_stream() returns should be safe to pass
> to string_stream_destroy(), and that will be an ERR_PTR.
>
> It's obviously good practise and generally helpful to also check
> for NULL pointers so that client cleanup code can call
> string_stream_destroy() unconditionally - which could include
> pointers that have never been set to anything and so are NULL.
>
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> ---

Yeah, this makes sense, and let's support NULL as well.

Reviewed-by: David Gow <davidgow@google.com>

Cheers,
-- David

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4003 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-01  3:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30 10:47 [PATCH RESEND] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy() Richard Fitzgerald
2023-11-30 20:51 ` Rae Moar
2023-12-01  3:34 ` David Gow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox