xref: /openbmc/linux/include/linux/kmemleak.h (revision e15a5365)
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 
9 #ifndef __KMEMLEAK_H
10 #define __KMEMLEAK_H
11 
12 #include <linux/slab.h>
13 #include <linux/vmalloc.h>
14 
15 #ifdef CONFIG_DEBUG_KMEMLEAK
16 
17 extern void kmemleak_init(void) __init;
18 extern void kmemleak_alloc(const void *ptr, size_t size, int min_count,
19 			   gfp_t gfp) __ref;
20 extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
21 				  gfp_t gfp) __ref;
22 extern void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
23 			     gfp_t gfp) __ref;
24 extern void kmemleak_free(const void *ptr) __ref;
25 extern void kmemleak_free_part(const void *ptr, size_t size) __ref;
26 extern void kmemleak_free_percpu(const void __percpu *ptr) __ref;
27 extern void kmemleak_update_trace(const void *ptr) __ref;
28 extern void kmemleak_not_leak(const void *ptr) __ref;
29 extern void kmemleak_ignore(const void *ptr) __ref;
30 extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
31 extern void kmemleak_no_scan(const void *ptr) __ref;
32 extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count,
33 				gfp_t gfp) __ref;
34 extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
35 extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref;
36 extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
37 
38 static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
39 					    int min_count, slab_flags_t flags,
40 					    gfp_t gfp)
41 {
42 	if (!(flags & SLAB_NOLEAKTRACE))
43 		kmemleak_alloc(ptr, size, min_count, gfp);
44 }
45 
46 static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
47 {
48 	if (!(flags & SLAB_NOLEAKTRACE))
49 		kmemleak_free(ptr);
50 }
51 
52 static inline void kmemleak_erase(void **ptr)
53 {
54 	*ptr = NULL;
55 }
56 
57 #else
58 
59 static inline void kmemleak_init(void)
60 {
61 }
62 static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count,
63 				  gfp_t gfp)
64 {
65 }
66 static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
67 					    int min_count, slab_flags_t flags,
68 					    gfp_t gfp)
69 {
70 }
71 static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
72 					 gfp_t gfp)
73 {
74 }
75 static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
76 				    gfp_t gfp)
77 {
78 }
79 static inline void kmemleak_free(const void *ptr)
80 {
81 }
82 static inline void kmemleak_free_part(const void *ptr, size_t size)
83 {
84 }
85 static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
86 {
87 }
88 static inline void kmemleak_free_percpu(const void __percpu *ptr)
89 {
90 }
91 static inline void kmemleak_update_trace(const void *ptr)
92 {
93 }
94 static inline void kmemleak_not_leak(const void *ptr)
95 {
96 }
97 static inline void kmemleak_ignore(const void *ptr)
98 {
99 }
100 static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
101 {
102 }
103 static inline void kmemleak_erase(void **ptr)
104 {
105 }
106 static inline void kmemleak_no_scan(const void *ptr)
107 {
108 }
109 static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
110 				       int min_count, gfp_t gfp)
111 {
112 }
113 static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
114 {
115 }
116 static inline void kmemleak_not_leak_phys(phys_addr_t phys)
117 {
118 }
119 static inline void kmemleak_ignore_phys(phys_addr_t phys)
120 {
121 }
122 
123 #endif	/* CONFIG_DEBUG_KMEMLEAK */
124 
125 #endif	/* __KMEMLEAK_H */
126