aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2017-09-20 19:27:25 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2017-11-14 09:19:03 -0500
commit1b18d05c7c204a59e0ac66cbfa813a7173c4426e (patch)
tree61566a79f4428305e3aa7feb453bb9713edf8ff9
parentbc27b77df1939b9567aa468c47d4a5784f40cfa1 (diff)
coccinelle: Improve setup_timer.cocci matching
This improves the patch mode of setup_timer.cocci. Several patterns were missing: - assignments-before-init_timer() cases - limit the .data case removal to the specific struct timer_list instance - handling calls by dereference (timer->field vs timer.field) Cc: Gilles Muller <Gilles.Muller@lip6.fr> Cc: Nicolas Palix <nicolas.palix@imag.fr> Cc: Michal Marek <mmarek@suse.com> Cc: cocci@systeme.lip6.fr Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
-rw-r--r--scripts/coccinelle/api/setup_timer.cocci129
1 files changed, 105 insertions, 24 deletions
diff --git a/scripts/coccinelle/api/setup_timer.cocci b/scripts/coccinelle/api/setup_timer.cocci
index b5ab0317fa03..e4577089dcb9 100644
--- a/scripts/coccinelle/api/setup_timer.cocci
+++ b/scripts/coccinelle/api/setup_timer.cocci
@@ -2,6 +2,7 @@
2/// and data fields 2/// and data fields
3// Confidence: High 3// Confidence: High
4// Copyright: (C) 2016 Vaishali Thakkar, Oracle. GPLv2 4// Copyright: (C) 2016 Vaishali Thakkar, Oracle. GPLv2
5// Copyright: (C) 2017 Kees Cook, Google. GPLv2
5// Options: --no-includes --include-headers 6// Options: --no-includes --include-headers
6// Keywords: init_timer, setup_timer 7// Keywords: init_timer, setup_timer
7 8
@@ -10,60 +11,123 @@ virtual context
10virtual org 11virtual org
11virtual report 12virtual report
12 13
14// Match the common cases first to avoid Coccinelle parsing loops with
15// "... when" clauses.
16
13@match_immediate_function_data_after_init_timer 17@match_immediate_function_data_after_init_timer
14depends on patch && !context && !org && !report@ 18depends on patch && !context && !org && !report@
15expression e, func, da; 19expression e, func, da;
16@@ 20@@
17 21
18-init_timer (&e); 22-init_timer
19+setup_timer (&e, func, da); 23+setup_timer
24 ( \(&e\|e\)
25+, func, da
26 );
27(
28-\(e.function\|e->function\) = func;
29-\(e.data\|e->data\) = da;
30|
31-\(e.data\|e->data\) = da;
32-\(e.function\|e->function\) = func;
33)
34
35@match_immediate_function_data_before_init_timer
36depends on patch && !context && !org && !report@
37expression e, func, da;
38@@
20 39
21( 40(
41-\(e.function\|e->function\) = func;
42-\(e.data\|e->data\) = da;
43|
44-\(e.data\|e->data\) = da;
45-\(e.function\|e->function\) = func;
46)
47-init_timer
48+setup_timer
49 ( \(&e\|e\)
50+, func, da
51 );
52
53@match_function_and_data_after_init_timer
54depends on patch && !context && !org && !report@
55expression e, e2, e3, e4, e5, func, da;
56@@
57
58-init_timer
59+setup_timer
60 ( \(&e\|e\)
61+, func, da
62 );
63 ... when != func = e2
64 when != da = e3
65(
22-e.function = func; 66-e.function = func;
67... when != da = e4
23-e.data = da; 68-e.data = da;
24| 69|
70-e->function = func;
71... when != da = e4
72-e->data = da;
73|
25-e.data = da; 74-e.data = da;
75... when != func = e5
26-e.function = func; 76-e.function = func;
77|
78-e->data = da;
79... when != func = e5
80-e->function = func;
27) 81)
28 82
29@match_function_and_data_after_init_timer 83@match_function_and_data_before_init_timer
30depends on patch && !context && !org && !report@ 84depends on patch && !context && !org && !report@
31expression e1, e2, e3, e4, e5, a, b; 85expression e, e2, e3, e4, e5, func, da;
32@@ 86@@
33
34-init_timer (&e1);
35+setup_timer (&e1, a, b);
36
37... when != a = e2
38 when != b = e3
39( 87(
40-e1.function = a; 88-e.function = func;
41... when != b = e4 89... when != da = e4
42-e1.data = b; 90-e.data = da;
43| 91|
44-e1.data = b; 92-e->function = func;
45... when != a = e5 93... when != da = e4
46-e1.function = a; 94-e->data = da;
95|
96-e.data = da;
97... when != func = e5
98-e.function = func;
99|
100-e->data = da;
101... when != func = e5
102-e->function = func;
47) 103)
104... when != func = e2
105 when != da = e3
106-init_timer
107+setup_timer
108 ( \(&e\|e\)
109+, func, da
110 );
48 111
49@r1 exists@ 112@r1 exists@
113expression t;
50identifier f; 114identifier f;
51position p; 115position p;
52@@ 116@@
53 117
54f(...) { ... when any 118f(...) { ... when any
55 init_timer@p(...) 119 init_timer@p(\(&t\|t\))
56 ... when any 120 ... when any
57} 121}
58 122
59@r2 exists@ 123@r2 exists@
124expression r1.t;
60identifier g != r1.f; 125identifier g != r1.f;
61struct timer_list t;
62expression e8; 126expression e8;
63@@ 127@@
64 128
65g(...) { ... when any 129g(...) { ... when any
66 t.data = e8 130 \(t.data\|t->data\) = e8
67 ... when any 131 ... when any
68} 132}
69 133
@@ -77,14 +141,31 @@ p << r1.p;
77cocci.include_match(False) 141cocci.include_match(False)
78 142
79@r3 depends on patch && !context && !org && !report@ 143@r3 depends on patch && !context && !org && !report@
80expression e6, e7, c; 144expression r1.t, func, e7;
81position r1.p; 145position r1.p;
82@@ 146@@
83 147
84-init_timer@p (&e6); 148(
85+setup_timer (&e6, c, 0UL); 149-init_timer@p(&t);
86... when != c = e7 150+setup_timer(&t, func, 0UL);
87-e6.function = c; 151... when != func = e7
152-t.function = func;
153|
154-t.function = func;
155... when != func = e7
156-init_timer@p(&t);
157+setup_timer(&t, func, 0UL);
158|
159-init_timer@p(t);
160+setup_timer(t, func, 0UL);
161... when != func = e7
162-t->function = func;
163|
164-t->function = func;
165... when != func = e7
166-init_timer@p(t);
167+setup_timer(t, func, 0UL);
168)
88 169
89// ---------------------------------------------------------------------------- 170// ----------------------------------------------------------------------------
90 171