VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100   1) #!/bin/bash
b24413180f560 (Greg Kroah-Hartman    2017-11-01 15:07:57 +0100   2) # SPDX-License-Identifier: GPL-2.0
c100d537b9a08 (Luis R. Rodriguez     2016-06-29 15:14:58 -0700   3) # Linux kernel coccicheck
c100d537b9a08 (Luis R. Rodriguez     2016-06-29 15:14:58 -0700   4) #
1e01892e7ad52 (Markus Elfring        2016-10-07 16:06:15 +0200   5) # Read Documentation/dev-tools/coccinelle.rst
ec97946ed038f (Nicolas Palix         2013-07-03 16:41:01 +0200   6) #
ec97946ed038f (Nicolas Palix         2013-07-03 16:41:01 +0200   7) # This script requires at least spatch
ec97946ed038f (Nicolas Palix         2013-07-03 16:41:01 +0200   8) # version 1.0.0-rc11.
ec97946ed038f (Nicolas Palix         2013-07-03 16:41:01 +0200   9) 
a9e064c00413f (Luis R. Rodriguez     2016-06-29 15:14:57 -0700  10) DIR="$(dirname $(readlink -f $0))/.."
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200  11) SPATCH="`which ${SPATCH:=spatch}`"
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200  12) 
13d9486533729 (Luis R. Rodriguez     2016-06-29 15:14:51 -0700  13) if [ ! -x "$SPATCH" ]; then
13d9486533729 (Luis R. Rodriguez     2016-06-29 15:14:51 -0700  14)     echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
13d9486533729 (Luis R. Rodriguez     2016-06-29 15:14:51 -0700  15)     exit 1
13d9486533729 (Luis R. Rodriguez     2016-06-29 15:14:51 -0700  16) fi
13d9486533729 (Luis R. Rodriguez     2016-06-29 15:14:51 -0700  17) 
a9e064c00413f (Luis R. Rodriguez     2016-06-29 15:14:57 -0700  18) SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
a9e064c00413f (Luis R. Rodriguez     2016-06-29 15:14:57 -0700  19) 
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700  20) USE_JOBS="no"
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700  21) $SPATCH --help | grep "\-\-jobs" > /dev/null && USE_JOBS="yes"
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700  22) 
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  23) # The verbosity may be set by the environmental parameter V=
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  24) # as for example with 'make V=1 coccicheck'
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  25) 
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  26) if [ -n "$V" -a "$V" != "0" ]; then
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700  27) 	VERBOSE="$V"
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  28) else
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  29) 	VERBOSE=0
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  30) fi
26e56720916a2 (Bernd Schubert        2013-01-29 17:03:37 +0100  31) 
8e826ad52b751 (Luis R. Rodriguez     2016-06-29 15:14:52 -0700  32) FLAGS="--very-quiet"
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  33) 
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  34) # You can use SPFLAGS to append extra arguments to coccicheck or override any
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  35) # heuristics done in this file as Coccinelle accepts the last options when
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  36) # options conflict.
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  37) #
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  38) # A good example for use of SPFLAGS is if you want to debug your cocci script,
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  39) # you can for instance use the following:
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  40) #
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  41) # $ export COCCI=scripts/coccinelle/misc/irqf_oneshot.cocci
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  42) # $ make coccicheck MODE=report DEBUG_FILE="all.err" SPFLAGS="--profile --show-trying" M=./drivers/mfd/arizona-irq.c
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  43) #
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  44) # "--show-trying" should show you what rule is being processed as it goes to
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  45) # stdout, you do not need a debug file for that. The profile output will be
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  46) # be sent to stdout, if you provide a DEBUG_FILE the profiling data can be
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  47) # inspected there.
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  48) #
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  49) # --profile will not output if --very-quiet is used, so avoid it.
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  50) echo $SPFLAGS | egrep -e "--profile|--show-trying" 2>&1 > /dev/null
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  51) if [ $? -eq 0 ]; then
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  52) 	FLAGS="--quiet"
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  53) fi
5c384dba979f7 (Luis R. Rodriguez     2016-06-29 15:14:55 -0700  54) 
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  55) # spatch only allows include directories with the syntax "-I include"
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  56) # while gcc also allows "-Iinclude" and "-include include"
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  57) COCCIINCLUDE=${LINUXINCLUDE//-I/-I }
5b169108571e0 (Andrzej Hajda         2015-09-22 15:15:30 +0200  58) COCCIINCLUDE=${COCCIINCLUDE// -include/ --include}
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  59) 
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200  60) if [ "$C" = "1" -o "$C" = "2" ]; then
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200  61)     ONLINE=1
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200  62) 
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  63)     if [[ $# -le 0 ]]; then
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  64) 	    echo ''
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  65) 	    echo 'Specifying both the variable "C" and rule "coccicheck" in the make
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  66) command results in a shift count error.'
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  67) 	    echo ''
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  68) 	    echo 'Try specifying "scripts/coccicheck" as a value for the CHECK variable instead.'
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  69) 	    echo ''
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  70) 	    echo 'Example:	make C=2 CHECK=scripts/coccicheck drivers/net/ethernet/ethoc.o'
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  71) 	    echo ''
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  72) 	    exit 1
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  73)     fi
d8f6e5c6c8373 (Sumera Priyadarsini   2020-11-25 02:02:12 +0530  74) 
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  75)     # Take only the last argument, which is the C file to test
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  76)     shift $(( $# - 1 ))
9e395550779ef (Nicolas Palix         2013-03-02 22:36:26 +0100  77)     OPTIONS="$COCCIINCLUDE $1"
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  78) 
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  79)     # No need to parallelize Coccinelle since this mode takes one input file.
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  80)     NPROC=1
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200  81) else
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200  82)     ONLINE=0
d0bc1fb4672b9 (Greg Dietsche         2011-11-05 20:59:43 -0500  83)     if [ "$KBUILD_EXTMOD" = "" ] ; then
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200  84)         OPTIONS="--dir $srctree $COCCIINCLUDE"
d0bc1fb4672b9 (Greg Dietsche         2011-11-05 20:59:43 -0500  85)     else
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200  86)         OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
d0bc1fb4672b9 (Greg Dietsche         2011-11-05 20:59:43 -0500  87)     fi
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  88) 
e16a7c47d56b4 (Sumera Priyadarsini   2020-09-24 16:56:08 +0530  89)     # Use only one thread per core by default if hyperthreading is enabled
f5b3553b5019f (Mauro Carvalho Chehab 2021-05-18 11:05:26 +0200  90)     THREADS_PER_CORE=$(LANG=C lscpu | grep "Thread(s) per core: " | tr -cd "[:digit:]")
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  91)     if [ -z "$J" ]; then
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  92)         NPROC=$(getconf _NPROCESSORS_ONLN)
c5864560d935d (Sumera Priyadarsini   2020-10-11 15:59:42 +0530  93) 	if [ $THREADS_PER_CORE -gt 1 -a $NPROC -gt 4 ] ; then
e16a7c47d56b4 (Sumera Priyadarsini   2020-09-24 16:56:08 +0530  94) 		NPROC=$((NPROC/2))
e16a7c47d56b4 (Sumera Priyadarsini   2020-09-24 16:56:08 +0530  95) 	fi
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  96)     else
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  97)         NPROC="$J"
d7059ca0147ad (Masahiro Yamada       2017-11-14 20:38:07 +0900  98)     fi
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200  99) fi
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 100) 
bad6a4092e7f8 (Nicolas Palix         2013-03-02 22:36:28 +0100 101) if [ "$KBUILD_EXTMOD" != "" ] ; then
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 102)     OPTIONS="--patch $srctree $OPTIONS"
bad6a4092e7f8 (Nicolas Palix         2013-03-02 22:36:28 +0100 103) fi
bad6a4092e7f8 (Nicolas Palix         2013-03-02 22:36:28 +0100 104) 
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 105) # You can override by using SPFLAGS
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 106) if [ "$USE_JOBS" = "no" ]; then
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 107) 	trap kill_running SIGTERM SIGINT
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 108) 	declare -a SPATCH_PID
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 109) elif [ "$NPROC" != "1" ]; then
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 110) 	# Using 0 should work as well, refer to _SC_NPROCESSORS_ONLN use on
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 111) 	# https://github.com/rdicosmo/parmap/blob/master/setcore_stubs.c
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 112) 	OPTIONS="$OPTIONS --jobs $NPROC --chunksize 1"
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 113) fi
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 114) 
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 115) if [ "$MODE" = "" ] ; then
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 116)     if [ "$ONLINE" = "0" ] ; then
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 117) 	echo 'You have not explicitly specified the mode to use. Using default "report" mode.'
4b2bd20c350a6 (Sumera Priyadarsini   2020-08-05 14:27:40 +0530 118) 	echo 'Available modes are the following: patch, report, context, org, chain'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 119) 	echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 120) 	echo 'Note however that some modes are not implemented by some semantic patches.'
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 121)     fi
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 122)     MODE="report"
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 123) fi
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 124) 
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 125) if [ "$MODE" = "chain" ] ; then
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 126)     if [ "$ONLINE" = "0" ] ; then
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 127) 	echo 'You have selected the "chain" mode.'
1f0a6742dd900 (Nicolas Palix         2013-06-06 23:39:52 +0200 128) 	echo 'All available modes will be tried (in that order): patch, report, context, org'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 129)     fi
03ee0c42a77fb (Nicolas Palix         2010-10-08 21:27:41 +0200 130) elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
7a2358b381869 (Deepa Dinamani        2016-06-12 12:04:39 -0700 131)     FLAGS="--no-show-diff $FLAGS"
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 132) fi
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 133) 
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 134) if [ "$ONLINE" = "0" ] ; then
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 135)     echo ''
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 136)     echo 'Please check for false positives in the output before submitting a patch.'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 137)     echo 'When using "patch" mode, carefully review the patch before submitting it.'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 138)     echo ''
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 139) fi
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 140) 
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 141) run_cmd_parmap() {
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 142) 	if [ $VERBOSE -ne 0 ] ; then
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 143) 		echo "Running ($NPROC in parallel): $@"
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 144) 	fi
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 145) 	if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 146)                 echo $@>>$DEBUG_FILE
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 147)                 $@ 2>>$DEBUG_FILE
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 148)         else
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 149)                 echo $@
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 150)                 $@ 2>&1
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 151) 	fi
a19d1358345e0 (Sumera Priyadarsini   2020-09-13 17:35:48 +0530 152) 
512ddf7d7db05 (Denis Efremov         2018-08-10 23:25:55 +0300 153) 	err=$?
512ddf7d7db05 (Denis Efremov         2018-08-10 23:25:55 +0300 154) 	if [[ $err -ne 0 ]]; then
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 155) 		echo "coccicheck failed"
512ddf7d7db05 (Denis Efremov         2018-08-10 23:25:55 +0300 156) 		exit $err
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 157) 	fi
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 158) }
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 159) 
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 160) run_cmd_old() {
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 161) 	local i
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 162) 	if [ $VERBOSE -ne 0 ] ; then
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 163) 		echo "Running ($NPROC in parallel): $@"
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 164) 	fi
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 165) 	for i in $(seq 0 $(( NPROC - 1)) ); do
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 166) 		eval "$@ --max $NPROC --index $i &"
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 167) 		SPATCH_PID[$i]=$!
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 168) 		if [ $VERBOSE -eq 2 ] ; then
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 169) 			echo "${SPATCH_PID[$i]} running"
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 170) 		fi
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 171) 	done
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 172) 	wait
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 173) }
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 174) 
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 175) run_cmd() {
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 176) 	if [ "$USE_JOBS" = "yes" ]; then
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 177) 		run_cmd_parmap $@
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 178) 	else
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 179) 		run_cmd_old $@
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 180) 	fi
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 181) }
c930a1b23bb7a (Luis R. Rodriguez     2016-06-29 15:14:53 -0700 182) 
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 183) kill_running() {
2552a39facb66 (Kees Cook             2016-05-16 05:55:58 -0700 184) 	for i in $(seq 0 $(( NPROC - 1 )) ); do
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 185) 		if [ $VERBOSE -eq 2 ] ; then
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 186) 			echo "Killing ${SPATCH_PID[$i]}"
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 187) 		fi
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 188) 		kill ${SPATCH_PID[$i]} 2>/dev/null
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 189) 	done
90d06a46835ba (Kees Cook             2013-06-18 14:49:29 -0700 190) }
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 191) 
8e826ad52b751 (Luis R. Rodriguez     2016-06-29 15:14:52 -0700 192) # You can override heuristics with SPFLAGS, these must always go last
8e826ad52b751 (Luis R. Rodriguez     2016-06-29 15:14:52 -0700 193) OPTIONS="$OPTIONS $SPFLAGS"
8e826ad52b751 (Luis R. Rodriguez     2016-06-29 15:14:52 -0700 194) 
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 195) coccinelle () {
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 196)     COCCI="$1"
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 197) 
e0be348e4d6eb (Masahiro Yamada       2017-10-26 13:50:38 +0900 198)     OPT=`grep "Options:" $COCCI | cut -d':' -f2`
e0be348e4d6eb (Masahiro Yamada       2017-10-26 13:50:38 +0900 199)     REQ=`grep "Requires:" $COCCI | cut -d':' -f2 | sed "s| ||"`
33114c4359592 (Masahiro Yamada       2020-12-13 01:54:29 +0900 200)     if [ -n "$REQ" ] && ! { echo "$REQ"; echo "$SPATCH_VERSION"; } | sort -CV ; then
33114c4359592 (Masahiro Yamada       2020-12-13 01:54:29 +0900 201) 	    echo "Skipping coccinelle SmPL patch: $COCCI"
33114c4359592 (Masahiro Yamada       2020-12-13 01:54:29 +0900 202) 	    echo "You have coccinelle:           $SPATCH_VERSION"
33114c4359592 (Masahiro Yamada       2020-12-13 01:54:29 +0900 203) 	    echo "This SmPL patch requires:      $REQ"
33114c4359592 (Masahiro Yamada       2020-12-13 01:54:29 +0900 204) 	    return
a9e064c00413f (Luis R. Rodriguez     2016-06-29 15:14:57 -0700 205)     fi
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 206) 
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 207) #   The option '--parse-cocci' can be used to syntactically check the SmPL files.
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 208) #
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 209) #    $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 210) 
35d88a3871058 (Nicolas Palix         2013-03-02 22:36:25 +0100 211)     if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 212) 
cd1af7cfbbdc7 (Masahiro Yamada       2017-10-26 13:55:51 +0900 213) 	FILE=${COCCI#$srctree/}
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 214) 
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 215) 	echo "Processing `basename $COCCI`"
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 216) 	echo "with option(s) \"$OPT\""
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 217) 	echo ''
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 218) 	echo 'Message example to submit a patch:'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 219) 
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 220) 	sed -ne 's|^///||p' $COCCI
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 221) 
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 222) 	if [ "$MODE" = "patch" ] ; then
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 223) 	    echo ' The semantic patch that makes this change is available'
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 224) 	elif [ "$MODE" = "report" ] ; then
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 225) 	    echo ' The semantic patch that makes this report is available'
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 226) 	elif [ "$MODE" = "context" ] ; then
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 227) 	    echo ' The semantic patch that spots this code is available'
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 228) 	elif [ "$MODE" = "org" ] ; then
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 229) 	    echo ' The semantic patch that makes this Org report is available'
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 230) 	else
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 231) 	    echo ' The semantic patch that makes this output is available'
062c1825a5f66 (Nicolas Palix         2010-10-24 23:37:34 +0200 232) 	fi
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 233) 	echo " in $FILE."
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 234) 	echo ''
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 235) 	echo ' More information about semantic patching is available at'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 236) 	echo ' http://coccinelle.lip6.fr/'
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 237) 	echo ''
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 238) 
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 239) 	if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 240) 	    echo 'Semantic patch information:'
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 241) 	    sed -ne 's|^//#||p' $COCCI
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 242) 	    echo ''
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 243) 	fi
2c1160c87465e (Nicolas Palix         2010-10-08 21:27:40 +0200 244)     fi
3c908417677f8 (Nicolas Palix         2010-10-08 21:27:38 +0200 245) 
2c1160c87465e (Nicolas Palix         2010-10-08 21:27:40 +0200 246)     if [ "$MODE" = "chain" ] ; then
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 247) 	run_cmd $SPATCH -D patch   \
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 248) 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS               || \
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 249) 	run_cmd $SPATCH -D report  \
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 250) 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || \
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 251) 	run_cmd $SPATCH -D context \
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 252) 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS               || \
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 253) 	run_cmd $SPATCH -D org     \
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 254) 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit 1
c05cd6ddb6fce (Nicolas Palix         2012-09-20 22:30:46 +0200 255)     elif [ "$MODE" = "rep+ctxt" ] ; then
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 256) 	run_cmd $SPATCH -D report  \
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 257) 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
5303265a48eb2 (Bernd Schubert        2013-01-29 17:03:42 +0100 258) 	run_cmd $SPATCH -D context \
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 259) 		$FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 260)     else
93f1446849174 (Nicolas Palix         2013-06-20 13:10:56 +0200 261) 	run_cmd $SPATCH -D $MODE   $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 262)     fi
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 263) 
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 264) }
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 265) 
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 266) if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 267) 	if [ -f $DEBUG_FILE ]; then
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 268) 		echo "Debug file $DEBUG_FILE exists, bailing"
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 269) 		exit
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 270) 	fi
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 271) else
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 272) 	DEBUG_FILE="/dev/null"
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 273) fi
9ed07ada0e147 (Julia Lawall          2017-10-15 11:55:53 +0200 274) 
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 275) if [ "$COCCI" = "" ] ; then
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 276)     for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 277) 	coccinelle $f
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 278)     done
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 279) else
1e9dea2a60b71 (Nicolas Palix         2010-06-13 09:26:34 +0200 280)     coccinelle $COCCI
74425eee71eb4 (Nicolas Palix         2010-06-06 17:15:01 +0200 281) fi