Skip to content

Commit

Permalink
kunit: string-stream: Allow ERR_PTR to be passed to string_stream_des…
Browse files Browse the repository at this point in the history
…troy()

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>
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Richard Fitzgerald authored and Shuah Khan committed Dec 18, 2023
1 parent 37f0d37 commit 15bf000
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kunit/string-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 15bf000

Please sign in to comment.