29 lines · plain
1.. title:: clang-tidy - linuxkernel-must-check-errs2 3linuxkernel-must-check-errs4===========================5 6Checks Linux kernel code to see if it uses the results from the functions in7``linux/err.h``. Also checks to see if code uses the results from functions8that directly return a value from one of these error functions.9 10This is important in the Linux kernel because ``ERR_PTR``, ``PTR_ERR``,11``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and ``PTR_ERR_OR_ZERO`` return12values must be checked, since positive pointers and negative error codes are13being used in the same context. These functions are marked with14``__attribute__((warn_unused_result))``, but some kernel versions do not have15this warning enabled for clang.16 17Examples:18 19.. code-block:: c20 21 /* Trivial unused call to an ERR function */22 PTR_ERR_OR_ZERO(some_function_call());23 24 /* A function that returns ERR_PTR. */25 void *fn() { ERR_PTR(-EINVAL); }26 27 /* An invalid use of fn. */28 fn();29