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