xref: /openbmc/linux/include/linux/kmemleak.h (revision d50112ed)
13c7b4e6bSCatalin Marinas /*
23c7b4e6bSCatalin Marinas  * include/linux/kmemleak.h
33c7b4e6bSCatalin Marinas  *
43c7b4e6bSCatalin Marinas  * Copyright (C) 2008 ARM Limited
53c7b4e6bSCatalin Marinas  * Written by Catalin Marinas <catalin.marinas@arm.com>
63c7b4e6bSCatalin Marinas  *
73c7b4e6bSCatalin Marinas  * This program is free software; you can redistribute it and/or modify
83c7b4e6bSCatalin Marinas  * it under the terms of the GNU General Public License version 2 as
93c7b4e6bSCatalin Marinas  * published by the Free Software Foundation.
103c7b4e6bSCatalin Marinas  *
113c7b4e6bSCatalin Marinas  * This program is distributed in the hope that it will be useful,
123c7b4e6bSCatalin Marinas  * but WITHOUT ANY WARRANTY; without even the implied warranty of
133c7b4e6bSCatalin Marinas  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
143c7b4e6bSCatalin Marinas  * GNU General Public License for more details.
153c7b4e6bSCatalin Marinas  *
163c7b4e6bSCatalin Marinas  * You should have received a copy of the GNU General Public License
173c7b4e6bSCatalin Marinas  * along with this program; if not, write to the Free Software
183c7b4e6bSCatalin Marinas  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
193c7b4e6bSCatalin Marinas  */
203c7b4e6bSCatalin Marinas 
213c7b4e6bSCatalin Marinas #ifndef __KMEMLEAK_H
223c7b4e6bSCatalin Marinas #define __KMEMLEAK_H
233c7b4e6bSCatalin Marinas 
2466f2ca7eSAndrew Morton #include <linux/slab.h>
2594f4a161SCatalin Marinas #include <linux/vmalloc.h>
2666f2ca7eSAndrew Morton 
273c7b4e6bSCatalin Marinas #ifdef CONFIG_DEBUG_KMEMLEAK
283c7b4e6bSCatalin Marinas 
2998e89cf0SNicolas Iooss extern void kmemleak_init(void) __init;
303c7b4e6bSCatalin Marinas extern void kmemleak_alloc(const void *ptr, size_t size, int min_count,
31a6186d89SCatalin Marinas 			   gfp_t gfp) __ref;
328a8c35faSLarry Finger extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
338a8c35faSLarry Finger 				  gfp_t gfp) __ref;
3494f4a161SCatalin Marinas extern void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
3594f4a161SCatalin Marinas 			     gfp_t gfp) __ref;
36a6186d89SCatalin Marinas extern void kmemleak_free(const void *ptr) __ref;
37a6186d89SCatalin Marinas extern void kmemleak_free_part(const void *ptr, size_t size) __ref;
38f528f0b8SCatalin Marinas extern void kmemleak_free_percpu(const void __percpu *ptr) __ref;
39ffe2c748SCatalin Marinas extern void kmemleak_update_trace(const void *ptr) __ref;
40a6186d89SCatalin Marinas extern void kmemleak_not_leak(const void *ptr) __ref;
41a6186d89SCatalin Marinas extern void kmemleak_ignore(const void *ptr) __ref;
42c017b4beSCatalin Marinas extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
43a6186d89SCatalin Marinas extern void kmemleak_no_scan(const void *ptr) __ref;
449099daedSCatalin Marinas extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count,
459099daedSCatalin Marinas 				gfp_t gfp) __ref;
469099daedSCatalin Marinas extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
479099daedSCatalin Marinas extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref;
489099daedSCatalin Marinas extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
493c7b4e6bSCatalin Marinas 
503c7b4e6bSCatalin Marinas static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
51d50112edSAlexey Dobriyan 					    int min_count, slab_flags_t flags,
523c7b4e6bSCatalin Marinas 					    gfp_t gfp)
533c7b4e6bSCatalin Marinas {
543c7b4e6bSCatalin Marinas 	if (!(flags & SLAB_NOLEAKTRACE))
553c7b4e6bSCatalin Marinas 		kmemleak_alloc(ptr, size, min_count, gfp);
563c7b4e6bSCatalin Marinas }
573c7b4e6bSCatalin Marinas 
58d50112edSAlexey Dobriyan static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
593c7b4e6bSCatalin Marinas {
603c7b4e6bSCatalin Marinas 	if (!(flags & SLAB_NOLEAKTRACE))
613c7b4e6bSCatalin Marinas 		kmemleak_free(ptr);
623c7b4e6bSCatalin Marinas }
633c7b4e6bSCatalin Marinas 
643c7b4e6bSCatalin Marinas static inline void kmemleak_erase(void **ptr)
653c7b4e6bSCatalin Marinas {
663c7b4e6bSCatalin Marinas 	*ptr = NULL;
673c7b4e6bSCatalin Marinas }
683c7b4e6bSCatalin Marinas 
693c7b4e6bSCatalin Marinas #else
703c7b4e6bSCatalin Marinas 
713c7b4e6bSCatalin Marinas static inline void kmemleak_init(void)
723c7b4e6bSCatalin Marinas {
733c7b4e6bSCatalin Marinas }
743c7b4e6bSCatalin Marinas static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count,
753c7b4e6bSCatalin Marinas 				  gfp_t gfp)
763c7b4e6bSCatalin Marinas {
773c7b4e6bSCatalin Marinas }
783c7b4e6bSCatalin Marinas static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
79d50112edSAlexey Dobriyan 					    int min_count, slab_flags_t flags,
803c7b4e6bSCatalin Marinas 					    gfp_t gfp)
813c7b4e6bSCatalin Marinas {
823c7b4e6bSCatalin Marinas }
838a8c35faSLarry Finger static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
848a8c35faSLarry Finger 					 gfp_t gfp)
85f528f0b8SCatalin Marinas {
86f528f0b8SCatalin Marinas }
8794f4a161SCatalin Marinas static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
8894f4a161SCatalin Marinas 				    gfp_t gfp)
8994f4a161SCatalin Marinas {
9094f4a161SCatalin Marinas }
913c7b4e6bSCatalin Marinas static inline void kmemleak_free(const void *ptr)
923c7b4e6bSCatalin Marinas {
933c7b4e6bSCatalin Marinas }
9453238a60SCatalin Marinas static inline void kmemleak_free_part(const void *ptr, size_t size)
9553238a60SCatalin Marinas {
9653238a60SCatalin Marinas }
97d50112edSAlexey Dobriyan static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
983c7b4e6bSCatalin Marinas {
993c7b4e6bSCatalin Marinas }
100f528f0b8SCatalin Marinas static inline void kmemleak_free_percpu(const void __percpu *ptr)
101f528f0b8SCatalin Marinas {
102f528f0b8SCatalin Marinas }
103ffe2c748SCatalin Marinas static inline void kmemleak_update_trace(const void *ptr)
104ffe2c748SCatalin Marinas {
105ffe2c748SCatalin Marinas }
1063c7b4e6bSCatalin Marinas static inline void kmemleak_not_leak(const void *ptr)
1073c7b4e6bSCatalin Marinas {
1083c7b4e6bSCatalin Marinas }
1093c7b4e6bSCatalin Marinas static inline void kmemleak_ignore(const void *ptr)
1103c7b4e6bSCatalin Marinas {
1113c7b4e6bSCatalin Marinas }
112c017b4beSCatalin Marinas static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
1133c7b4e6bSCatalin Marinas {
1143c7b4e6bSCatalin Marinas }
1153c7b4e6bSCatalin Marinas static inline void kmemleak_erase(void **ptr)
1163c7b4e6bSCatalin Marinas {
1173c7b4e6bSCatalin Marinas }
1183c7b4e6bSCatalin Marinas static inline void kmemleak_no_scan(const void *ptr)
1193c7b4e6bSCatalin Marinas {
1203c7b4e6bSCatalin Marinas }
1219099daedSCatalin Marinas static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
1229099daedSCatalin Marinas 				       int min_count, gfp_t gfp)
1239099daedSCatalin Marinas {
1249099daedSCatalin Marinas }
1259099daedSCatalin Marinas static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
1269099daedSCatalin Marinas {
1279099daedSCatalin Marinas }
1289099daedSCatalin Marinas static inline void kmemleak_not_leak_phys(phys_addr_t phys)
1299099daedSCatalin Marinas {
1309099daedSCatalin Marinas }
1319099daedSCatalin Marinas static inline void kmemleak_ignore_phys(phys_addr_t phys)
1329099daedSCatalin Marinas {
1339099daedSCatalin Marinas }
1343c7b4e6bSCatalin Marinas 
1353c7b4e6bSCatalin Marinas #endif	/* CONFIG_DEBUG_KMEMLEAK */
1363c7b4e6bSCatalin Marinas 
1373c7b4e6bSCatalin Marinas #endif	/* __KMEMLEAK_H */
138