kmemleak.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * include/linux/kmemleak.h
  4. *
  5. * Copyright (C) 2008 ARM Limited
  6. * Written by Catalin Marinas <catalin.marinas@arm.com>
  7. */
  8. #ifndef __KMEMLEAK_H
  9. #define __KMEMLEAK_H
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #ifdef CONFIG_DEBUG_KMEMLEAK
  13. extern void kmemleak_init(void) __init;
  14. extern void kmemleak_alloc(const void *ptr, size_t size, int min_count,
  15. gfp_t gfp) __ref;
  16. extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
  17. gfp_t gfp) __ref;
  18. extern void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
  19. gfp_t gfp) __ref;
  20. extern void kmemleak_free(const void *ptr) __ref;
  21. extern void kmemleak_free_part(const void *ptr, size_t size) __ref;
  22. extern void kmemleak_free_percpu(const void __percpu *ptr) __ref;
  23. extern void kmemleak_update_trace(const void *ptr) __ref;
  24. extern void kmemleak_not_leak(const void *ptr) __ref;
  25. extern void kmemleak_ignore(const void *ptr) __ref;
  26. extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
  27. extern void kmemleak_no_scan(const void *ptr) __ref;
  28. extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count,
  29. gfp_t gfp) __ref;
  30. extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
  31. extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref;
  32. extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
  33. static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
  34. int min_count, slab_flags_t flags,
  35. gfp_t gfp)
  36. {
  37. if (!(flags & SLAB_NOLEAKTRACE))
  38. kmemleak_alloc(ptr, size, min_count, gfp);
  39. }
  40. static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
  41. {
  42. if (!(flags & SLAB_NOLEAKTRACE))
  43. kmemleak_free(ptr);
  44. }
  45. static inline void kmemleak_erase(void **ptr)
  46. {
  47. *ptr = NULL;
  48. }
  49. #else
  50. static inline void kmemleak_init(void)
  51. {
  52. }
  53. static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count,
  54. gfp_t gfp)
  55. {
  56. }
  57. static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
  58. int min_count, slab_flags_t flags,
  59. gfp_t gfp)
  60. {
  61. }
  62. static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
  63. gfp_t gfp)
  64. {
  65. }
  66. static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
  67. gfp_t gfp)
  68. {
  69. }
  70. static inline void kmemleak_free(const void *ptr)
  71. {
  72. }
  73. static inline void kmemleak_free_part(const void *ptr, size_t size)
  74. {
  75. }
  76. static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
  77. {
  78. }
  79. static inline void kmemleak_free_percpu(const void __percpu *ptr)
  80. {
  81. }
  82. static inline void kmemleak_update_trace(const void *ptr)
  83. {
  84. }
  85. static inline void kmemleak_not_leak(const void *ptr)
  86. {
  87. }
  88. static inline void kmemleak_ignore(const void *ptr)
  89. {
  90. }
  91. static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
  92. {
  93. }
  94. static inline void kmemleak_erase(void **ptr)
  95. {
  96. }
  97. static inline void kmemleak_no_scan(const void *ptr)
  98. {
  99. }
  100. static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
  101. int min_count, gfp_t gfp)
  102. {
  103. }
  104. static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
  105. {
  106. }
  107. static inline void kmemleak_not_leak_phys(phys_addr_t phys)
  108. {
  109. }
  110. static inline void kmemleak_ignore_phys(phys_addr_t phys)
  111. {
  112. }
  113. #endif /* CONFIG_DEBUG_KMEMLEAK */
  114. #endif /* __KMEMLEAK_H */