1 // SPDX-License-Identifier: GPL-2.0-only
3 /// Check that kvmalloc'ed memory is freed by kfree functions,
4 /// vmalloc'ed by vfree functions and kvmalloc'ed by kvfree
8 // Copyright: (C) 2020 Denis Efremov ISPRAS
9 // Options: --no-includes --include-headers
25 E = \(kmalloc\|kzalloc\|krealloc\|kcalloc\|
26 kmalloc_node\|kzalloc_node\|kmalloc_array\|
27 kmalloc_array_node\|kcalloc_node\)(...)@kok
31 E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|
32 vzalloc_node\|vmalloc_exec\|vmalloc_32\|
33 vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|
34 __vmalloc_node\)(...)@vok
38 E = \(kmalloc\|kzalloc\|krealloc\|kcalloc\|kmalloc_node\|kzalloc_node\|
39 kmalloc_array\|kmalloc_array_node\|kcalloc_node\)(...)@kok
44 E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|
45 vzalloc_node\|vmalloc_exec\|vmalloc_32\|
46 vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|
47 __vmalloc_node\)(...)@vok
57 E = \(kvmalloc\|kvzalloc\|kvcalloc\|kvzalloc_node\|kvmalloc_node\|
62 @vfree depends on !patch@
64 position a != alloc.kok;
65 position f != free.fok;
68 * E = \(kmalloc\|kzalloc\|krealloc\|kcalloc\|kmalloc_node\|
69 * kzalloc_node\|kmalloc_array\|kmalloc_array_node\|
70 * kcalloc_node\)(...)@a
71 ... when != if (...) { ... E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|__vmalloc_node\)(...); ... }
72 when != is_vmalloc_addr(E)
74 * \(vfree\|vfree_atomic\|kvfree\)(E)@f
76 @depends on patch exists@
78 position a != alloc.kok;
79 position f != free.fok;
82 E = \(kmalloc\|kzalloc\|krealloc\|kcalloc\|kmalloc_node\|
83 kzalloc_node\|kmalloc_array\|kmalloc_array_node\|
85 ... when != if (...) { ... E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|__vmalloc_node_range\|__vmalloc_node\)(...); ... }
86 when != is_vmalloc_addr(E)
88 - \(vfree\|vfree_atomic\|kvfree\)(E)@f
91 @kfree depends on !patch@
93 position a != alloc.vok;
94 position f != free.fok;
97 * E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|
98 * vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|
99 * __vmalloc_node_range\|__vmalloc_node\)(...)@a
100 ... when != is_vmalloc_addr(E)
102 * \(kfree\|kfree_sensitive\|kvfree\)(E)@f
104 @depends on patch exists@
106 position a != alloc.vok;
107 position f != free.fok;
110 E = \(vmalloc\|vzalloc\|vmalloc_user\|vmalloc_node\|vzalloc_node\|
111 vmalloc_exec\|vmalloc_32\|vmalloc_32_user\|__vmalloc\|
112 __vmalloc_node_range\|__vmalloc_node\)(...)@a
113 ... when != is_vmalloc_addr(E)
115 - \(kfree\|kvfree\)(E)@f
118 @kvfree depends on !patch@
123 * E = \(kvmalloc\|kvzalloc\|kvcalloc\|kvzalloc_node\|kvmalloc_node\|
124 * kvmalloc_array\)(...)@a
125 ... when != is_vmalloc_addr(E)
127 * \(kfree\|kfree_sensitive\|vfree\|vfree_atomic\)(E)@f
129 @depends on patch exists@
133 E = \(kvmalloc\|kvzalloc\|kvcalloc\|kvzalloc_node\|kvmalloc_node\|
134 kvmalloc_array\)(...)
135 ... when != is_vmalloc_addr(E)
137 - \(kfree\|vfree\)(E)
140 @kvfree_switch depends on !patch@
145 ... when != is_vmalloc_addr(E)
147 * \(kfree\|kfree_sensitive\|vfree\|vfree_atomic\)(E)@f
149 @depends on patch exists@
154 ... when != is_vmalloc_addr(E)
157 - \(kfree\|vfree\)(E)@f
160 - kfree_sensitive(E)@f
161 + kvfree_sensitive(E)
164 @script: python depends on report@
169 msg = "WARNING kmalloc is used to allocate this memory at line %s" % (a[0].line)
170 coccilib.report.print_report(f[0], msg)
172 @script: python depends on org@
177 msg = "WARNING kmalloc is used to allocate this memory at line %s" % (a[0].line)
178 coccilib.org.print_todo(f[0], msg)
180 @script: python depends on report@
185 msg = "WARNING vmalloc is used to allocate this memory at line %s" % (a[0].line)
186 coccilib.report.print_report(f[0], msg)
188 @script: python depends on org@
193 msg = "WARNING vmalloc is used to allocate this memory at line %s" % (a[0].line)
194 coccilib.org.print_todo(f[0], msg)
196 @script: python depends on report@
201 msg = "WARNING kvmalloc is used to allocate this memory at line %s" % (a[0].line)
202 coccilib.report.print_report(f[0], msg)
204 @script: python depends on org@
209 msg = "WARNING kvmalloc is used to allocate this memory at line %s" % (a[0].line)
210 coccilib.org.print_todo(f[0], msg)
212 @script: python depends on report@
215 f << kvfree_switch.f;
218 msg = "WARNING kmalloc (line %s) && vmalloc (line %s) are used to allocate this memory" % (ka[0].line, va[0].line)
219 coccilib.report.print_report(f[0], msg)
221 @script: python depends on org@
224 f << kvfree_switch.f;
227 msg = "WARNING kmalloc (line %s) && vmalloc (line %s) are used to allocate this memory" % (ka[0].line, va[0].line)
228 coccilib.org.print_todo(f[0], msg)