Skip to contentSkip to conversation

kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()

PATCH RESEND In review Richard Fitzgerald 3 participants 3 messages Oct 30, 2023 – Dec 1, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy()

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.

---
 lib/kunit/string-stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/string-stream.c +1 -1
index a6f3616c2048..54f4fdcbfac8 100644
@@ -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);
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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.

Quoted 6 lines

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.

Hello!

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

Thanks!
-Rae

Quoted 20 lines
---
 lib/kunit/string-stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/string-stream.c +1 -2
index a6f3616c2048..54f4fdcbfac8 100644
@@ -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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Richard Fitzgerald
Quoted 7 lines · 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.

Quoted 7 lines

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.

---

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

Cheers,
-- David