1 /// Use setup_timer function instead of initializing timer with the function
4 // Copyright: (C) 2016 Vaishali Thakkar, Oracle. GPLv2
5 // Copyright: (C) 2017 Kees Cook, Google. GPLv2
6 // Options: --no-includes --include-headers
7 // Keywords: init_timer, setup_timer
14 // Match the common cases first to avoid Coccinelle parsing loops with
15 // "... when" clauses.
17 @match_immediate_function_data_after_init_timer
18 depends on patch && !context && !org && !report@
19 expression e, func, da;
28 -\(e.function\|e->function\) = func;
29 -\(e.data\|e->data\) = da;
31 -\(e.data\|e->data\) = da;
32 -\(e.function\|e->function\) = func;
35 @match_immediate_function_data_before_init_timer
36 depends on patch && !context && !org && !report@
37 expression e, func, da;
41 -\(e.function\|e->function\) = func;
42 -\(e.data\|e->data\) = da;
44 -\(e.data\|e->data\) = da;
45 -\(e.function\|e->function\) = func;
53 @match_function_and_data_after_init_timer
54 depends on patch && !context && !org && !report@
55 expression e, e2, e3, e4, e5, func, da;
83 @match_function_and_data_before_init_timer
84 depends on patch && !context && !org && !report@
85 expression e, e2, e3, e4, e5, func, da;
101 ... when != func = e5
104 ... when != func = e2
118 f(...) { ... when any
119 init_timer@p(\(&t\|t\))
125 identifier g != r1.f;
129 g(...) { ... when any
130 \(t.data\|t->data\) = e8
134 // It is dangerous to use setup_timer if data field is initialized
135 // in another function.
137 @script:python depends on r2@
141 cocci.include_match(False)
143 @r3 depends on patch && !context && !org && !report@
144 expression r1.t, func, e7;
150 +setup_timer(&t, func, 0UL);
151 ... when != func = e7
155 ... when != func = e7
157 +setup_timer(&t, func, 0UL);
160 +setup_timer(t, func, 0UL);
161 ... when != func = e7
165 ... when != func = e7
167 +setup_timer(t, func, 0UL);
170 // ----------------------------------------------------------------------------
172 @match_immediate_function_data_after_init_timer_context
173 depends on !patch && (context || org || report)@
174 expression da, e, func;
178 * init_timer@j0 (&e);
180 * e@j1.function = func;
184 * e@j2.function = func;
187 @match_function_and_data_after_init_timer_context
188 depends on !patch && (context || org || report)@
189 expression a, b, e1, e2, e3, e4, e5;
190 position j0 != match_immediate_function_data_after_init_timer_context.j0,j1,j2;
193 * init_timer@j0 (&e1);
197 * e1@j1.function = a;
203 * e1@j2.function = a;
206 @r3_context depends on !patch && (context || org || report)@
207 expression c, e6, e7;
210 {match_immediate_function_data_after_init_timer_context.j0,
211 match_function_and_data_after_init_timer_context.j0}, j1;
214 * init_timer@j0@p (&e6);
216 * e6@j1.function = c;
218 // ----------------------------------------------------------------------------
220 @script:python match_immediate_function_data_after_init_timer_org
222 j0 << match_immediate_function_data_after_init_timer_context.j0;
223 j1 << match_immediate_function_data_after_init_timer_context.j1;
224 j2 << match_immediate_function_data_after_init_timer_context.j2;
227 msg = "Use setup_timer function."
228 coccilib.org.print_todo(j0[0], msg)
229 coccilib.org.print_link(j1[0], "")
230 coccilib.org.print_link(j2[0], "")
232 @script:python match_function_and_data_after_init_timer_org depends on org@
233 j0 << match_function_and_data_after_init_timer_context.j0;
234 j1 << match_function_and_data_after_init_timer_context.j1;
235 j2 << match_function_and_data_after_init_timer_context.j2;
238 msg = "Use setup_timer function."
239 coccilib.org.print_todo(j0[0], msg)
240 coccilib.org.print_link(j1[0], "")
241 coccilib.org.print_link(j2[0], "")
243 @script:python r3_org depends on org@
248 msg = "Use setup_timer function."
249 coccilib.org.print_todo(j0[0], msg)
250 coccilib.org.print_link(j1[0], "")
252 // ----------------------------------------------------------------------------
254 @script:python match_immediate_function_data_after_init_timer_report
256 j0 << match_immediate_function_data_after_init_timer_context.j0;
257 j1 << match_immediate_function_data_after_init_timer_context.j1;
260 msg = "Use setup_timer function for function on line %s." % (j1[0].line)
261 coccilib.report.print_report(j0[0], msg)
263 @script:python match_function_and_data_after_init_timer_report depends on report@
264 j0 << match_function_and_data_after_init_timer_context.j0;
265 j1 << match_function_and_data_after_init_timer_context.j1;
268 msg = "Use setup_timer function for function on line %s." % (j1[0].line)
269 coccilib.report.print_report(j0[0], msg)
271 @script:python r3_report depends on report@
276 msg = "Use setup_timer function for function on line %s." % (j1[0].line)
277 coccilib.report.print_report(j0[0], msg)