Skip to contentSkip to conversation

kunit: debugfs: Use IS_ERR() for alloc_string_stream() error check

PATCH In review Kuan-Wei Chiu 2 participants 2 messages Nov 14, 2024 – Nov 15, 2024

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

PATCH 1/1 kunit: debugfs: Use IS_ERR() for alloc_string_stream() error check

The alloc_string_stream() function only returns ERR_PTR(-ENOMEM) on failure and never returns NULL. Therefore, switching the error check in the caller from IS_ERR_OR_NULL to IS_ERR improves clarity, indicating that this function will return an error pointer (not NULL) when an error occurs. This change avoids any ambiguity regarding the function's return behavior.

---
 lib/kunit/debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/kunit/debugfs.c +2 -2
index d548750a325a..6273fa9652df 100644
@@ -181,7 +181,7 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
 	 * successfully.
 	 */
 	stream = alloc_string_stream(GFP_KERNEL);
-	if (IS_ERR_OR_NULL(stream))
+	if (IS_ERR(stream))
 		return;
 
 	string_stream_set_append_newlines(stream, true);
@@ -189,7 +189,7 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
 
 	kunit_suite_for_each_test_case(suite, test_case) {
 		stream = alloc_string_stream(GFP_KERNEL);
-		if (IS_ERR_OR_NULL(stream))
+		if (IS_ERR(stream))
 			goto err;
 
 		string_stream_set_append_newlines(stream, true);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Kuan-Wei Chiu

The alloc_string_stream() function only returns ERR_PTR(-ENOMEM) on failure and never returns NULL. Therefore, switching the error check in the caller from IS_ERR_OR_NULL to IS_ERR improves clarity, indicating that this function will return an error pointer (not NULL) when an error occurs. This change avoids any ambiguity regarding the function's return behavior.

--

Makes sense to me, thanks.

Cheers,
-- David

Quoted 28 lines
 lib/kunit/debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/kunit/debugfs.c +2 -3
index d548750a325a..6273fa9652df 100644
@@ -181,7 +181,7 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
         * successfully.
         */
        stream = alloc_string_stream(GFP_KERNEL);
-       if (IS_ERR_OR_NULL(stream))
+       if (IS_ERR(stream))
                return;
 
        string_stream_set_append_newlines(stream, true);
@@ -189,7 +189,7 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
 
        kunit_suite_for_each_test_case(suite, test_case) {
                stream = alloc_string_stream(GFP_KERNEL);
-               if (IS_ERR_OR_NULL(stream))
+               if (IS_ERR(stream))
                        goto err;
 
                string_stream_set_append_newlines(stream, true);
--

2.34.1