xref: /illumos-gate/usr/src/tools/smatch/src/smatch_scripts/kpatch.sh (revision 5a0e240f87295cfc13c53236f30ccace0d5412c7)
1#!/bin/bash -e
2
3TMP_DIR=/tmp
4
5help()
6{
7    echo "Usage: $0 [--no-compile|--amend] <filename>"
8    echo "You must be at the base of the kernel tree to run this."
9    exit 1
10}
11
12continue_yn()
13{
14    echo -n "Do you want to fix these issues now? "
15    read ans
16    if ! echo $ans | grep -iq ^n ; then
17	exit 1;
18    fi
19}
20
21qc()
22{
23    local msg=$1
24    local ans
25
26    echo -n "$msg:  "
27    read ans
28    if ! echo $ans | grep -qi ^y ; then
29	exit 1
30    fi
31}
32
33NO_COMPILE=false
34AMEND=""
35
36while true ; do
37    if [[ "$1" == "--no-compile" ]] ; then
38        NO_COMPILE=true
39        shift
40    elif [[ "$1" == "--amend" ]] ; then
41        AMEND="--amend"
42        shift
43    else
44        break
45    fi
46done
47
48if [ ! -f $1 ] ; then
49    help
50fi
51
52fullname=$1
53filename=$(basename $fullname)
54oname=$(echo ${fullname/.c/.o})
55
56MSG_FILE=$TMP_DIR/${filename}.msg
57MAIL_FILE=$TMP_DIR/${filename}.mail
58
59# heat up the disk cache
60#git log --oneline $fullname | head -n 10 > /dev/null &
61
62echo "QC checklist"
63qc "Have you handled all the errors properly?"
64if git diff $fullname | grep ^+ | grep -qi alloc ; then
65    qc "Have you freed all your mallocs?"
66fi
67if git diff $fullname | grep ^+ | grep -qi alloc ; then
68    qc "Have you check all your mallocs for NULL returns?"
69fi
70
71if [ "$NO_COMPILE" != "true" ] ; then
72    kchecker --spammy $fullname
73    kchecker --sparse --endian $fullname
74#    rm $oname
75#    make C=1 CHECK="scripts/coccicheck" $oname
76fi
77
78for file in $(grep -l $fullname ~/var/mail/sent-*) ; do
79    grepmail $fullname $file | grep -i ^subject || echo -n ""
80done
81qc "Looks OK?"
82
83git add $fullname
84
85cat /dev/null > $MSG_FILE
86if [ "$AMEND" != "" ] ; then
87    git format-patch HEAD^ --stdout >> $MSG_FILE
88else
89    echo "" >> $MSG_FILE
90    echo "Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>" >> $MSG_FILE
91    echo "" >> $MSG_FILE
92    echo "# $sm_err" >> $MSG_FILE
93fi
94git log -10 --oneline $fullname | sed -e 's/^/# /' >> $MSG_FILE
95vim $MSG_FILE
96
97grep -v '^#' $MSG_FILE > $MSG_FILE.1
98mv $MSG_FILE.1 $MSG_FILE
99
100git commit $AMEND -F $MSG_FILE
101
102git format-patch HEAD^ --stdout >> $MSG_FILE
103
104to_addr=$(./scripts/get_maintainer.pl --noroles --norolestats $MSG_FILE | head -n 1)
105cc_addr=$(./scripts/get_maintainer.pl --noroles --norolestats $MSG_FILE | tail -n +2 | \
106    perl -ne 's/\n$/, /; print')
107cc_addr="$cc_addr, kernel-janitors@vger.kernel.org"
108
109echo -n "To:  "  > $MAIL_FILE
110echo "$to_addr" >> $MAIL_FILE
111echo -n "CC:  " >> $MAIL_FILE
112echo "$cc_addr" >> $MAIL_FILE
113echo "X-Mailer: git-send-email haha only kidding" >> $MAIL_FILE
114
115git format-patch HEAD^ --stdout >> $MAIL_FILE
116
117./scripts/checkpatch.pl $MAIL_FILE || continue_yn
118
119echo "Press ENTER to continue"
120read unused
121
122mutt -H $MAIL_FILE
123rm -f $MSG_FILE
124