b5ab0317fa031dec9b4806d6abef02391b242ac1
[sfrench/cifs-2.6.git] / scripts / coccinelle / api / setup_timer.cocci
1 /// Use setup_timer function instead of initializing timer with the function
2 /// and data fields
3 // Confidence: High
4 // Copyright: (C) 2016 Vaishali Thakkar, Oracle. GPLv2
5 // Options: --no-includes --include-headers
6 // Keywords: init_timer, setup_timer
7
8 virtual patch
9 virtual context
10 virtual org
11 virtual report
12
13 @match_immediate_function_data_after_init_timer
14 depends on patch && !context && !org && !report@
15 expression e, func, da;
16 @@
17
18 -init_timer (&e);
19 +setup_timer (&e, func, da);
20
21 (
22 -e.function = func;
23 -e.data = da;
24 |
25 -e.data = da;
26 -e.function = func;
27 )
28
29 @match_function_and_data_after_init_timer
30 depends on patch && !context && !org && !report@
31 expression e1, e2, e3, e4, e5, a, b;
32 @@
33
34 -init_timer (&e1);
35 +setup_timer (&e1, a, b);
36
37 ... when != a = e2
38     when != b = e3
39 (
40 -e1.function = a;
41 ... when != b = e4
42 -e1.data = b;
43 |
44 -e1.data = b;
45 ... when != a = e5
46 -e1.function = a;
47 )
48
49 @r1 exists@
50 identifier f;
51 position p;
52 @@
53
54 f(...) { ... when any
55   init_timer@p(...)
56   ... when any
57 }
58
59 @r2 exists@
60 identifier g != r1.f;
61 struct timer_list t;
62 expression e8;
63 @@
64
65 g(...) { ... when any
66   t.data = e8
67   ... when any
68 }
69
70 // It is dangerous to use setup_timer if data field is initialized
71 // in another function.
72
73 @script:python depends on r2@
74 p << r1.p;
75 @@
76
77 cocci.include_match(False)
78
79 @r3 depends on patch && !context && !org && !report@
80 expression e6, e7, c;
81 position r1.p;
82 @@
83
84 -init_timer@p (&e6);
85 +setup_timer (&e6, c, 0UL);
86 ... when != c = e7
87 -e6.function = c;
88
89 // ----------------------------------------------------------------------------
90
91 @match_immediate_function_data_after_init_timer_context
92 depends on !patch && (context || org || report)@
93 expression da, e, func;
94 position j0, j1, j2;
95 @@
96
97 * init_timer@j0 (&e);
98 (
99 * e@j1.function = func;
100 * e@j2.data = da;
101 |
102 * e@j1.data = da;
103 * e@j2.function = func;
104 )
105
106 @match_function_and_data_after_init_timer_context
107 depends on !patch && (context || org || report)@
108 expression a, b, e1, e2, e3, e4, e5;
109 position j0 != match_immediate_function_data_after_init_timer_context.j0,j1,j2;
110 @@
111
112 * init_timer@j0 (&e1);
113 ... when != a = e2
114     when != b = e3
115 (
116 * e1@j1.function = a;
117 ... when != b = e4
118 * e1@j2.data = b;
119 |
120 * e1@j1.data = b;
121 ... when != a = e5
122 * e1@j2.function = a;
123 )
124
125 @r3_context depends on !patch && (context || org || report)@
126 expression c, e6, e7;
127 position r1.p;
128 position j0 !=
129   {match_immediate_function_data_after_init_timer_context.j0,
130    match_function_and_data_after_init_timer_context.j0}, j1;
131 @@
132
133 * init_timer@j0@p (&e6);
134 ... when != c = e7
135 * e6@j1.function = c;
136
137 // ----------------------------------------------------------------------------
138
139 @script:python match_immediate_function_data_after_init_timer_org
140 depends on org@
141 j0 << match_immediate_function_data_after_init_timer_context.j0;
142 j1 << match_immediate_function_data_after_init_timer_context.j1;
143 j2 << match_immediate_function_data_after_init_timer_context.j2;
144 @@
145
146 msg = "Use setup_timer function."
147 coccilib.org.print_todo(j0[0], msg)
148 coccilib.org.print_link(j1[0], "")
149 coccilib.org.print_link(j2[0], "")
150
151 @script:python match_function_and_data_after_init_timer_org depends on org@
152 j0 << match_function_and_data_after_init_timer_context.j0;
153 j1 << match_function_and_data_after_init_timer_context.j1;
154 j2 << match_function_and_data_after_init_timer_context.j2;
155 @@
156
157 msg = "Use setup_timer function."
158 coccilib.org.print_todo(j0[0], msg)
159 coccilib.org.print_link(j1[0], "")
160 coccilib.org.print_link(j2[0], "")
161
162 @script:python r3_org depends on org@
163 j0 << r3_context.j0;
164 j1 << r3_context.j1;
165 @@
166
167 msg = "Use setup_timer function."
168 coccilib.org.print_todo(j0[0], msg)
169 coccilib.org.print_link(j1[0], "")
170
171 // ----------------------------------------------------------------------------
172
173 @script:python match_immediate_function_data_after_init_timer_report
174 depends on report@
175 j0 << match_immediate_function_data_after_init_timer_context.j0;
176 j1 << match_immediate_function_data_after_init_timer_context.j1;
177 @@
178
179 msg = "Use setup_timer function for function on line %s." % (j1[0].line)
180 coccilib.report.print_report(j0[0], msg)
181
182 @script:python match_function_and_data_after_init_timer_report depends on report@
183 j0 << match_function_and_data_after_init_timer_context.j0;
184 j1 << match_function_and_data_after_init_timer_context.j1;
185 @@
186
187 msg = "Use setup_timer function for function on line %s." % (j1[0].line)
188 coccilib.report.print_report(j0[0], msg)
189
190 @script:python r3_report depends on report@
191 j0 << r3_context.j0;
192 j1 << r3_context.j1;
193 @@
194
195 msg = "Use setup_timer function for function on line %s." % (j1[0].line)
196 coccilib.report.print_report(j0[0], msg)