blob: 34684b2026abfa3e2badd265fe19a2dc4eac59b4 [file] [log] [blame]
Thomas Gleixner45051532019-05-29 16:57:47 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Catalin Marinas3c7b4e62009-06-11 13:22:39 +01002/*
3 * include/linux/kmemleak.h
4 *
5 * Copyright (C) 2008 ARM Limited
6 * Written by Catalin Marinas <catalin.marinas@arm.com>
Catalin Marinas3c7b4e62009-06-11 13:22:39 +01007 */
8
9#ifndef __KMEMLEAK_H
10#define __KMEMLEAK_H
11
Andrew Morton66f2ca72014-12-12 16:55:41 -080012#include <linux/slab.h>
Catalin Marinas94f4a162017-07-06 15:40:22 -070013#include <linux/vmalloc.h>
Andrew Morton66f2ca72014-12-12 16:55:41 -080014
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010015#ifdef CONFIG_DEBUG_KMEMLEAK
16
Nicolas Iooss98e89cf2015-12-11 13:40:43 -080017extern void kmemleak_init(void) __init;
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010018extern void kmemleak_alloc(const void *ptr, size_t size, int min_count,
Catalin Marinasa6186d82009-08-27 14:29:16 +010019 gfp_t gfp) __ref;
Larry Finger8a8c35f2015-06-24 16:58:51 -070020extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
21 gfp_t gfp) __ref;
Catalin Marinas94f4a162017-07-06 15:40:22 -070022extern void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
23 gfp_t gfp) __ref;
Catalin Marinasa6186d82009-08-27 14:29:16 +010024extern void kmemleak_free(const void *ptr) __ref;
25extern void kmemleak_free_part(const void *ptr, size_t size) __ref;
Catalin Marinasf528f0b2011-09-26 17:12:53 +010026extern void kmemleak_free_percpu(const void __percpu *ptr) __ref;
Catalin Marinasffe2c742014-06-06 14:38:17 -070027extern void kmemleak_update_trace(const void *ptr) __ref;
Catalin Marinasa6186d82009-08-27 14:29:16 +010028extern void kmemleak_not_leak(const void *ptr) __ref;
29extern void kmemleak_ignore(const void *ptr) __ref;
Catalin Marinasc017b4b2009-10-28 13:33:09 +000030extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
Catalin Marinasa6186d82009-08-27 14:29:16 +010031extern void kmemleak_no_scan(const void *ptr) __ref;
Catalin Marinas9099dae2016-10-11 13:55:11 -070032extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count,
33 gfp_t gfp) __ref;
34extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
35extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref;
36extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010037
38static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
Alexey Dobriyand50112e2017-11-15 17:32:18 -080039 int min_count, slab_flags_t flags,
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010040 gfp_t gfp)
41{
42 if (!(flags & SLAB_NOLEAKTRACE))
43 kmemleak_alloc(ptr, size, min_count, gfp);
44}
45
Alexey Dobriyand50112e2017-11-15 17:32:18 -080046static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010047{
48 if (!(flags & SLAB_NOLEAKTRACE))
49 kmemleak_free(ptr);
50}
51
52static inline void kmemleak_erase(void **ptr)
53{
54 *ptr = NULL;
55}
56
57#else
58
59static inline void kmemleak_init(void)
60{
61}
62static inline void kmemleak_alloc(const void *ptr, size_t size, int min_count,
63 gfp_t gfp)
64{
65}
66static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
Alexey Dobriyand50112e2017-11-15 17:32:18 -080067 int min_count, slab_flags_t flags,
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010068 gfp_t gfp)
69{
70}
Larry Finger8a8c35f2015-06-24 16:58:51 -070071static inline void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,
72 gfp_t gfp)
Catalin Marinasf528f0b2011-09-26 17:12:53 +010073{
74}
Catalin Marinas94f4a162017-07-06 15:40:22 -070075static inline void kmemleak_vmalloc(const struct vm_struct *area, size_t size,
76 gfp_t gfp)
77{
78}
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010079static inline void kmemleak_free(const void *ptr)
80{
81}
Catalin Marinas53238a62009-07-07 10:33:00 +010082static inline void kmemleak_free_part(const void *ptr, size_t size)
83{
84}
Alexey Dobriyand50112e2017-11-15 17:32:18 -080085static inline void kmemleak_free_recursive(const void *ptr, slab_flags_t flags)
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010086{
87}
Catalin Marinasf528f0b2011-09-26 17:12:53 +010088static inline void kmemleak_free_percpu(const void __percpu *ptr)
89{
90}
Catalin Marinasffe2c742014-06-06 14:38:17 -070091static inline void kmemleak_update_trace(const void *ptr)
92{
93}
Catalin Marinas3c7b4e62009-06-11 13:22:39 +010094static inline void kmemleak_not_leak(const void *ptr)
95{
96}
97static inline void kmemleak_ignore(const void *ptr)
98{
99}
Catalin Marinasc017b4b2009-10-28 13:33:09 +0000100static inline void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp)
Catalin Marinas3c7b4e62009-06-11 13:22:39 +0100101{
102}
103static inline void kmemleak_erase(void **ptr)
104{
105}
106static inline void kmemleak_no_scan(const void *ptr)
107{
108}
Catalin Marinas9099dae2016-10-11 13:55:11 -0700109static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
110 int min_count, gfp_t gfp)
111{
112}
113static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
114{
115}
116static inline void kmemleak_not_leak_phys(phys_addr_t phys)
117{
118}
119static inline void kmemleak_ignore_phys(phys_addr_t phys)
120{
121}
Catalin Marinas3c7b4e62009-06-11 13:22:39 +0100122
123#endif /* CONFIG_DEBUG_KMEMLEAK */
124
125#endif /* __KMEMLEAK_H */