aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-08-02 16:48:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-08-02 16:48:52 -0400
commit44cee85a8824464e7e951e590243c2a85d79c494 (patch)
tree0ee07cb0a45f7fd9658b0460c288e52ffaf5c4b3 /scripts
parentf716a85cd6045c994011268223706642cff7e485 (diff)
parent4c586062b275dcddc18f521ac092cf0f600a36de (diff)
Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
Pull misc kbuild updates from Michal Marek: - coccicheck script improvements by Luis Rodriguez and Deepa Dinamani - new coccinelle patches by Yann Droneaud and Vaishali Thakkar - debian packaging fixes by Wilfried Klaebe, Henning Schild and Marcin Mielniczuk * 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild: Fix the Debian packaging script on systems with no codename builddeb: fix file permissions before packaging scripts/coccinelle: require coccinelle >= 1.0.4 on device_node_continue.cocci coccicheck: refer to Documentation/coccinelle.txt and wiki coccicheck: add support for requring a coccinelle version scripts: add Linux .cocciconfig for coccinelle coccicheck: replace --very-quiet with --quiet when debugging coccicheck: add support for DEBUG_FILE coccicheck: enable parmap support coccicheck: make SPFLAGS more useful coccicheck: move spatch binary check up builddeb: really include objtool binary in headers package coccinelle: catch krealloc() on devm_*() allocated memory coccinelle: recognize more devm_* memory allocation functions coccinelle: also catch kzfree() issues coccicheck: Allow for overriding spatch flags Coccinelle: noderef: Add new rules and correct the old rule
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/coccicheck96
-rw-r--r--scripts/coccinelle/free/devm_free.cocci26
-rw-r--r--scripts/coccinelle/free/ifnullfree.cocci4
-rw-r--r--scripts/coccinelle/free/kfree.cocci18
-rw-r--r--scripts/coccinelle/free/kfreeaddr.cocci6
-rw-r--r--scripts/coccinelle/iterators/device_node_continue.cocci3
-rw-r--r--scripts/coccinelle/misc/noderef.cocci18
-rwxr-xr-xscripts/package/builddeb11
8 files changed, 162 insertions, 20 deletions
diff --git a/scripts/coccicheck b/scripts/coccicheck
index dd85a455b2ba..c92c1528a54d 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -1,14 +1,24 @@
1#!/bin/bash 1#!/bin/bash
2 2# Linux kernel coccicheck
3#
4# Read Documentation/coccinelle.txt
3# 5#
4# This script requires at least spatch 6# This script requires at least spatch
5# version 1.0.0-rc11. 7# version 1.0.0-rc11.
6#
7 8
9DIR="$(dirname $(readlink -f $0))/.."
8SPATCH="`which ${SPATCH:=spatch}`" 10SPATCH="`which ${SPATCH:=spatch}`"
9 11
10trap kill_running SIGTERM SIGINT 12if [ ! -x "$SPATCH" ]; then
11declare -a SPATCH_PID 13 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
14 exit 1
15fi
16
17SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
18SPATCH_VERSION_NUM=$(echo $SPATCH_VERSION | ${DIR}/scripts/ld-version.sh)
19
20USE_JOBS="no"
21$SPATCH --help | grep "\-\-jobs" > /dev/null && USE_JOBS="yes"
12 22
13# The verbosity may be set by the environmental parameter V= 23# The verbosity may be set by the environmental parameter V=
14# as for example with 'make V=1 coccicheck' 24# as for example with 'make V=1 coccicheck'
@@ -25,7 +35,28 @@ else
25 NPROC="$J" 35 NPROC="$J"
26fi 36fi
27 37
28FLAGS="$SPFLAGS --very-quiet" 38FLAGS="--very-quiet"
39
40# You can use SPFLAGS to append extra arguments to coccicheck or override any
41# heuristics done in this file as Coccinelle accepts the last options when
42# options conflict.
43#
44# A good example for use of SPFLAGS is if you want to debug your cocci script,
45# you can for instance use the following:
46#
47# $ export COCCI=scripts/coccinelle/misc/irqf_oneshot.cocci
48# $ make coccicheck MODE=report DEBUG_FILE="all.err" SPFLAGS="--profile --show-trying" M=./drivers/mfd/arizona-irq.c
49#
50# "--show-trying" should show you what rule is being processed as it goes to
51# stdout, you do not need a debug file for that. The profile output will be
52# be sent to stdout, if you provide a DEBUG_FILE the profiling data can be
53# inspected there.
54#
55# --profile will not output if --very-quiet is used, so avoid it.
56echo $SPFLAGS | egrep -e "--profile|--show-trying" 2>&1 > /dev/null
57if [ $? -eq 0 ]; then
58 FLAGS="--quiet"
59fi
29 60
30# spatch only allows include directories with the syntax "-I include" 61# spatch only allows include directories with the syntax "-I include"
31# while gcc also allows "-Iinclude" and "-include include" 62# while gcc also allows "-Iinclude" and "-include include"
@@ -51,9 +82,14 @@ if [ "$KBUILD_EXTMOD" != "" ] ; then
51 OPTIONS="--patch $srctree $OPTIONS" 82 OPTIONS="--patch $srctree $OPTIONS"
52fi 83fi
53 84
54if [ ! -x "$SPATCH" ]; then 85# You can override by using SPFLAGS
55 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' 86if [ "$USE_JOBS" = "no" ]; then
56 exit 1 87 trap kill_running SIGTERM SIGINT
88 declare -a SPATCH_PID
89elif [ "$NPROC" != "1" ]; then
90 # Using 0 should work as well, refer to _SC_NPROCESSORS_ONLN use on
91 # https://github.com/rdicosmo/parmap/blob/master/setcore_stubs.c
92 OPTIONS="$OPTIONS --jobs $NPROC --chunksize 1"
57fi 93fi
58 94
59if [ "$MODE" = "" ] ; then 95if [ "$MODE" = "" ] ; then
@@ -72,7 +108,7 @@ if [ "$MODE" = "chain" ] ; then
72 echo 'All available modes will be tried (in that order): patch, report, context, org' 108 echo 'All available modes will be tried (in that order): patch, report, context, org'
73 fi 109 fi
74elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then 110elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
75 FLAGS="$FLAGS --no-show-diff" 111 FLAGS="--no-show-diff $FLAGS"
76fi 112fi
77 113
78if [ "$ONLINE" = "0" ] ; then 114if [ "$ONLINE" = "0" ] ; then
@@ -82,7 +118,26 @@ if [ "$ONLINE" = "0" ] ; then
82 echo '' 118 echo ''
83fi 119fi
84 120
85run_cmd() { 121run_cmd_parmap() {
122 if [ $VERBOSE -ne 0 ] ; then
123 echo "Running ($NPROC in parallel): $@"
124 fi
125 if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then
126 if [ -f $DEBUG_FILE ]; then
127 echo "Debug file $DEBUG_FILE exists, bailing"
128 exit
129 fi
130 else
131 DEBUG_FILE="/dev/null"
132 fi
133 $@ 2>$DEBUG_FILE
134 if [[ $? -ne 0 ]]; then
135 echo "coccicheck failed"
136 exit $?
137 fi
138}
139
140run_cmd_old() {
86 local i 141 local i
87 if [ $VERBOSE -ne 0 ] ; then 142 if [ $VERBOSE -ne 0 ] ; then
88 echo "Running ($NPROC in parallel): $@" 143 echo "Running ($NPROC in parallel): $@"
@@ -97,6 +152,14 @@ run_cmd() {
97 wait 152 wait
98} 153}
99 154
155run_cmd() {
156 if [ "$USE_JOBS" = "yes" ]; then
157 run_cmd_parmap $@
158 else
159 run_cmd_old $@
160 fi
161}
162
100kill_running() { 163kill_running() {
101 for i in $(seq 0 $(( NPROC - 1 )) ); do 164 for i in $(seq 0 $(( NPROC - 1 )) ); do
102 if [ $VERBOSE -eq 2 ] ; then 165 if [ $VERBOSE -eq 2 ] ; then
@@ -106,10 +169,23 @@ kill_running() {
106 done 169 done
107} 170}
108 171
172# You can override heuristics with SPFLAGS, these must always go last
173OPTIONS="$OPTIONS $SPFLAGS"
174
109coccinelle () { 175coccinelle () {
110 COCCI="$1" 176 COCCI="$1"
111 177
112 OPT=`grep "Option" $COCCI | cut -d':' -f2` 178 OPT=`grep "Option" $COCCI | cut -d':' -f2`
179 REQ=`grep "Requires" $COCCI | cut -d':' -f2 | sed "s| ||"`
180 REQ_NUM=$(echo $REQ | ${DIR}/scripts/ld-version.sh)
181 if [ "$REQ_NUM" != "0" ] ; then
182 if [ "$SPATCH_VERSION_NUM" -lt "$REQ_NUM" ] ; then
183 echo "Skipping coccinele SmPL patch: $COCCI"
184 echo "You have coccinelle: $SPATCH_VERSION"
185 echo "This SmPL patch requires: $REQ"
186 return
187 fi
188 fi
113 189
114# The option '--parse-cocci' can be used to syntactically check the SmPL files. 190# The option '--parse-cocci' can be used to syntactically check the SmPL files.
115# 191#
diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci
index 3d9349012bb3..c990d2c7ee16 100644
--- a/scripts/coccinelle/free/devm_free.cocci
+++ b/scripts/coccinelle/free/devm_free.cocci
@@ -29,8 +29,24 @@ expression x;
29@@ 29@@
30 30
31( 31(
32 x = devm_kmalloc(...)
33|
34 x = devm_kvasprintf(...)
35|
36 x = devm_kasprintf(...)
37|
32 x = devm_kzalloc(...) 38 x = devm_kzalloc(...)
33| 39|
40 x = devm_kmalloc_array(...)
41|
42 x = devm_kcalloc(...)
43|
44 x = devm_kstrdup(...)
45|
46 x = devm_kmemdup(...)
47|
48 x = devm_get_free_pages(...)
49|
34 x = devm_request_irq(...) 50 x = devm_request_irq(...)
35| 51|
36 x = devm_ioremap(...) 52 x = devm_ioremap(...)
@@ -48,6 +64,16 @@ position p;
48( 64(
49* kfree@p(x) 65* kfree@p(x)
50| 66|
67* kzfree@p(x)
68|
69* __krealloc@p(x, ...)
70|
71* krealloc@p(x, ...)
72|
73* free_pages@p(x, ...)
74|
75* free_page@p(x)
76|
51* free_irq@p(x) 77* free_irq@p(x)
52| 78|
53* iounmap@p(x) 79* iounmap@p(x)
diff --git a/scripts/coccinelle/free/ifnullfree.cocci b/scripts/coccinelle/free/ifnullfree.cocci
index 52bd235286fa..14a4cd98e83b 100644
--- a/scripts/coccinelle/free/ifnullfree.cocci
+++ b/scripts/coccinelle/free/ifnullfree.cocci
@@ -20,6 +20,8 @@ expression E;
20( 20(
21 kfree(E); 21 kfree(E);
22| 22|
23 kzfree(E);
24|
23 debugfs_remove(E); 25 debugfs_remove(E);
24| 26|
25 debugfs_remove_recursive(E); 27 debugfs_remove_recursive(E);
@@ -39,7 +41,7 @@ position p;
39@@ 41@@
40 42
41* if (E != NULL) 43* if (E != NULL)
42* \(kfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\| 44* \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|
43* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\| 45* usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\|
44* dma_pool_destroy@p\)(E); 46* dma_pool_destroy@p\)(E);
45 47
diff --git a/scripts/coccinelle/free/kfree.cocci b/scripts/coccinelle/free/kfree.cocci
index 577b78056990..ac438da4fd7b 100644
--- a/scripts/coccinelle/free/kfree.cocci
+++ b/scripts/coccinelle/free/kfree.cocci
@@ -20,7 +20,11 @@ expression E;
20position p1; 20position p1;
21@@ 21@@
22 22
23kfree@p1(E) 23(
24* kfree@p1(E)
25|
26* kzfree@p1(E)
27)
24 28
25@print expression@ 29@print expression@
26constant char [] c; 30constant char [] c;
@@ -60,7 +64,11 @@ position ok;
60@@ 64@@
61 65
62while (1) { ... 66while (1) { ...
63 kfree@ok(E) 67(
68* kfree@ok(E)
69|
70* kzfree@ok(E)
71)
64 ... when != break; 72 ... when != break;
65 when != goto l; 73 when != goto l;
66 when forall 74 when forall
@@ -74,7 +82,11 @@ statement S;
74position free.p1!=loop.ok,p2!={print.p,sz.p}; 82position free.p1!=loop.ok,p2!={print.p,sz.p};
75@@ 83@@
76 84
77kfree@p1(E,...) 85(
86* kfree@p1(E,...)
87|
88* kzfree@p1(E,...)
89)
78... 90...
79( 91(
80 iter(...,subE,...) S // no use 92 iter(...,subE,...) S // no use
diff --git a/scripts/coccinelle/free/kfreeaddr.cocci b/scripts/coccinelle/free/kfreeaddr.cocci
index ce8aacc314cb..d46063b1db8b 100644
--- a/scripts/coccinelle/free/kfreeaddr.cocci
+++ b/scripts/coccinelle/free/kfreeaddr.cocci
@@ -16,7 +16,11 @@ identifier f;
16position p; 16position p;
17@@ 17@@
18 18
19(
19* kfree@p(&e->f) 20* kfree@p(&e->f)
21|
22* kzfree@p(&e->f)
23)
20 24
21@script:python depends on org@ 25@script:python depends on org@
22p << r.p; 26p << r.p;
@@ -28,5 +32,5 @@ cocci.print_main("kfree",p)
28p << r.p; 32p << r.p;
29@@ 33@@
30 34
31msg = "ERROR: kfree of structure field" 35msg = "ERROR: invalid free of structure field"
32coccilib.report.print_report(p[0],msg) 36coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/iterators/device_node_continue.cocci b/scripts/coccinelle/iterators/device_node_continue.cocci
index 38ab744a4037..a36c16db171b 100644
--- a/scripts/coccinelle/iterators/device_node_continue.cocci
+++ b/scripts/coccinelle/iterators/device_node_continue.cocci
@@ -5,8 +5,11 @@
5// Copyright: (C) 2015 Julia Lawall, Inria. GPLv2. 5// Copyright: (C) 2015 Julia Lawall, Inria. GPLv2.
6// URL: http://coccinelle.lip6.fr/ 6// URL: http://coccinelle.lip6.fr/
7// Options: --no-includes --include-headers 7// Options: --no-includes --include-headers
8// Requires: 1.0.4
8// Keywords: for_each_child_of_node, etc. 9// Keywords: for_each_child_of_node, etc.
9 10
11// This uses a conjunction, which requires at least coccinelle >= 1.0.4
12
10virtual patch 13virtual patch
11virtual context 14virtual context
12virtual org 15virtual org
diff --git a/scripts/coccinelle/misc/noderef.cocci b/scripts/coccinelle/misc/noderef.cocci
index 80a831c91161..007f0de0c715 100644
--- a/scripts/coccinelle/misc/noderef.cocci
+++ b/scripts/coccinelle/misc/noderef.cocci
@@ -16,6 +16,7 @@ virtual patch
16@depends on patch@ 16@depends on patch@
17expression *x; 17expression *x;
18expression f; 18expression f;
19expression i;
19type T; 20type T;
20@@ 21@@
21 22
@@ -30,15 +31,26 @@ f(...,(T)(x),...,sizeof(
30+ *x 31+ *x
31 ),...) 32 ),...)
32| 33|
33f(...,sizeof(x),...,(T)( 34f(...,sizeof(
35- x
36+ *x
37 ),...,(T)(x),...)
38|
39f(...,(T)(x),...,i*sizeof(
34- x 40- x
35+ *x 41+ *x
36 ),...) 42 ),...)
43|
44f(...,i*sizeof(
45- x
46+ *x
47 ),...,(T)(x),...)
37) 48)
38 49
39@r depends on !patch@ 50@r depends on !patch@
40expression *x; 51expression *x;
41expression f; 52expression f;
53expression i;
42position p; 54position p;
43type T; 55type T;
44@@ 56@@
@@ -49,6 +61,10 @@ type T;
49*f(...,(T)(x),...,sizeof@p(x),...) 61*f(...,(T)(x),...,sizeof@p(x),...)
50| 62|
51*f(...,sizeof@p(x),...,(T)(x),...) 63*f(...,sizeof@p(x),...,(T)(x),...)
64|
65*f(...,(T)(x),...,i*sizeof@p(x),...)
66|
67*f(...,i*sizeof@p(x),...,(T)(x),...)
52) 68)
53 69
54@script:python depends on org@ 70@script:python depends on org@
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 4d4418a8d54d..e1c09e2f9be7 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -26,6 +26,8 @@ create_package() {
26 # Fix ownership and permissions 26 # Fix ownership and permissions
27 chown -R root:root "$pdir" 27 chown -R root:root "$pdir"
28 chmod -R go-w "$pdir" 28 chmod -R go-w "$pdir"
29 # in case we are in a restrictive umask environment like 0077
30 chmod -R a+rX "$pdir"
29 31
30 # Create the package 32 # Create the package
31 dpkg-gencontrol $forcearch -Vkernel:debarch="${debarch}" -p$pname -P"$pdir" 33 dpkg-gencontrol $forcearch -Vkernel:debarch="${debarch}" -p$pname -P"$pdir"
@@ -238,7 +240,8 @@ maintainer="$name <$email>"
238# Try to determine distribution 240# Try to determine distribution
239if [ -n "$KDEB_CHANGELOG_DIST" ]; then 241if [ -n "$KDEB_CHANGELOG_DIST" ]; then
240 distribution=$KDEB_CHANGELOG_DIST 242 distribution=$KDEB_CHANGELOG_DIST
241elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ]; then 243# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
244elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
242 : # nothing to do in this case 245 : # nothing to do in this case
243else 246else
244 distribution="unstable" 247 distribution="unstable"
@@ -322,12 +325,12 @@ fi
322 325
323# Build kernel header package 326# Build kernel header package
324(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles" 327(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles"
325if grep -q '^CONFIG_STACK_VALIDATION=y' $KCONFIG_CONFIG ; then
326 (cd $srctree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrsrcfiles"
327fi
328(cd $srctree; find arch/*/include include scripts -type f) >> "$objtree/debian/hdrsrcfiles" 328(cd $srctree; find arch/*/include include scripts -type f) >> "$objtree/debian/hdrsrcfiles"
329(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" 329(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
330(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" 330(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
331if grep -q '^CONFIG_STACK_VALIDATION=y' $KCONFIG_CONFIG ; then
332 (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles"
333fi
331(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" 334(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
332(cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles" 335(cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
333destdir=$kernel_headers_dir/usr/src/linux-headers-$version 336destdir=$kernel_headers_dir/usr/src/linux-headers-$version