Debian Codegraph @

llvm-project/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst

raw
1 .. title:: clang-tidy - linuxkernel-must-use-errs
2
3 linuxkernel-must-use-errs
4 =========================
5
6 Checks Linux kernel code to see if it uses the results from the functions in
7 ``linux/err.h``. Also checks to see if code uses the results from functions that
8 directly return a value from one of these error functions.
9
10 This 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`` return
12 values must be checked, since positive pointers and negative error codes are
13 being used in the same context. These functions are marked with
14 ``__attribute__((warn_unused_result))``, but some kernel versions do not have
15 this warning enabled for clang.
16
17 Examples:
18
19 .. code-block:: c
20
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();