Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

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>

authored by

Richard Fitzgerald and committed by
Shuah Khan
15bf0000 37f0d37f

+1 -1
+1 -1
lib/kunit/string-stream.c
··· 173 173 { 174 174 KUNIT_STATIC_STUB_REDIRECT(string_stream_destroy, stream); 175 175 176 - if (!stream) 176 + if (IS_ERR_OR_NULL(stream)) 177 177 return; 178 178 179 179 string_stream_clear(stream);