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

Configure Feed

Select the types of activity you want to include in your feed.

kunit: Protect KUNIT_BINARY_STR_ASSERTION against ERR_PTR values

Replace the NULL checks with IS_ERR_OR_NULL() in
KUNIT_BINARY_STR_ASSERTION() to prevent the strcmp() faulting if a
passed pointer is an ERR_PTR.

Commit 7ece381aa72d4 ("kunit: Protect string comparisons against NULL")
added the checks for NULL on both pointers so that asserts would fail,
instead of faulting, if either pointer is NULL. But either pointer
could hold an ERR_PTR value.

This assumes that the assertion is expecting both strings to be valid,
and is asserting the equality of their _content_.

Link: https://lore.kernel.org/r/20251219161212.1648076-1-rf@opensource.cirrus.com
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.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
a7a81655 90b5f2dc

+2 -1
+2 -1
include/kunit/test.h
··· 906 906 }; \ 907 907 \ 908 908 _KUNIT_SAVE_LOC(test); \ 909 - if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \ 909 + if (likely(!IS_ERR_OR_NULL(__left) && !IS_ERR_OR_NULL(__right) && \ 910 + (strcmp(__left, __right) op 0))) \ 910 911 break; \ 911 912 \ 912 913 \