aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/misc
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /scripts/coccinelle/misc
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'scripts/coccinelle/misc')
-rw-r--r--scripts/coccinelle/misc/boolinit.cocci178
-rw-r--r--scripts/coccinelle/misc/cstptr.cocci41
-rw-r--r--scripts/coccinelle/misc/doubleinit.cocci8
-rw-r--r--scripts/coccinelle/misc/ifaddr.cocci35
-rw-r--r--scripts/coccinelle/misc/irqf_oneshot.cocci65
-rw-r--r--scripts/coccinelle/misc/noderef.cocci65
-rw-r--r--scripts/coccinelle/misc/warn.cocci109
7 files changed, 4 insertions, 497 deletions
diff --git a/scripts/coccinelle/misc/boolinit.cocci b/scripts/coccinelle/misc/boolinit.cocci
deleted file mode 100644
index 97ce41ce813..00000000000
--- a/scripts/coccinelle/misc/boolinit.cocci
+++ /dev/null
@@ -1,178 +0,0 @@
1/// Bool initializations should use true and false. Bool tests don't need
2/// comparisons. Based on contributions from Joe Perches, Rusty Russell
3/// and Bruce W Allan.
4///
5// Confidence: High
6// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/
9// Options: -include_headers
10
11virtual patch
12virtual context
13virtual org
14virtual report
15
16@depends on patch@
17bool t;
18symbol true;
19symbol false;
20@@
21
22(
23- t == true
24+ t
25|
26- true == t
27+ t
28|
29- t != true
30+ !t
31|
32- true != t
33+ !t
34|
35- t == false
36+ !t
37|
38- false == t
39+ !t
40|
41- t != false
42+ t
43|
44- false != t
45+ t
46)
47
48@depends on patch disable is_zero, isnt_zero@
49bool t;
50@@
51
52(
53- t == 1
54+ t
55|
56- t != 1
57+ !t
58|
59- t == 0
60+ !t
61|
62- t != 0
63+ t
64)
65
66@depends on patch@
67bool b;
68@@
69(
70 b =
71- 0
72+ false
73|
74 b =
75- 1
76+ true
77)
78
79// ---------------------------------------------------------------------
80
81@r1 depends on !patch@
82bool t;
83position p;
84@@
85
86(
87* t@p == true
88|
89* true == t@p
90|
91* t@p != true
92|
93* true != t@p
94|
95* t@p == false
96|
97* false == t@p
98|
99* t@p != false
100|
101* false != t@p
102)
103
104@r2 depends on !patch disable is_zero, isnt_zero@
105bool t;
106position p;
107@@
108
109(
110* t@p == 1
111|
112* t@p != 1
113|
114* t@p == 0
115|
116* t@p != 0
117)
118
119@r3 depends on !patch@
120bool b;
121position p1,p2;
122constant c;
123@@
124(
125*b@p1 = 0
126|
127*b@p1 = 1
128|
129*b@p2 = c
130)
131
132@script:python depends on org@
133p << r1.p;
134@@
135
136cocci.print_main("WARNING: Comparison to bool",p)
137
138@script:python depends on org@
139p << r2.p;
140@@
141
142cocci.print_main("WARNING: Comparison of bool to 0/1",p)
143
144@script:python depends on org@
145p1 << r3.p1;
146@@
147
148cocci.print_main("WARNING: Assignment of bool to 0/1",p1)
149
150@script:python depends on org@
151p2 << r3.p2;
152@@
153
154cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2)
155
156@script:python depends on report@
157p << r1.p;
158@@
159
160coccilib.report.print_report(p[0],"WARNING: Comparison to bool")
161
162@script:python depends on report@
163p << r2.p;
164@@
165
166coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1")
167
168@script:python depends on report@
169p1 << r3.p1;
170@@
171
172coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1")
173
174@script:python depends on report@
175p2 << r3.p2;
176@@
177
178coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant")
diff --git a/scripts/coccinelle/misc/cstptr.cocci b/scripts/coccinelle/misc/cstptr.cocci
deleted file mode 100644
index d4256448452..00000000000
--- a/scripts/coccinelle/misc/cstptr.cocci
+++ /dev/null
@@ -1,41 +0,0 @@
1/// PTR_ERR should be applied before its argument is reassigned, typically
2/// to NULL
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Comments:
9// Options: -no_includes -include_headers
10
11virtual org
12virtual report
13virtual context
14
15@r exists@
16expression e,e1;
17constant c;
18position p1,p2;
19@@
20
21*e@p1 = c
22... when != e = e1
23 when != &e
24 when != true IS_ERR(e)
25*PTR_ERR@p2(e)
26
27@script:python depends on org@
28p1 << r.p1;
29p2 << r.p2;
30@@
31
32cocci.print_main("PTR_ERR",p2)
33cocci.print_secs("assignment",p1)
34
35@script:python depends on report@
36p1 << r.p1;
37p2 << r.p2;
38@@
39
40msg = "ERROR: PTR_ERR applied after initialization to constant on line %s" % (p1[0].line)
41coccilib.report.print_report(p2[0],msg)
diff --git a/scripts/coccinelle/misc/doubleinit.cocci b/scripts/coccinelle/misc/doubleinit.cocci
index cf74a00cf59..156b20adb35 100644
--- a/scripts/coccinelle/misc/doubleinit.cocci
+++ b/scripts/coccinelle/misc/doubleinit.cocci
@@ -3,9 +3,9 @@
3/// initialization. 3/// initialization.
4/// 4///
5// Confidence: Low 5// Confidence: Low
6// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2. 6// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
7// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2. 7// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
8// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/ 9// URL: http://coccinelle.lip6.fr/
10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise 10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
11// Options: -no_includes -include_headers 11// Options: -no_includes -include_headers
@@ -49,5 +49,5 @@ pr << r.p;
49@@ 49@@
50 50
51if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)): 51if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)):
52 msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line) 52 msg = "%s: first occurrence %s, second occurrence %s" % (fld,ps[0].line,pr[0].line)
53 coccilib.report.print_report(p0[0],msg) 53 coccilib.report.print_report(p0[0],msg)
diff --git a/scripts/coccinelle/misc/ifaddr.cocci b/scripts/coccinelle/misc/ifaddr.cocci
deleted file mode 100644
index 3e4089a7700..00000000000
--- a/scripts/coccinelle/misc/ifaddr.cocci
+++ /dev/null
@@ -1,35 +0,0 @@
1/// the address of a variable or field is non-zero is likely always to bo
2/// non-zero
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Comments:
9// Options: -no_includes -include_headers
10
11virtual org
12virtual report
13virtual context
14
15@r@
16expression x;
17statement S1,S2;
18position p;
19@@
20
21*if@p (&x)
22 S1 else S2
23
24@script:python depends on org@
25p << r.p;
26@@
27
28cocci.print_main("test of a variable/field address",p)
29
30@script:python depends on report@
31p << r.p;
32@@
33
34msg = "ERROR: test of a variable/field address"
35coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/irqf_oneshot.cocci b/scripts/coccinelle/misc/irqf_oneshot.cocci
deleted file mode 100644
index 6cfde94be0e..00000000000
--- a/scripts/coccinelle/misc/irqf_oneshot.cocci
+++ /dev/null
@@ -1,65 +0,0 @@
1/// Make sure threaded IRQs without a primary handler are always request with
2/// IRQF_ONESHOT
3///
4//
5// Confidence: Good
6// Comments:
7// Options: --no-includes
8
9virtual patch
10virtual context
11virtual org
12virtual report
13
14@r1@
15expression irq;
16expression thread_fn;
17expression flags;
18position p;
19@@
20request_threaded_irq@p(irq, NULL, thread_fn,
21(
22flags | IRQF_ONESHOT
23|
24IRQF_ONESHOT
25)
26, ...)
27
28@depends on patch@
29expression irq;
30expression thread_fn;
31expression flags;
32position p != r1.p;
33@@
34request_threaded_irq@p(irq, NULL, thread_fn,
35(
36-0
37+IRQF_ONESHOT
38|
39-flags
40+flags | IRQF_ONESHOT
41)
42, ...)
43
44@depends on context@
45position p != r1.p;
46@@
47*request_threaded_irq@p(...)
48
49@match depends on report || org@
50expression irq;
51position p != r1.p;
52@@
53request_threaded_irq@p(irq, NULL, ...)
54
55@script:python depends on org@
56p << match.p;
57@@
58msg = "ERROR: Threaded IRQ with no primary handler requested without IRQF_ONESHOT"
59coccilib.org.print_todo(p[0],msg)
60
61@script:python depends on report@
62p << match.p;
63@@
64msg = "ERROR: Threaded IRQ with no primary handler requested without IRQF_ONESHOT"
65coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/noderef.cocci b/scripts/coccinelle/misc/noderef.cocci
deleted file mode 100644
index c1707214e60..00000000000
--- a/scripts/coccinelle/misc/noderef.cocci
+++ /dev/null
@@ -1,65 +0,0 @@
1/// sizeof when applied to a pointer typed expression gives the size of
2/// the pointer
3///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Comments:
9// Options: -no_includes -include_headers
10
11virtual org
12virtual report
13virtual context
14virtual patch
15
16@depends on patch@
17expression *x;
18expression f;
19type T;
20@@
21
22(
23x = <+... sizeof(
24- x
25+ *x
26 ) ...+>
27|
28f(...,(T)(x),...,sizeof(
29- x
30+ *x
31 ),...)
32|
33f(...,sizeof(x),...,(T)(
34- x
35+ *x
36 ),...)
37)
38
39@r depends on !patch@
40expression *x;
41expression f;
42position p;
43type T;
44@@
45
46(
47*x = <+... sizeof@p(x) ...+>
48|
49*f(...,(T)(x),...,sizeof@p(x),...)
50|
51*f(...,sizeof@p(x),...,(T)(x),...)
52)
53
54@script:python depends on org@
55p << r.p;
56@@
57
58cocci.print_main("application of sizeof to pointer",p)
59
60@script:python depends on report@
61p << r.p;
62@@
63
64msg = "ERROR: application of sizeof to pointer"
65coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/warn.cocci b/scripts/coccinelle/misc/warn.cocci
deleted file mode 100644
index fda8c3558e4..00000000000
--- a/scripts/coccinelle/misc/warn.cocci
+++ /dev/null
@@ -1,109 +0,0 @@
1/// Use WARN(1,...) rather than printk followed by WARN_ON(1)
2///
3// Confidence: High
4// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
5// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
6// URL: http://coccinelle.lip6.fr/
7// Comments:
8// Options: -no_includes -include_headers
9
10virtual patch
11virtual context
12virtual org
13virtual report
14
15@bad1@
16position p;
17@@
18
19printk(...);
20printk@p(...);
21WARN_ON(1);
22
23@r1 depends on context || report || org@
24position p != bad1.p;
25@@
26
27 printk@p(...);
28*WARN_ON(1);
29
30@script:python depends on org@
31p << r1.p;
32@@
33
34cocci.print_main("printk + WARN_ON can be just WARN",p)
35
36@script:python depends on report@
37p << r1.p;
38@@
39
40msg = "SUGGESTION: printk + WARN_ON can be just WARN"
41coccilib.report.print_report(p[0],msg)
42
43@ok1 depends on patch@
44expression list es;
45position p != bad1.p;
46@@
47
48-printk@p(
49+WARN(1,
50 es);
51-WARN_ON(1);
52
53@depends on patch@
54expression list ok1.es;
55@@
56
57if (...)
58- {
59 WARN(1,es);
60- }
61
62// --------------------------------------------------------------------
63
64@bad2@
65position p;
66@@
67
68printk(...);
69printk@p(...);
70WARN_ON_ONCE(1);
71
72@r2 depends on context || report || org@
73position p != bad1.p;
74@@
75
76 printk@p(...);
77*WARN_ON_ONCE(1);
78
79@script:python depends on org@
80p << r2.p;
81@@
82
83cocci.print_main("printk + WARN_ON_ONCE can be just WARN_ONCE",p)
84
85@script:python depends on report@
86p << r2.p;
87@@
88
89msg = "SUGGESTION: printk + WARN_ON_ONCE can be just WARN_ONCE"
90coccilib.report.print_report(p[0],msg)
91
92@ok2 depends on patch@
93expression list es;
94position p != bad2.p;
95@@
96
97-printk@p(
98+WARN_ONCE(1,
99 es);
100-WARN_ON_ONCE(1);
101
102@depends on patch@
103expression list ok2.es;
104@@
105
106if (...)
107- {
108 WARN_ONCE(1,es);
109- }