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; 329099daedSCatalin Marinas extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count, 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_not_leak_phys(phys_addr_t phys) __ref; 369099daedSCatalin Marinas extern void kmemleak_ignore_phys(phys_addr_t phys) __ref; 373c7b4e6bSCatalin Marinas 383c7b4e6bSCatalin Marinas static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, 39d50112edSAlexey Dobriyan int min_count, slab_flags_t flags, 403c7b4e6bSCatalin Marinas gfp_t gfp) 413c7b4e6bSCatalin Marinas { 423c7b4e6bSCatalin Marinas if (!(flags & SLAB_NOLEAKTRACE)) 433c7b4e6bSCatalin Marinas kmemleak_alloc(ptr, size, min_count, gfp); 443c7b4e6bSCatalin Marinas } 453c7b4e6bSCatalin Marinas 46d50112edSAlexey Dobriyan static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags) 473c7b4e6bSCatalin Marinas { 483c7b4e6bSCatalin Marinas if (!(flags & SLAB_NOLEAKTRACE)) 493c7b4e6bSCatalin Marinas kmemleak_free(ptr); 503c7b4e6bSCatalin Marinas } 513c7b4e6bSCatalin Marinas 523c7b4e6bSCatalin Marinas static inline void kmemleak_erase(void **ptr) 533c7b4e6bSCatalin Marinas { 543c7b4e6bSCatalin Marinas *ptr = NULL; 553c7b4e6bSCatalin Marinas } 563c7b4e6bSCatalin Marinas 573c7b4e6bSCatalin Marinas #else 583c7b4e6bSCatalin Marinas 593c7b4e6bSCatalin Marinas static inline void kmemleak_init(void) 603c7b4e6bSCatalin Marinas { 613c7b4e6bSCatalin Marinas } 623c7b4e6bSCatalin Marinas static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count, 633c7b4e6bSCatalin Marinas gfp_t gfp) 643c7b4e6bSCatalin Marinas { 653c7b4e6bSCatalin Marinas } 663c7b4e6bSCatalin Marinas static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, 67d50112edSAlexey Dobriyan int min_count, slab_flags_t flags, 683c7b4e6bSCatalin Marinas gfp_t gfp) 693c7b4e6bSCatalin Marinas { 703c7b4e6bSCatalin Marinas } 718a8c35faSLarry Finger static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size, 728a8c35faSLarry Finger gfp_t gfp) 73f528f0b8SCatalin Marinas { 74f528f0b8SCatalin Marinas } 7594f4a161SCatalin Marinas static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size, 7694f4a161SCatalin Marinas gfp_t gfp) 7794f4a161SCatalin Marinas { 7894f4a161SCatalin Marinas } 793c7b4e6bSCatalin Marinas static inline void kmemleak_free(const void *ptr) 803c7b4e6bSCatalin Marinas { 813c7b4e6bSCatalin Marinas } 8253238a60SCatalin Marinas static inline void kmemleak_free_part(const void *ptr, size_t size) 8353238a60SCatalin Marinas { 8453238a60SCatalin Marinas } 85d50112edSAlexey Dobriyan static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags) 863c7b4e6bSCatalin Marinas { 873c7b4e6bSCatalin Marinas } 88f528f0b8SCatalin Marinas static inline void kmemleak_free_percpu(const void __percpu *ptr) 89f528f0b8SCatalin Marinas { 90f528f0b8SCatalin Marinas } 91ffe2c748SCatalin Marinas static inline void kmemleak_update_trace(const void *ptr) 92ffe2c748SCatalin Marinas { 93ffe2c748SCatalin Marinas } 943c7b4e6bSCatalin Marinas static inline void kmemleak_not_leak(const void *ptr) 953c7b4e6bSCatalin Marinas { 963c7b4e6bSCatalin Marinas } 973c7b4e6bSCatalin Marinas static inline void kmemleak_ignore(const void *ptr) 983c7b4e6bSCatalin Marinas { 993c7b4e6bSCatalin Marinas } 100c017b4beSCatalin Marinas static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) 1013c7b4e6bSCatalin Marinas { 1023c7b4e6bSCatalin Marinas } 1033c7b4e6bSCatalin Marinas static inline void kmemleak_erase(void **ptr) 1043c7b4e6bSCatalin Marinas { 1053c7b4e6bSCatalin Marinas } 1063c7b4e6bSCatalin Marinas static inline void kmemleak_no_scan(const void *ptr) 1073c7b4e6bSCatalin Marinas { 1083c7b4e6bSCatalin Marinas } 1099099daedSCatalin Marinas static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size, 1109099daedSCatalin Marinas int min_count, gfp_t gfp) 1119099daedSCatalin Marinas { 1129099daedSCatalin Marinas } 1139099daedSCatalin Marinas static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size) 1149099daedSCatalin Marinas { 1159099daedSCatalin Marinas } 1169099daedSCatalin Marinas static inline void kmemleak_not_leak_phys(phys_addr_t phys) 1179099daedSCatalin Marinas { 1189099daedSCatalin Marinas } 1199099daedSCatalin Marinas static inline void kmemleak_ignore_phys(phys_addr_t phys) 1209099daedSCatalin Marinas { 1219099daedSCatalin Marinas } 1223c7b4e6bSCatalin Marinas 1233c7b4e6bSCatalin Marinas #endif /* CONFIG_DEBUG_KMEMLEAK */ 1243c7b4e6bSCatalin Marinas 1253c7b4e6bSCatalin Marinas #endif /* __KMEMLEAK_H */ 126