kmemleak.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <[email protected]>
  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,
  29. gfp_t gfp) __ref;
  30. extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
  31. extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
  32. static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
  33. int min_count, slab_flags_t flags,
  34. gfp_t gfp)
  35. {
  36. if (!(flags & SLAB_NOLEAKTRACE))
  37. kmemleak_alloc(ptr, size, min_count, gfp);
  38. }
  39. static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
  40. {
  41. if (!(flags & SLAB_NOLEAKTRACE))
  42. kmemleak_free(ptr);
  43. }
  44. static inline void kmemleak_erase(void **ptr)
  45. {
  46. *ptr = NULL;
  47. }
  48. #else
  49. static inline void kmemleak_init(void)
  50. {
  51. }
  52. static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count,
  53. gfp_t gfp)
  54. {
  55. }
  56. static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
  57. int min_count, slab_flags_t flags,
  58. gfp_t gfp)
  59. {
  60. }
  61. static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
  62. gfp_t gfp)
  63. {
  64. }
  65. static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
  66. gfp_t gfp)
  67. {
  68. }
  69. static inline void kmemleak_free(const void *ptr)
  70. {
  71. }
  72. static inline void kmemleak_free_part(const void *ptr, size_t size)
  73. {
  74. }
  75. static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
  76. {
  77. }
  78. static inline void kmemleak_free_percpu(const void __percpu *ptr)
  79. {
  80. }
  81. static inline void kmemleak_update_trace(const void *ptr)
  82. {
  83. }
  84. static inline void kmemleak_not_leak(const void *ptr)
  85. {
  86. }
  87. static inline void kmemleak_ignore(const void *ptr)
  88. {
  89. }
  90. static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
  91. {
  92. }
  93. static inline void kmemleak_erase(void **ptr)
  94. {
  95. }
  96. static inline void kmemleak_no_scan(const void *ptr)
  97. {
  98. }
  99. static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
  100. gfp_t gfp)
  101. {
  102. }
  103. static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
  104. {
  105. }
  106. static inline void kmemleak_ignore_phys(phys_addr_t phys)
  107. {
  108. }
  109. #endif /* CONFIG_DEBUG_KMEMLEAK */
  110. #endif /* __KMEMLEAK_H */