aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccicheck
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-10 19:08:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-10 19:08:06 -0400
commitae9249493049fd41fa52fc0470251ee1efaabe74 (patch)
treecad8b206dda4caec111877a762f8f590702257de /scripts/coccicheck
parentb202c0d5205662fd96f7151afa83f891f2f4d542 (diff)
parentec97946ed038f4b3faa587bc76152b198805b0c4 (diff)
Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
Pull coccinelle updates from Michal Marek: "The misc branch is reserved for Coccinelle this time: - 'report' is the default mode - MAINTAINERS update for Coccinelle - documentation udate - use new option format for spatch(1) - J=<n> variable to mimic make -j for coccicheck - check for missing pci_free_consistent() calls There are some patches for rpm-pkg and deb-pkg waiting for the 3.12-rc1 merge window" * 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild: Coccinelle: Update information about the minimal version required Coccinelle: Update the options used to the new option scheme scripts: Coccinelle script for pci_free_consistent() Coccinelle: Update the documentation Coccinelle: Update section of MAINTAINERS coccicheck: span checks across CPUs scripts/coccinelle: check for field address argument to kfree Coccinelle: Update the Coccinelle section of MAINTAINERS Coccinelle: Make 'report' the default mode
Diffstat (limited to 'scripts/coccicheck')
-rwxr-xr-xscripts/coccicheck76
1 files changed, 57 insertions, 19 deletions
diff --git a/scripts/coccicheck b/scripts/coccicheck
index 06fcb3333247..bbf901afb606 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -1,17 +1,31 @@
1#!/bin/bash 1#!/bin/bash
2 2
3#
4# This script requires at least spatch
5# version 1.0.0-rc11.
6#
7
3SPATCH="`which ${SPATCH:=spatch}`" 8SPATCH="`which ${SPATCH:=spatch}`"
4 9
10trap kill_running SIGTERM SIGINT
11declare -a SPATCH_PID
12
5# The verbosity may be set by the environmental parameter V= 13# The verbosity may be set by the environmental parameter V=
6# as for example with 'make V=1 coccicheck' 14# as for example with 'make V=1 coccicheck'
7 15
8if [ -n "$V" -a "$V" != "0" ]; then 16if [ -n "$V" -a "$V" != "0" ]; then
9 VERBOSE=1 17 VERBOSE="$V"
10else 18else
11 VERBOSE=0 19 VERBOSE=0
12fi 20fi
13 21
14FLAGS="$SPFLAGS -very_quiet" 22if [ -z "$J" ]; then
23 NPROC=$(getconf _NPROCESSORS_ONLN)
24else
25 NPROC="$J"
26fi
27
28FLAGS="$SPFLAGS --very-quiet"
15 29
16# spatch only allows include directories with the syntax "-I include" 30# spatch only allows include directories with the syntax "-I include"
17# while gcc also allows "-Iinclude" and "-include include" 31# while gcc also allows "-Iinclude" and "-include include"
@@ -27,14 +41,14 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
27else 41else
28 ONLINE=0 42 ONLINE=0
29 if [ "$KBUILD_EXTMOD" = "" ] ; then 43 if [ "$KBUILD_EXTMOD" = "" ] ; then
30 OPTIONS="-dir $srctree $COCCIINCLUDE" 44 OPTIONS="--dir $srctree $COCCIINCLUDE"
31 else 45 else
32 OPTIONS="-dir $KBUILD_EXTMOD $COCCIINCLUDE" 46 OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
33 fi 47 fi
34fi 48fi
35 49
36if [ "$KBUILD_EXTMOD" != "" ] ; then 50if [ "$KBUILD_EXTMOD" != "" ] ; then
37 OPTIONS="-patch $srctree $OPTIONS" 51 OPTIONS="--patch $srctree $OPTIONS"
38fi 52fi
39 53
40if [ ! -x "$SPATCH" ]; then 54if [ ! -x "$SPATCH" ]; then
@@ -44,13 +58,21 @@ fi
44 58
45if [ "$MODE" = "" ] ; then 59if [ "$MODE" = "" ] ; then
46 if [ "$ONLINE" = "0" ] ; then 60 if [ "$ONLINE" = "0" ] ; then
47 echo 'You have not explicitly specified the mode to use. Using default "chain" mode.' 61 echo 'You have not explicitly specified the mode to use. Using default "report" mode.'
48 echo 'All available modes will be tried (in that order): patch, report, context, org' 62 echo 'Available modes are the following: patch, report, context, org'
49 echo 'You can specify the mode with "make coccicheck MODE=<mode>"' 63 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
64 echo 'Note however that some modes are not implemented by some semantic patches.'
65 fi
66 MODE="report"
67fi
68
69if [ "$MODE" = "chain" ] ; then
70 if [ "$ONLINE" = "0" ] ; then
71 echo 'You have selected the "chain" mode.'
72 echo 'All available modes will be tried (in that order): patch, report, context, org'
50 fi 73 fi
51 MODE="chain"
52elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then 74elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
53 FLAGS="$FLAGS -no_show_diff" 75 FLAGS="$FLAGS --no-show-diff"
54fi 76fi
55 77
56if [ "$ONLINE" = "0" ] ; then 78if [ "$ONLINE" = "0" ] ; then
@@ -61,19 +83,35 @@ if [ "$ONLINE" = "0" ] ; then
61fi 83fi
62 84
63run_cmd() { 85run_cmd() {
86 local i
64 if [ $VERBOSE -ne 0 ] ; then 87 if [ $VERBOSE -ne 0 ] ; then
65 echo "Running: $@" 88 echo "Running ($NPROC in parallel): $@"
66 fi 89 fi
67 eval $@ 90 for i in $(seq 0 $(( NPROC - 1)) ); do
91 eval "$@ --max $NPROC --index $i &"
92 SPATCH_PID[$i]=$!
93 if [ $VERBOSE -eq 2 ] ; then
94 echo "${SPATCH_PID[$i]} running"
95 fi
96 done
97 wait
68} 98}
69 99
100kill_running() {
101 for i in $(seq $(( NPROC - 1 )) ); do
102 if [ $VERBOSE -eq 2 ] ; then
103 echo "Killing ${SPATCH_PID[$i]}"
104 fi
105 kill ${SPATCH_PID[$i]} 2>/dev/null
106 done
107}
70 108
71coccinelle () { 109coccinelle () {
72 COCCI="$1" 110 COCCI="$1"
73 111
74 OPT=`grep "Option" $COCCI | cut -d':' -f2` 112 OPT=`grep "Option" $COCCI | cut -d':' -f2`
75 113
76# The option '-parse_cocci' can be used to syntactically check the SmPL files. 114# The option '--parse-cocci' can be used to syntactically check the SmPL files.
77# 115#
78# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null 116# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
79 117
@@ -114,20 +152,20 @@ coccinelle () {
114 152
115 if [ "$MODE" = "chain" ] ; then 153 if [ "$MODE" = "chain" ] ; then
116 run_cmd $SPATCH -D patch \ 154 run_cmd $SPATCH -D patch \
117 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ 155 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || \
118 run_cmd $SPATCH -D report \ 156 run_cmd $SPATCH -D report \
119 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ 157 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || \
120 run_cmd $SPATCH -D context \ 158 run_cmd $SPATCH -D context \
121 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ 159 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || \
122 run_cmd $SPATCH -D org \ 160 run_cmd $SPATCH -D org \
123 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 161 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit 1
124 elif [ "$MODE" = "rep+ctxt" ] ; then 162 elif [ "$MODE" = "rep+ctxt" ] ; then
125 run_cmd $SPATCH -D report \ 163 run_cmd $SPATCH -D report \
126 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ 164 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
127 run_cmd $SPATCH -D context \ 165 run_cmd $SPATCH -D context \
128 $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 166 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
129 else 167 else
130 run_cmd $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 168 run_cmd $SPATCH -D $MODE $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
131 fi 169 fi
132 170
133} 171}