diff options
-rw-r--r-- | Documentation/coccinelle.txt | 4 | ||||
-rwxr-xr-x | scripts/coccicheck | 39 | ||||
-rw-r--r-- | scripts/coccinelle/misc/memcpy-assign.cocci | 103 | ||||
-rw-r--r-- | scripts/coccinelle/misc/orplus.cocci | 55 | ||||
-rw-r--r-- | scripts/coccinelle/misc/semicolon.cocci | 83 | ||||
-rwxr-xr-x | scripts/package/mkspec | 2 | ||||
-rwxr-xr-x | scripts/tags.sh | 50 |
7 files changed, 302 insertions, 34 deletions
diff --git a/Documentation/coccinelle.txt b/Documentation/coccinelle.txt index cf44eb6499b4..dffa2d620d6d 100644 --- a/Documentation/coccinelle.txt +++ b/Documentation/coccinelle.txt | |||
@@ -87,6 +87,10 @@ As any static code analyzer, Coccinelle produces false | |||
87 | positives. Thus, reports must be carefully checked, and patches | 87 | positives. Thus, reports must be carefully checked, and patches |
88 | reviewed. | 88 | reviewed. |
89 | 89 | ||
90 | To enable verbose messages set the V= variable, for example: | ||
91 | |||
92 | make coccicheck MODE=report V=1 | ||
93 | |||
90 | 94 | ||
91 | Using Coccinelle with a single semantic patch | 95 | Using Coccinelle with a single semantic patch |
92 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 96 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
diff --git a/scripts/coccicheck b/scripts/coccicheck index 1a49d1c7ecfe..85d31899ad98 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck | |||
@@ -2,6 +2,15 @@ | |||
2 | 2 | ||
3 | SPATCH="`which ${SPATCH:=spatch}`" | 3 | SPATCH="`which ${SPATCH:=spatch}`" |
4 | 4 | ||
5 | # The verbosity may be set by the environmental parameter V= | ||
6 | # as for example with 'make V=1 coccicheck' | ||
7 | |||
8 | if [ -n "$V" -a "$V" != "0" ]; then | ||
9 | VERBOSE=1 | ||
10 | else | ||
11 | VERBOSE=0 | ||
12 | fi | ||
13 | |||
5 | if [ "$C" = "1" -o "$C" = "2" ]; then | 14 | if [ "$C" = "1" -o "$C" = "2" ]; then |
6 | ONLINE=1 | 15 | ONLINE=1 |
7 | 16 | ||
@@ -46,6 +55,14 @@ if [ "$ONLINE" = "0" ] ; then | |||
46 | echo '' | 55 | echo '' |
47 | fi | 56 | fi |
48 | 57 | ||
58 | run_cmd() { | ||
59 | if [ $VERBOSE -ne 0 ] ; then | ||
60 | echo "Running: $@" | ||
61 | fi | ||
62 | eval $@ | ||
63 | } | ||
64 | |||
65 | |||
49 | coccinelle () { | 66 | coccinelle () { |
50 | COCCI="$1" | 67 | COCCI="$1" |
51 | 68 | ||
@@ -55,7 +72,7 @@ coccinelle () { | |||
55 | # | 72 | # |
56 | # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null | 73 | # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null |
57 | 74 | ||
58 | if [ "$ONLINE" = "0" ] ; then | 75 | if [ $VERBOSE -ne 0 ] ; then |
59 | 76 | ||
60 | FILE=`echo $COCCI | sed "s|$srctree/||"` | 77 | FILE=`echo $COCCI | sed "s|$srctree/||"` |
61 | 78 | ||
@@ -91,15 +108,21 @@ coccinelle () { | |||
91 | fi | 108 | fi |
92 | 109 | ||
93 | if [ "$MODE" = "chain" ] ; then | 110 | if [ "$MODE" = "chain" ] ; then |
94 | $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | 111 | run_cmd $SPATCH -D patch \ |
95 | $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ | 112 | $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ |
96 | $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | 113 | run_cmd $SPATCH -D report \ |
97 | $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 | 114 | $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ |
115 | run_cmd $SPATCH -D context \ | ||
116 | $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | ||
117 | run_cmd $SPATCH -D org \ | ||
118 | $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 | ||
98 | elif [ "$MODE" = "rep+ctxt" ] ; then | 119 | elif [ "$MODE" = "rep+ctxt" ] ; then |
99 | $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ | 120 | run_cmd $SPATCH -D report \ |
100 | $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 | 121 | $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ |
122 | run_cmd $SPATCH -D context \ | ||
123 | $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 | ||
101 | else | 124 | else |
102 | $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 | 125 | run_cmd $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
103 | fi | 126 | fi |
104 | 127 | ||
105 | } | 128 | } |
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 | |||
10 | virtual patch | ||
11 | virtual report | ||
12 | virtual context | ||
13 | virtual org | ||
14 | |||
15 | @r1 depends on !patch@ | ||
16 | identifier struct_name; | ||
17 | struct struct_name to; | ||
18 | struct struct_name from; | ||
19 | struct struct_name *top; | ||
20 | struct struct_name *fromp; | ||
21 | position p; | ||
22 | @@ | ||
23 | memcpy@p(\(&(to)\|top\), \(&(from)\|fromp\), \(sizeof(to)\|sizeof(from)\|sizeof(struct struct_name)\|sizeof(*top)\|sizeof(*fromp)\)) | ||
24 | |||
25 | @script:python depends on report@ | ||
26 | p << r1.p; | ||
27 | @@ | ||
28 | coccilib.report.print_report(p[0],"Replace memcpy with struct assignment") | ||
29 | |||
30 | @depends on context@ | ||
31 | position r1.p; | ||
32 | @@ | ||
33 | *memcpy@p(...); | ||
34 | |||
35 | @script:python depends on org@ | ||
36 | p << r1.p; | ||
37 | @@ | ||
38 | cocci.print_main("Replace memcpy with struct assignment",p) | ||
39 | |||
40 | @depends on patch@ | ||
41 | identifier struct_name; | ||
42 | struct struct_name to; | ||
43 | struct 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@ | ||
57 | identifier struct_name; | ||
58 | struct struct_name to; | ||
59 | struct 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@ | ||
73 | identifier struct_name; | ||
74 | struct struct_name *to; | ||
75 | struct 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@ | ||
89 | identifier struct_name; | ||
90 | struct struct_name *to; | ||
91 | struct 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 | |||
12 | virtual org | ||
13 | virtual report | ||
14 | virtual context | ||
15 | |||
16 | @r@ | ||
17 | constant c; | ||
18 | identifier i; | ||
19 | expression e; | ||
20 | @@ | ||
21 | |||
22 | ( | ||
23 | e | c@i | ||
24 | | | ||
25 | e & c@i | ||
26 | | | ||
27 | e |= c@i | ||
28 | | | ||
29 | e &= c@i | ||
30 | ) | ||
31 | |||
32 | @s@ | ||
33 | constant r.c,c1; | ||
34 | identifier i1; | ||
35 | position p; | ||
36 | @@ | ||
37 | |||
38 | ( | ||
39 | c1 + c - 1 | ||
40 | | | ||
41 | *c1@i1 +@p c | ||
42 | ) | ||
43 | |||
44 | @script:python depends on org@ | ||
45 | p << s.p; | ||
46 | @@ | ||
47 | |||
48 | cocci.print_main("sum of probable bitmasks, consider |",p) | ||
49 | |||
50 | @script:python depends on report@ | ||
51 | p << s.p; | ||
52 | @@ | ||
53 | |||
54 | msg = "WARNING: sum of probable bitmasks, consider |" | ||
55 | coccilib.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 | |||
10 | virtual patch | ||
11 | virtual report | ||
12 | virtual context | ||
13 | virtual org | ||
14 | |||
15 | @r_default@ | ||
16 | position p; | ||
17 | @@ | ||
18 | switch (...) | ||
19 | { | ||
20 | default: ...;@p | ||
21 | } | ||
22 | |||
23 | @r_case@ | ||
24 | position p; | ||
25 | @@ | ||
26 | ( | ||
27 | switch (...) | ||
28 | { | ||
29 | case ...:;@p | ||
30 | } | ||
31 | | | ||
32 | switch (...) | ||
33 | { | ||
34 | case ...:... | ||
35 | case ...:;@p | ||
36 | } | ||
37 | | | ||
38 | switch (...) | ||
39 | { | ||
40 | case ...:... | ||
41 | case ...: | ||
42 | case ...:;@p | ||
43 | } | ||
44 | ) | ||
45 | |||
46 | @r1@ | ||
47 | statement S; | ||
48 | position p1; | ||
49 | position p != {r_default.p, r_case.p}; | ||
50 | identifier label; | ||
51 | @@ | ||
52 | ( | ||
53 | label:; | ||
54 | | | ||
55 | S@p1;@p | ||
56 | ) | ||
57 | |||
58 | @script:python@ | ||
59 | p << r1.p; | ||
60 | p1 << r1.p1; | ||
61 | @@ | ||
62 | if p[0].line != p1[0].line_end: | ||
63 | cocci.include_match(False) | ||
64 | |||
65 | @depends on patch@ | ||
66 | position r1.p; | ||
67 | @@ | ||
68 | -;@p | ||
69 | |||
70 | @script:python depends on report@ | ||
71 | p << r1.p; | ||
72 | @@ | ||
73 | coccilib.report.print_report(p[0],"Unneeded semicolon") | ||
74 | |||
75 | @depends on context@ | ||
76 | position r1.p; | ||
77 | @@ | ||
78 | *;@p | ||
79 | |||
80 | @script:python depends on org@ | ||
81 | p << r1.p; | ||
82 | @@ | ||
83 | cocci.print_main("Unneeded semicolon",p) | ||
diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 4bf17ddf7c7f..fbbfd08853d3 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec | |||
@@ -95,7 +95,7 @@ echo 'cp $KBUILD_IMAGE $RPM_BUILD_ROOT'"/boot/vmlinuz-$KERNELRELEASE" | |||
95 | echo "%endif" | 95 | echo "%endif" |
96 | echo "%endif" | 96 | echo "%endif" |
97 | 97 | ||
98 | echo 'make %{?_smp_mflags} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr headers_install' | 98 | echo 'make %{?_smp_mflags} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install' |
99 | echo 'cp System.map $RPM_BUILD_ROOT'"/boot/System.map-$KERNELRELEASE" | 99 | echo 'cp System.map $RPM_BUILD_ROOT'"/boot/System.map-$KERNELRELEASE" |
100 | 100 | ||
101 | echo 'cp .config $RPM_BUILD_ROOT'"/boot/config-$KERNELRELEASE" | 101 | echo 'cp .config $RPM_BUILD_ROOT'"/boot/config-$KERNELRELEASE" |
diff --git a/scripts/tags.sh b/scripts/tags.sh index 65f9595acea9..26a87e68afed 100755 --- a/scripts/tags.sh +++ b/scripts/tags.sh | |||
@@ -217,34 +217,34 @@ exuberant() | |||
217 | emacs() | 217 | emacs() |
218 | { | 218 | { |
219 | all_target_sources | xargs $1 -a \ | 219 | all_target_sources | xargs $1 -a \ |
220 | --regex='/^(ENTRY|_GLOBAL)(\([^)]*\)).*/\2/' \ | 220 | --regex='/^\(ENTRY\|_GLOBAL\)(\([^)]*\)).*/\2/' \ |
221 | --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' \ | 221 | --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' \ |
222 | --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/' \ | 222 | --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/' \ |
223 | --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/' \ | 223 | --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/' \ |
224 | --regex='/PAGEFLAG\(([^,)]*).*/Page\1/' \ | 224 | --regex='/PAGEFLAG(\([^,)]*\).*/Page\1/' \ |
225 | --regex='/PAGEFLAG\(([^,)]*).*/SetPage\1/' \ | 225 | --regex='/PAGEFLAG(\([^,)]*\).*/SetPage\1/' \ |
226 | --regex='/PAGEFLAG\(([^,)]*).*/ClearPage\1/' \ | 226 | --regex='/PAGEFLAG(\([^,)]*\).*/ClearPage\1/' \ |
227 | --regex='/TESTSETFLAG\(([^,)]*).*/TestSetPage\1/' \ | 227 | --regex='/TESTSETFLAG(\([^,)]*\).*/TestSetPage\1/' \ |
228 | --regex='/TESTPAGEFLAG\(([^,)]*).*/Page\1/' \ | 228 | --regex='/TESTPAGEFLAG(\([^,)]*\).*/Page\1/' \ |
229 | --regex='/SETPAGEFLAG\(([^,)]*).*/SetPage\1/' \ | 229 | --regex='/SETPAGEFLAG(\([^,)]*\).*/SetPage\1/' \ |
230 | --regex='/__SETPAGEFLAG\(([^,)]*).*/__SetPage\1/' \ | 230 | --regex='/__SETPAGEFLAG(\([^,)]*\).*/__SetPage\1/' \ |
231 | --regex='/TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \ | 231 | --regex='/TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \ |
232 | --regex='/__TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \ | 232 | --regex='/__TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \ |
233 | --regex='/CLEARPAGEFLAG\(([^,)]*).*/ClearPage\1/' \ | 233 | --regex='/CLEARPAGEFLAG(\([^,)]*\).*/ClearPage\1/' \ |
234 | --regex='/__CLEARPAGEFLAG\(([^,)]*).*/__ClearPage\1/' \ | 234 | --regex='/__CLEARPAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \ |
235 | --regex='/__PAGEFLAG\(([^,)]*).*/__SetPage\1/' \ | 235 | --regex='/__PAGEFLAG(\([^,)]*\).*/__SetPage\1/' \ |
236 | --regex='/__PAGEFLAG\(([^,)]*).*/__ClearPage\1/' \ | 236 | --regex='/__PAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \ |
237 | --regex='/PAGEFLAG_FALSE\(([^,)]*).*/Page\1/' \ | 237 | --regex='/PAGEFLAG_FALSE(\([^,)]*\).*/Page\1/' \ |
238 | --regex='/TESTSCFLAG\(([^,)]*).*/TestSetPage\1/' \ | 238 | --regex='/TESTSCFLAG(\([^,)]*\).*/TestSetPage\1/' \ |
239 | --regex='/TESTSCFLAG\(([^,)]*).*/TestClearPage\1/' \ | 239 | --regex='/TESTSCFLAG(\([^,)]*\).*/TestClearPage\1/' \ |
240 | --regex='/SETPAGEFLAG_NOOP\(([^,)]*).*/SetPage\1/' \ | 240 | --regex='/SETPAGEFLAG_NOOP(\([^,)]*\).*/SetPage\1/' \ |
241 | --regex='/CLEARPAGEFLAG_NOOP\(([^,)]*).*/ClearPage\1/' \ | 241 | --regex='/CLEARPAGEFLAG_NOOP(\([^,)]*\).*/ClearPage\1/' \ |
242 | --regex='/__CLEARPAGEFLAG_NOOP\(([^,)]*).*/__ClearPage\1/' \ | 242 | --regex='/__CLEARPAGEFLAG_NOOP(\([^,)]*\).*/__ClearPage\1/' \ |
243 | --regex='/TESTCLEARFLAG_FALSE\(([^,)]*).*/TestClearPage\1/' \ | 243 | --regex='/TESTCLEARFLAG_FALSE(\([^,)]*\).*/TestClearPage\1/' \ |
244 | --regex='/__TESTCLEARFLAG_FALSE\(([^,)]*).*/__TestClearPage\1/' \ | 244 | --regex='/__TESTCLEARFLAG_FALSE(\([^,)]*\).*/__TestClearPage\1/' \ |
245 | --regex='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' \ | 245 | --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' \ |
246 | --regex='/PCI_OP_READ\(([a-z]*[a-z]).*[1-4]\)/pci_bus_read_config_\1/' \ | 246 | --regex='/PCI_OP_READ(\([a-z]*[a-z]\).*[1-4])/pci_bus_read_config_\1/' \ |
247 | --regex='/PCI_OP_WRITE\(([a-z]*[a-z]).*[1-4]\)/pci_bus_write_config_\1/' | 247 | --regex='/PCI_OP_WRITE(\([a-z]*[a-z]\).*[1-4])/pci_bus_write_config_\1/' |
248 | 248 | ||
249 | all_kconfigs | xargs $1 -a \ | 249 | all_kconfigs | xargs $1 -a \ |
250 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/' | 250 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/' |