MustCheckErrsCheck.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //===--- MustCheckErrsCheck.h - clang-tidy ----------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MUSTCHECKERRSCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MUSTCHECKERRSCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::linuxkernel {
  12. /// Checks Linux kernel code to see if it uses the results from the functions in
  13. /// linux/err.h. Also checks to see if code uses the results from functions that
  14. /// directly return a value from one of these error functions.
  15. ///
  16. /// This is important in the Linux kernel because ERR_PTR, PTR_ERR, IS_ERR,
  17. /// IS_ERR_OR_NULL, ERR_CAST, and PTR_ERR_OR_ZERO return values must be checked,
  18. /// since positive pointers and negative error codes are being used in the same
  19. /// context. These functions are marked with
  20. /// __attribute__((warn_unused_result)), but some kernel versions do not have
  21. /// this warning enabled for clang.
  22. ///
  23. /// For the user-facing documentation see:
  24. /// http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-use-errs.html
  25. class MustCheckErrsCheck : public ClangTidyCheck {
  26. public:
  27. MustCheckErrsCheck(StringRef Name, ClangTidyContext *Context)
  28. : ClangTidyCheck(Name, Context) {}
  29. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  30. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  31. };
  32. } // namespace clang::tidy::linuxkernel
  33. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LINUXKERNEL_MUSTCHECKERRSCHECK_H