xref: /openbmc/linux/include/linux/kmemleak.h (revision c200d900)
145051539SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
23c7b4e6bSCatalin Marinas /*
33c7b4e6bSCatalin Marinas  * include/linux/kmemleak.h
43c7b4e6bSCatalin Marinas  *
53c7b4e6bSCatalin Marinas  * Copyright (C) 2008 ARM Limited
63c7b4e6bSCatalin Marinas  * Written by Catalin Marinas <catalin.marinas@arm.com>
73c7b4e6bSCatalin Marinas  */
83c7b4e6bSCatalin Marinas 
93c7b4e6bSCatalin Marinas #ifndef __KMEMLEAK_H
103c7b4e6bSCatalin Marinas #define __KMEMLEAK_H
113c7b4e6bSCatalin Marinas 
1266f2ca7eSAndrew Morton #include <linux/slab.h>
1394f4a161SCatalin Marinas #include <linux/vmalloc.h>
1466f2ca7eSAndrew Morton 
153c7b4e6bSCatalin Marinas #ifdef CONFIG_DEBUG_KMEMLEAK
163c7b4e6bSCatalin Marinas 
1798e89cf0SNicolas Iooss extern void kmemleak_init(void) __init;
183c7b4e6bSCatalin Marinas extern void kmemleak_alloc(const void *ptr, size_t size, int min_count,
19a6186d89SCatalin Marinas 			   gfp_t gfp) __ref;
208a8c35faSLarry Finger extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
218a8c35faSLarry Finger 				  gfp_t gfp) __ref;
2294f4a161SCatalin Marinas extern void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
2394f4a161SCatalin Marinas 			     gfp_t gfp) __ref;
24a6186d89SCatalin Marinas extern void kmemleak_free(const void *ptr) __ref;
25a6186d89SCatalin Marinas extern void kmemleak_free_part(const void *ptr, size_t size) __ref;
26f528f0b8SCatalin Marinas extern void kmemleak_free_percpu(const void __percpu *ptr) __ref;
27ffe2c748SCatalin Marinas extern void kmemleak_update_trace(const void *ptr) __ref;
28a6186d89SCatalin Marinas extern void kmemleak_not_leak(const void *ptr) __ref;
29a6186d89SCatalin Marinas extern void kmemleak_ignore(const void *ptr) __ref;
30c017b4beSCatalin Marinas extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
31a6186d89SCatalin Marinas extern void kmemleak_no_scan(const void *ptr) __ref;
32*c200d900SPatrick Wang extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
339099daedSCatalin Marinas 				gfp_t gfp) __ref;
349099daedSCatalin Marinas extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
359099daedSCatalin Marinas extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
363c7b4e6bSCatalin Marinas 
kmemleak_alloc_recursive(const void * ptr,size_t size,int min_count,slab_flags_t flags,gfp_t gfp)373c7b4e6bSCatalin Marinas static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
38d50112edSAlexey Dobriyan 					    int min_count, slab_flags_t flags,
393c7b4e6bSCatalin Marinas 					    gfp_t gfp)
403c7b4e6bSCatalin Marinas {
413c7b4e6bSCatalin Marinas 	if (!(flags & SLAB_NOLEAKTRACE))
423c7b4e6bSCatalin Marinas 		kmemleak_alloc(ptr, size, min_count, gfp);
433c7b4e6bSCatalin Marinas }
443c7b4e6bSCatalin Marinas 
kmemleak_free_recursive(const void * ptr,slab_flags_t flags)45d50112edSAlexey Dobriyan static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
463c7b4e6bSCatalin Marinas {
473c7b4e6bSCatalin Marinas 	if (!(flags & SLAB_NOLEAKTRACE))
483c7b4e6bSCatalin Marinas 		kmemleak_free(ptr);
493c7b4e6bSCatalin Marinas }
503c7b4e6bSCatalin Marinas 
kmemleak_erase(void ** ptr)513c7b4e6bSCatalin Marinas static inline void kmemleak_erase(void **ptr)
523c7b4e6bSCatalin Marinas {
533c7b4e6bSCatalin Marinas 	*ptr = NULL;
543c7b4e6bSCatalin Marinas }
553c7b4e6bSCatalin Marinas 
563c7b4e6bSCatalin Marinas #else
573c7b4e6bSCatalin Marinas 
kmemleak_init(void)583c7b4e6bSCatalin Marinas static inline void kmemleak_init(void)
593c7b4e6bSCatalin Marinas {
603c7b4e6bSCatalin Marinas }
kmemleak_alloc(const void * ptr,size_t size,int min_count,gfp_t gfp)613c7b4e6bSCatalin Marinas static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count,
623c7b4e6bSCatalin Marinas 				  gfp_t gfp)
633c7b4e6bSCatalin Marinas {
643c7b4e6bSCatalin Marinas }
kmemleak_alloc_recursive(const void * ptr,size_t size,int min_count,slab_flags_t flags,gfp_t gfp)653c7b4e6bSCatalin Marinas static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
66d50112edSAlexey Dobriyan 					    int min_count, slab_flags_t flags,
673c7b4e6bSCatalin Marinas 					    gfp_t gfp)
683c7b4e6bSCatalin Marinas {
693c7b4e6bSCatalin Marinas }
kmemleak_alloc_percpu(const void __percpu * ptr,size_t size,gfp_t gfp)708a8c35faSLarry Finger static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
718a8c35faSLarry Finger 					 gfp_t gfp)
72f528f0b8SCatalin Marinas {
73f528f0b8SCatalin Marinas }
kmemleak_vmalloc(const struct vm_struct * area,size_t size,gfp_t gfp)7494f4a161SCatalin Marinas static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
7594f4a161SCatalin Marinas 				    gfp_t gfp)
7694f4a161SCatalin Marinas {
7794f4a161SCatalin Marinas }
kmemleak_free(const void * ptr)783c7b4e6bSCatalin Marinas static inline void kmemleak_free(const void *ptr)
793c7b4e6bSCatalin Marinas {
803c7b4e6bSCatalin Marinas }
kmemleak_free_part(const void * ptr,size_t size)8153238a60SCatalin Marinas static inline void kmemleak_free_part(const void *ptr, size_t size)
8253238a60SCatalin Marinas {
8353238a60SCatalin Marinas }
kmemleak_free_recursive(const void * ptr,slab_flags_t flags)84d50112edSAlexey Dobriyan static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
853c7b4e6bSCatalin Marinas {
863c7b4e6bSCatalin Marinas }
kmemleak_free_percpu(const void __percpu * ptr)87f528f0b8SCatalin Marinas static inline void kmemleak_free_percpu(const void __percpu *ptr)
88f528f0b8SCatalin Marinas {
89f528f0b8SCatalin Marinas }
kmemleak_update_trace(const void * ptr)90ffe2c748SCatalin Marinas static inline void kmemleak_update_trace(const void *ptr)
91ffe2c748SCatalin Marinas {
92ffe2c748SCatalin Marinas }
kmemleak_not_leak(const void * ptr)933c7b4e6bSCatalin Marinas static inline void kmemleak_not_leak(const void *ptr)
943c7b4e6bSCatalin Marinas {
953c7b4e6bSCatalin Marinas }
kmemleak_ignore(const void * ptr)963c7b4e6bSCatalin Marinas static inline void kmemleak_ignore(const void *ptr)
973c7b4e6bSCatalin Marinas {
983c7b4e6bSCatalin Marinas }
kmemleak_scan_area(const void * ptr,size_t size,gfp_t gfp)99c017b4beSCatalin Marinas static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
1003c7b4e6bSCatalin Marinas {
1013c7b4e6bSCatalin Marinas }
kmemleak_erase(void ** ptr)1023c7b4e6bSCatalin Marinas static inline void kmemleak_erase(void **ptr)
1033c7b4e6bSCatalin Marinas {
1043c7b4e6bSCatalin Marinas }
kmemleak_no_scan(const void * ptr)1053c7b4e6bSCatalin Marinas static inline void kmemleak_no_scan(const void *ptr)
1063c7b4e6bSCatalin Marinas {
1073c7b4e6bSCatalin Marinas }
kmemleak_alloc_phys(phys_addr_t phys,size_t size,gfp_t gfp)1089099daedSCatalin Marinas static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
109*c200d900SPatrick Wang 				       gfp_t gfp)
1109099daedSCatalin Marinas {
1119099daedSCatalin Marinas }
kmemleak_free_part_phys(phys_addr_t phys,size_t size)1129099daedSCatalin Marinas static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
1139099daedSCatalin Marinas {
1149099daedSCatalin Marinas }
kmemleak_ignore_phys(phys_addr_t phys)1159099daedSCatalin Marinas static inline void kmemleak_ignore_phys(phys_addr_t phys)
1169099daedSCatalin Marinas {
1179099daedSCatalin Marinas }
1183c7b4e6bSCatalin Marinas 
1193c7b4e6bSCatalin Marinas #endif	/* CONFIG_DEBUG_KMEMLEAK */
1203c7b4e6bSCatalin Marinas 
1213c7b4e6bSCatalin Marinas #endif	/* __KMEMLEAK_H */
122