~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/coccinelle/api/kvmalloc.cocci

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/coccinelle/api/kvmalloc.cocci (Architecture ppc) and /scripts/coccinelle/api/kvmalloc.cocci (Architecture sparc)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 ///                                                 2 ///
  3 /// Find if/else condition with kmalloc/vmallo      3 /// Find if/else condition with kmalloc/vmalloc calls.
  4 /// Suggest to use kvmalloc instead. Same for       4 /// Suggest to use kvmalloc instead. Same for kvfree.
  5 ///                                                 5 ///
  6 // Confidence: High                                 6 // Confidence: High
  7 // Copyright: (C) 2020 Denis Efremov ISPRAS         7 // Copyright: (C) 2020 Denis Efremov ISPRAS
  8 // Options: --no-includes --include-headers         8 // Options: --no-includes --include-headers
  9 //                                                  9 //
 10                                                    10 
 11 virtual patch                                      11 virtual patch
 12 virtual report                                     12 virtual report
 13 virtual org                                        13 virtual org
 14 virtual context                                    14 virtual context
 15                                                    15 
 16 @initialize:python@                                16 @initialize:python@
 17 @@                                                 17 @@
 18 filter = frozenset(['kvfree'])                     18 filter = frozenset(['kvfree'])
 19                                                    19 
 20 def relevant(p):                                   20 def relevant(p):
 21     return not (filter & {el.current_element f     21     return not (filter & {el.current_element for el in p})
 22                                                    22 
 23 @kvmalloc depends on !patch@                       23 @kvmalloc depends on !patch@
 24 expression E, E1, size;                            24 expression E, E1, size;
 25 identifier flags;                                  25 identifier flags;
 26 binary operator cmp = {<=, <, ==, >, >=};          26 binary operator cmp = {<=, <, ==, >, >=};
 27 identifier x;                                      27 identifier x;
 28 type T;                                            28 type T;
 29 position p;                                        29 position p;
 30 @@                                                 30 @@
 31                                                    31 
 32 (                                                  32 (
 33 * if (size cmp E1 || ...)@p {                      33 * if (size cmp E1 || ...)@p {
 34     ...                                            34     ...
 35 *    E = \(kmalloc\|kzalloc\|kcalloc\|kmalloc_     35 *    E = \(kmalloc\|kzalloc\|kcalloc\|kmalloc_node\|kzalloc_node\|
 36 *          kmalloc_array\|kmalloc_array_node\|     36 *          kmalloc_array\|kmalloc_array_node\|kcalloc_node\)
 37 *          (..., size, \(flags\|GFP_KERNEL\|\(     37 *          (..., size, \(flags\|GFP_KERNEL\|\(GFP_KERNEL\|flags\)|__GFP_NOWARN\), ...)
 38     ...                                            38     ...
 39   } else {                                         39   } else {
 40     ...                                            40     ...
 41 *    E = \(vmalloc\|vzalloc\|vmalloc_node\|vza     41 *    E = \(vmalloc\|vzalloc\|vmalloc_node\|vzalloc_node\)(..., size, ...)
 42     ...                                            42     ...
 43   }                                                43   }
 44 |                                                  44 |
 45 * E = \(kmalloc\|kzalloc\|kcalloc\|kmalloc_nod     45 * E = \(kmalloc\|kzalloc\|kcalloc\|kmalloc_node\|kzalloc_node\|
 46 *       kmalloc_array\|kmalloc_array_node\|kca     46 *       kmalloc_array\|kmalloc_array_node\|kcalloc_node\)
 47 *       (..., size, \(flags\|GFP_KERNEL\|\(GFP     47 *       (..., size, \(flags\|GFP_KERNEL\|\(GFP_KERNEL\|flags\)|__GFP_NOWARN\), ...)
 48   ... when != E = E1                               48   ... when != E = E1
 49       when != size = E1                            49       when != size = E1
 50       when any                                     50       when any
 51 * if (E == NULL)@p {                               51 * if (E == NULL)@p {
 52     ...                                            52     ...
 53 *   E = \(vmalloc\|vzalloc\|vmalloc_node\|vzal     53 *   E = \(vmalloc\|vzalloc\|vmalloc_node\|vzalloc_node\)(..., size, ...)
 54     ...                                            54     ...
 55   }                                                55   }
 56 |                                                  56 |
 57 * T x = \(kmalloc\|kzalloc\|kcalloc\|kmalloc_n     57 * T x = \(kmalloc\|kzalloc\|kcalloc\|kmalloc_node\|kzalloc_node\|
 58 *         kmalloc_array\|kmalloc_array_node\|k     58 *         kmalloc_array\|kmalloc_array_node\|kcalloc_node\)
 59 *         (..., size, \(flags\|GFP_KERNEL\|\(G     59 *         (..., size, \(flags\|GFP_KERNEL\|\(GFP_KERNEL\|flags\)|__GFP_NOWARN\), ...);
 60   ... when != x = E1                               60   ... when != x = E1
 61       when != size = E1                            61       when != size = E1
 62       when any                                     62       when any
 63 * if (x == NULL)@p {                               63 * if (x == NULL)@p {
 64     ...                                            64     ...
 65 *   x = \(vmalloc\|vzalloc\|vmalloc_node\|vzal     65 *   x = \(vmalloc\|vzalloc\|vmalloc_node\|vzalloc_node\)(..., size, ...)
 66     ...                                            66     ...
 67   }                                                67   }
 68 )                                                  68 )
 69                                                    69 
 70 @kvfree depends on !patch@                         70 @kvfree depends on !patch@
 71 expression E;                                      71 expression E;
 72 position p : script:python() { relevant(p) };      72 position p : script:python() { relevant(p) };
 73 @@                                                 73 @@
 74                                                    74 
 75 * if (is_vmalloc_addr(E))@p {                      75 * if (is_vmalloc_addr(E))@p {
 76     ...                                            76     ...
 77 *   vfree(E)                                       77 *   vfree(E)
 78     ...                                            78     ...
 79   } else {                                         79   } else {
 80     ... when != krealloc(E, ...)                   80     ... when != krealloc(E, ...)
 81         when any                                   81         when any
 82 *   \(kfree\|kfree_sensitive\)(E)                  82 *   \(kfree\|kfree_sensitive\)(E)
 83     ...                                            83     ...
 84   }                                                84   }
 85                                                    85 
 86 @depends on patch@                                 86 @depends on patch@
 87 expression E, E1, size, node;                      87 expression E, E1, size, node;
 88 binary operator cmp = {<=, <, ==, >, >=};          88 binary operator cmp = {<=, <, ==, >, >=};
 89 identifier flags, x;                               89 identifier flags, x;
 90 type T;                                            90 type T;
 91 @@                                                 91 @@
 92                                                    92 
 93 (                                                  93 (
 94 - if (size cmp E1)                                 94 - if (size cmp E1)
 95 -    E = kmalloc(size, flags);                     95 -    E = kmalloc(size, flags);
 96 - else                                             96 - else
 97 -    E = vmalloc(size);                            97 -    E = vmalloc(size);
 98 + E = kvmalloc(size, flags);                       98 + E = kvmalloc(size, flags);
 99 |                                                  99 |
100 - if (size cmp E1)                                100 - if (size cmp E1)
101 -    E = kmalloc(size, \(GFP_KERNEL\|GFP_KERNE    101 -    E = kmalloc(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\));
102 - else                                            102 - else
103 -    E = vmalloc(size);                           103 -    E = vmalloc(size);
104 + E = kvmalloc(size, GFP_KERNEL);                 104 + E = kvmalloc(size, GFP_KERNEL);
105 |                                                 105 |
106 - E = kmalloc(size, flags | __GFP_NOWARN);        106 - E = kmalloc(size, flags | __GFP_NOWARN);
107 - if (E == NULL)                                  107 - if (E == NULL)
108 -   E = vmalloc(size);                            108 -   E = vmalloc(size);
109 + E = kvmalloc(size, flags);                      109 + E = kvmalloc(size, flags);
110 |                                                 110 |
111 - E = kmalloc(size, \(GFP_KERNEL\|GFP_KERNEL|_    111 - E = kmalloc(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\));
112 - if (E == NULL)                                  112 - if (E == NULL)
113 -   E = vmalloc(size);                            113 -   E = vmalloc(size);
114 + E = kvmalloc(size, GFP_KERNEL);                 114 + E = kvmalloc(size, GFP_KERNEL);
115 |                                                 115 |
116 - T x = kmalloc(size, flags | __GFP_NOWARN);      116 - T x = kmalloc(size, flags | __GFP_NOWARN);
117 - if (x == NULL)                                  117 - if (x == NULL)
118 -   x = vmalloc(size);                            118 -   x = vmalloc(size);
119 + T x = kvmalloc(size, flags);                    119 + T x = kvmalloc(size, flags);
120 |                                                 120 |
121 - T x = kmalloc(size, \(GFP_KERNEL\|GFP_KERNEL    121 - T x = kmalloc(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\));
122 - if (x == NULL)                                  122 - if (x == NULL)
123 -   x = vmalloc(size);                            123 -   x = vmalloc(size);
124 + T x = kvmalloc(size, GFP_KERNEL);               124 + T x = kvmalloc(size, GFP_KERNEL);
125 |                                                 125 |
126 - if (size cmp E1)                                126 - if (size cmp E1)
127 -    E = kzalloc(size, flags);                    127 -    E = kzalloc(size, flags);
128 - else                                            128 - else
129 -    E = vzalloc(size);                           129 -    E = vzalloc(size);
130 + E = kvzalloc(size, flags);                      130 + E = kvzalloc(size, flags);
131 |                                                 131 |
132 - if (size cmp E1)                                132 - if (size cmp E1)
133 -    E = kzalloc(size, \(GFP_KERNEL\|GFP_KERNE    133 -    E = kzalloc(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\));
134 - else                                            134 - else
135 -    E = vzalloc(size);                           135 -    E = vzalloc(size);
136 + E = kvzalloc(size, GFP_KERNEL);                 136 + E = kvzalloc(size, GFP_KERNEL);
137 |                                                 137 |
138 - E = kzalloc(size, flags | __GFP_NOWARN);        138 - E = kzalloc(size, flags | __GFP_NOWARN);
139 - if (E == NULL)                                  139 - if (E == NULL)
140 -   E = vzalloc(size);                            140 -   E = vzalloc(size);
141 + E = kvzalloc(size, flags);                      141 + E = kvzalloc(size, flags);
142 |                                                 142 |
143 - E = kzalloc(size, \(GFP_KERNEL\|GFP_KERNEL|_    143 - E = kzalloc(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\));
144 - if (E == NULL)                                  144 - if (E == NULL)
145 -   E = vzalloc(size);                            145 -   E = vzalloc(size);
146 + E = kvzalloc(size, GFP_KERNEL);                 146 + E = kvzalloc(size, GFP_KERNEL);
147 |                                                 147 |
148 - T x = kzalloc(size, flags | __GFP_NOWARN);      148 - T x = kzalloc(size, flags | __GFP_NOWARN);
149 - if (x == NULL)                                  149 - if (x == NULL)
150 -   x = vzalloc(size);                            150 -   x = vzalloc(size);
151 + T x = kvzalloc(size, flags);                    151 + T x = kvzalloc(size, flags);
152 |                                                 152 |
153 - T x = kzalloc(size, \(GFP_KERNEL\|GFP_KERNEL    153 - T x = kzalloc(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\));
154 - if (x == NULL)                                  154 - if (x == NULL)
155 -   x = vzalloc(size);                            155 -   x = vzalloc(size);
156 + T x = kvzalloc(size, GFP_KERNEL);               156 + T x = kvzalloc(size, GFP_KERNEL);
157 |                                                 157 |
158 - if (size cmp E1)                                158 - if (size cmp E1)
159 -    E = kmalloc_node(size, flags, node);         159 -    E = kmalloc_node(size, flags, node);
160 - else                                            160 - else
161 -    E = vmalloc_node(size, node);                161 -    E = vmalloc_node(size, node);
162 + E = kvmalloc_node(size, flags, node);           162 + E = kvmalloc_node(size, flags, node);
163 |                                                 163 |
164 - if (size cmp E1)                                164 - if (size cmp E1)
165 -    E = kmalloc_node(size, \(GFP_KERNEL\|GFP_    165 -    E = kmalloc_node(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\), node);
166 - else                                            166 - else
167 -    E = vmalloc_node(size, node);                167 -    E = vmalloc_node(size, node);
168 + E = kvmalloc_node(size, GFP_KERNEL, node);      168 + E = kvmalloc_node(size, GFP_KERNEL, node);
169 |                                                 169 |
170 - E = kmalloc_node(size, flags | __GFP_NOWARN,    170 - E = kmalloc_node(size, flags | __GFP_NOWARN, node);
171 - if (E == NULL)                                  171 - if (E == NULL)
172 -   E = vmalloc_node(size, node);                 172 -   E = vmalloc_node(size, node);
173 + E = kvmalloc_node(size, flags, node);           173 + E = kvmalloc_node(size, flags, node);
174 |                                                 174 |
175 - E = kmalloc_node(size, \(GFP_KERNEL\|GFP_KER    175 - E = kmalloc_node(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\), node);
176 - if (E == NULL)                                  176 - if (E == NULL)
177 -   E = vmalloc_node(size, node);                 177 -   E = vmalloc_node(size, node);
178 + E = kvmalloc_node(size, GFP_KERNEL, node);      178 + E = kvmalloc_node(size, GFP_KERNEL, node);
179 |                                                 179 |
180 - T x = kmalloc_node(size, flags | __GFP_NOWAR    180 - T x = kmalloc_node(size, flags | __GFP_NOWARN, node);
181 - if (x == NULL)                                  181 - if (x == NULL)
182 -   x = vmalloc_node(size, node);                 182 -   x = vmalloc_node(size, node);
183 + T x = kvmalloc_node(size, flags, node);         183 + T x = kvmalloc_node(size, flags, node);
184 |                                                 184 |
185 - T x = kmalloc_node(size, \(GFP_KERNEL\|GFP_K    185 - T x = kmalloc_node(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\), node);
186 - if (x == NULL)                                  186 - if (x == NULL)
187 -   x = vmalloc_node(size, node);                 187 -   x = vmalloc_node(size, node);
188 + T x = kvmalloc_node(size, GFP_KERNEL, node);    188 + T x = kvmalloc_node(size, GFP_KERNEL, node);
189 |                                                 189 |
190 - if (size cmp E1)                                190 - if (size cmp E1)
191 -    E = kvzalloc_node(size, flags, node);        191 -    E = kvzalloc_node(size, flags, node);
192 - else                                            192 - else
193 -    E = vzalloc_node(size, node);                193 -    E = vzalloc_node(size, node);
194 + E = kvzalloc_node(size, flags, node);           194 + E = kvzalloc_node(size, flags, node);
195 |                                                 195 |
196 - if (size cmp E1)                                196 - if (size cmp E1)
197 -    E = kvzalloc_node(size, \(GFP_KERNEL\|GFP    197 -    E = kvzalloc_node(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\), node);
198 - else                                            198 - else
199 -    E = vzalloc_node(size, node);                199 -    E = vzalloc_node(size, node);
200 + E = kvzalloc_node(size, GFP_KERNEL, node);      200 + E = kvzalloc_node(size, GFP_KERNEL, node);
201 |                                                 201 |
202 - E = kvzalloc_node(size, flags | __GFP_NOWARN    202 - E = kvzalloc_node(size, flags | __GFP_NOWARN, node);
203 - if (E == NULL)                                  203 - if (E == NULL)
204 -   E = vzalloc_node(size, node);                 204 -   E = vzalloc_node(size, node);
205 + E = kvzalloc_node(size, flags, node);           205 + E = kvzalloc_node(size, flags, node);
206 |                                                 206 |
207 - E = kvzalloc_node(size, \(GFP_KERNEL\|GFP_KE    207 - E = kvzalloc_node(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\), node);
208 - if (E == NULL)                                  208 - if (E == NULL)
209 -   E = vzalloc_node(size, node);                 209 -   E = vzalloc_node(size, node);
210 + E = kvzalloc_node(size, GFP_KERNEL, node);      210 + E = kvzalloc_node(size, GFP_KERNEL, node);
211 |                                                 211 |
212 - T x = kvzalloc_node(size, flags | __GFP_NOWA    212 - T x = kvzalloc_node(size, flags | __GFP_NOWARN, node);
213 - if (x == NULL)                                  213 - if (x == NULL)
214 -   x = vzalloc_node(size, node);                 214 -   x = vzalloc_node(size, node);
215 + T x = kvzalloc_node(size, flags, node);         215 + T x = kvzalloc_node(size, flags, node);
216 |                                                 216 |
217 - T x = kvzalloc_node(size, \(GFP_KERNEL\|GFP_    217 - T x = kvzalloc_node(size, \(GFP_KERNEL\|GFP_KERNEL|__GFP_NOWARN\), node);
218 - if (x == NULL)                                  218 - if (x == NULL)
219 -   x = vzalloc_node(size, node);                 219 -   x = vzalloc_node(size, node);
220 + T x = kvzalloc_node(size, GFP_KERNEL, node);    220 + T x = kvzalloc_node(size, GFP_KERNEL, node);
221 )                                                 221 )
222                                                   222 
223 @depends on patch@                                223 @depends on patch@
224 expression E;                                     224 expression E;
225 position p : script:python() { relevant(p) };     225 position p : script:python() { relevant(p) };
226 @@                                                226 @@
227                                                   227 
228 - if (is_vmalloc_addr(E))@p                       228 - if (is_vmalloc_addr(E))@p
229 -   vfree(E);                                     229 -   vfree(E);
230 - else                                            230 - else
231 -   kfree(E);                                     231 -   kfree(E);
232 + kvfree(E);                                      232 + kvfree(E);
233                                                   233 
234 @script: python depends on report@                234 @script: python depends on report@
235 p << kvmalloc.p;                                  235 p << kvmalloc.p;
236 @@                                                236 @@
237                                                   237 
238 coccilib.report.print_report(p[0], "WARNING op    238 coccilib.report.print_report(p[0], "WARNING opportunity for kvmalloc")
239                                                   239 
240 @script: python depends on org@                   240 @script: python depends on org@
241 p << kvmalloc.p;                                  241 p << kvmalloc.p;
242 @@                                                242 @@
243                                                   243 
244 coccilib.org.print_todo(p[0], "WARNING opportu    244 coccilib.org.print_todo(p[0], "WARNING opportunity for kvmalloc")
245                                                   245 
246 @script: python depends on report@                246 @script: python depends on report@
247 p << kvfree.p;                                    247 p << kvfree.p;
248 @@                                                248 @@
249                                                   249 
250 coccilib.report.print_report(p[0], "WARNING op    250 coccilib.report.print_report(p[0], "WARNING opportunity for kvfree")
251                                                   251 
252 @script: python depends on org@                   252 @script: python depends on org@
253 p << kvfree.p;                                    253 p << kvfree.p;
254 @@                                                254 @@
255                                                   255 
256 coccilib.org.print_todo(p[0], "WARNING opportu    256 coccilib.org.print_todo(p[0], "WARNING opportunity for kvfree")
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php