As you note, these IS_ERR() calls are totally redundant. So there's a
fair argument that this is a bug (albeit a harmless one) in the test,
which smatch has successfully caught.
That being said, I could definitely see there being situations where
this sort of check would result in a false positive with KUnit tests,
particularly if the function being tested checks its arguments.
>
> 109 return;
> 110
>
> No one runs kunit on production systems so I think just disabling
> Smatch for these functions is okay.
>
While "no one runs KUnit on production systems" may prove slightly
optimistic (there are definitely quite a few people who _build_ with
KUnit enabled on production systems, though they go to some effort to
not actually run it), I think this is probably an appropriate
tradeoff. Certainly, I think it makes sense to disable this IS_ERR
warning, and anything similar.
I suspect most of the problems we'd encounter are with the
KUNIT_ASSERT_* macros, given those are the only ones which trigger
serious control-flow changes. We do also have the kunit_add_action()
API now[1], which allows cleanup to be more easily scheduled to occur
when a test exits. I don't know if that's also likely to trip smatch
up...
Either way, I'm not too worried about disabling smatch in these cases
where false positives are likely: we're pretty careful to do things
like taint the kernel when tests are run, so that should keep people
from doing anything too silly in production (or at least warn them).
Cheers,
-- David
[1]:
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=kunit&id=b9dce8a1ed3efe0f5c0957f4605140f204226a0f