aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 15:27:18 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 15:27:18 -0500
commitad60a9333035f2323840b71ab8ad07bbab728faf (patch)
treec0bee7557b62a0c1c26ede9cb26f1a1785cfd04c /scripts/coccinelle
parent0ca7ffb356063c5ece847687da457dfe748612a2 (diff)
parent24f0c2d6ff859fbca45fd765f0d241528bdb4365 (diff)
Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
Pull misc non-critical kbuild changes from Michal Marek: - Fix for make TAGS - Fix for make rpm - Some new coccinelle semantic patches * 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild: scripts/coccinelle: find constant additions that could be bit ors coccicheck: Allow to show the executed command line coccicheck: Allow the user to give a V= (verbose) argument scripts/coccinelle/misc/memcpy-assign.cocci: Replace memcpy with struct assignment kbuild: clear KBUILD_SRC when calling 'make' in RPM spec scripts/coccinelle/misc/semicolon.cocci: Add unneeded semicolon test scripts/tags.sh: Fix regex syntax for etags
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r--scripts/coccinelle/misc/memcpy-assign.cocci103
-rw-r--r--scripts/coccinelle/misc/orplus.cocci55
-rw-r--r--scripts/coccinelle/misc/semicolon.cocci83
3 files changed, 241 insertions, 0 deletions
diff --git a/scripts/coccinelle/misc/memcpy-assign.cocci b/scripts/coccinelle/misc/memcpy-assign.cocci
new file mode 100644
index 000000000000..afd058be497f
--- /dev/null
+++ b/scripts/coccinelle/misc/memcpy-assign.cocci
@@ -0,0 +1,103 @@
1//
2// Replace memcpy with struct assignment.
3//
4// Confidence: High
5// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. GPLv2.
6// URL: http://coccinelle.lip6.fr/
7// Comments:
8// Options: --no-includes --include-headers
9
10virtual patch
11virtual report
12virtual context
13virtual org
14
15@r1 depends on !patch@
16identifier struct_name;
17struct struct_name to;
18struct struct_name from;
19struct struct_name *top;
20struct struct_name *fromp;
21position p;
22@@
23memcpy@p(\(&(to)\|top\), \(&(from)\|fromp\), \(sizeof(to)\|sizeof(from)\|sizeof(struct struct_name)\|sizeof(*top)\|sizeof(*fromp)\))
24
25@script:python depends on report@
26p << r1.p;
27@@
28coccilib.report.print_report(p[0],"Replace memcpy with struct assignment")
29
30@depends on context@
31position r1.p;
32@@
33*memcpy@p(...);
34
35@script:python depends on org@
36p << r1.p;
37@@
38cocci.print_main("Replace memcpy with struct assignment",p)
39
40@depends on patch@
41identifier struct_name;
42struct struct_name to;
43struct struct_name from;
44@@
45(
46-memcpy(&(to), &(from), sizeof(to));
47+to = from;
48|
49-memcpy(&(to), &(from), sizeof(from));
50+to = from;
51|
52-memcpy(&(to), &(from), sizeof(struct struct_name));
53+to = from;
54)
55
56@depends on patch@
57identifier struct_name;
58struct struct_name to;
59struct struct_name *from;
60@@
61(
62-memcpy(&(to), from, sizeof(to));
63+to = *from;
64|
65-memcpy(&(to), from, sizeof(*from));
66+to = *from;
67|
68-memcpy(&(to), from, sizeof(struct struct_name));
69+to = *from;
70)
71
72@depends on patch@
73identifier struct_name;
74struct struct_name *to;
75struct struct_name from;
76@@
77(
78-memcpy(to, &(from), sizeof(*to));
79+ *to = from;
80|
81-memcpy(to, &(from), sizeof(from));
82+ *to = from;
83|
84-memcpy(to, &(from), sizeof(struct struct_name));
85+ *to = from;
86)
87
88@depends on patch@
89identifier struct_name;
90struct struct_name *to;
91struct struct_name *from;
92@@
93(
94-memcpy(to, from, sizeof(*to));
95+ *to = *from;
96|
97-memcpy(to, from, sizeof(*from));
98+ *to = *from;
99|
100-memcpy(to, from, sizeof(struct struct_name));
101+ *to = *from;
102)
103
diff --git a/scripts/coccinelle/misc/orplus.cocci b/scripts/coccinelle/misc/orplus.cocci
new file mode 100644
index 000000000000..4a28cef1484e
--- /dev/null
+++ b/scripts/coccinelle/misc/orplus.cocci
@@ -0,0 +1,55 @@
1/// Check for constants that are added but are used elsewhere as bitmasks
2/// The results should be checked manually to ensure that the nonzero
3/// bits in the two constants are actually disjoint.
4///
5// Confidence: Moderate
6// Copyright: (C) 2013 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2013 Gilles Muller, INRIA/LIP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/
9// Comments:
10// Options: -no_includes -include_headers
11
12virtual org
13virtual report
14virtual context
15
16@r@
17constant c;
18identifier i;
19expression e;
20@@
21
22(
23e | c@i
24|
25e & c@i
26|
27e |= c@i
28|
29e &= c@i
30)
31
32@s@
33constant r.c,c1;
34identifier i1;
35position p;
36@@
37
38(
39 c1 + c - 1
40|
41*c1@i1 +@p c
42)
43
44@script:python depends on org@
45p << s.p;
46@@
47
48cocci.print_main("sum of probable bitmasks, consider |",p)
49
50@script:python depends on report@
51p << s.p;
52@@
53
54msg = "WARNING: sum of probable bitmasks, consider |"
55coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/semicolon.cocci b/scripts/coccinelle/misc/semicolon.cocci
new file mode 100644
index 000000000000..a47eba2edc9e
--- /dev/null
+++ b/scripts/coccinelle/misc/semicolon.cocci
@@ -0,0 +1,83 @@
1///
2/// Removes unneeded semicolon.
3///
4// Confidence: Moderate
5// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. GPLv2.
6// URL: http://coccinelle.lip6.fr/
7// Comments: Some false positives on empty default cases in switch statements.
8// Options: --no-includes --include-headers
9
10virtual patch
11virtual report
12virtual context
13virtual org
14
15@r_default@
16position p;
17@@
18switch (...)
19{
20default: ...;@p
21}
22
23@r_case@
24position p;
25@@
26(
27switch (...)
28{
29case ...:;@p
30}
31|
32switch (...)
33{
34case ...:...
35case ...:;@p
36}
37|
38switch (...)
39{
40case ...:...
41case ...:
42case ...:;@p
43}
44)
45
46@r1@
47statement S;
48position p1;
49position p != {r_default.p, r_case.p};
50identifier label;
51@@
52(
53label:;
54|
55S@p1;@p
56)
57
58@script:python@
59p << r1.p;
60p1 << r1.p1;
61@@
62if p[0].line != p1[0].line_end:
63 cocci.include_match(False)
64
65@depends on patch@
66position r1.p;
67@@
68-;@p
69
70@script:python depends on report@
71p << r1.p;
72@@
73coccilib.report.print_report(p[0],"Unneeded semicolon")
74
75@depends on context@
76position r1.p;
77@@
78*;@p
79
80@script:python depends on org@
81p << r1.p;
82@@
83cocci.print_main("Unneeded semicolon",p)