diff options
| author | Michal Marek <mmarek@suse.cz> | 2010-06-11 18:01:31 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2010-06-11 18:01:31 -0400 |
| commit | 6ff21517c001f38b02393ad9dc92decbaee209fa (patch) | |
| tree | 7cd980dd3d869613669847ccda444459f6fdf0e4 /scripts | |
| parent | b396aa03084b51f6822052a8070703287f198360 (diff) | |
| parent | 82c4340b0a3ccf090ef38fa111363018cf0594c8 (diff) | |
Merge branch 'kbuild/coccinelle' into kbuild/misc
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Makefile.help | 3 | ||||
| -rwxr-xr-x | scripts/coccicheck | 54 | ||||
| -rw-r--r-- | scripts/coccinelle/alloc/drop_kmalloc_cast.cocci | 67 | ||||
| -rw-r--r-- | scripts/coccinelle/alloc/kzalloc-simple.cocci | 82 | ||||
| -rw-r--r-- | scripts/coccinelle/deref_null.cocci | 293 | ||||
| -rw-r--r-- | scripts/coccinelle/err_cast.cocci | 56 | ||||
| -rw-r--r-- | scripts/coccinelle/resource_size.cocci | 93 |
7 files changed, 648 insertions, 0 deletions
diff --git a/scripts/Makefile.help b/scripts/Makefile.help new file mode 100644 index 000000000000..d03608f5db04 --- /dev/null +++ b/scripts/Makefile.help | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | |||
| 2 | checker-help: | ||
| 3 | @echo ' coccicheck - Check with Coccinelle.' | ||
diff --git a/scripts/coccicheck b/scripts/coccicheck new file mode 100755 index 000000000000..037424b9ede5 --- /dev/null +++ b/scripts/coccicheck | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | SPATCH="`which ${SPATCH:=spatch}`" | ||
| 4 | |||
| 5 | if [ ! -x "$SPATCH" ]; then | ||
| 6 | echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' | ||
| 7 | exit 1 | ||
| 8 | fi | ||
| 9 | |||
| 10 | if [ "$MODE" = "" ] ; then | ||
| 11 | echo 'You have not explicitly specify the mode to use. Fallback to "report".' | ||
| 12 | echo 'You can specify the mode with "make coccicheck MODE=<mode>"' | ||
| 13 | echo 'Available modes are: report, patch, context, org' | ||
| 14 | MODE="report" | ||
| 15 | fi | ||
| 16 | |||
| 17 | echo '' | ||
| 18 | echo 'Please check for false positives in the output before submitting a patch.' | ||
| 19 | echo 'When using "patch" mode, carefully review the patch before submitting it.' | ||
| 20 | echo '' | ||
| 21 | |||
| 22 | function coccinelle { | ||
| 23 | COCCI="$1" | ||
| 24 | DIR="$2" | ||
| 25 | |||
| 26 | OPT=`grep "Option" $COCCI | cut -d':' -f2` | ||
| 27 | FILE=`echo $COCCI | sed "s|$DIR/||"` | ||
| 28 | |||
| 29 | echo "Processing `basename $COCCI` with option(s) \"$OPT\"" | ||
| 30 | echo 'Message example to submit a patch:' | ||
| 31 | |||
| 32 | sed -e '/\/\/\//!d' -e 's|^///||' $COCCI | ||
| 33 | |||
| 34 | echo ' The semantic patch that makes this change is available' | ||
| 35 | echo " in $FILE." | ||
| 36 | echo '' | ||
| 37 | echo ' More information about semantic patching is available at' | ||
| 38 | echo ' http://coccinelle.lip6.fr/' | ||
| 39 | echo '' | ||
| 40 | |||
| 41 | # The option '-parse_cocci' can be used to syntaxically check the SmPL files. | ||
| 42 | # | ||
| 43 | # $SPATCH -D $MODE -very_quiet -parse_cocci $COCCI $OPT > /dev/null | ||
| 44 | |||
| 45 | $SPATCH -D $MODE -very_quiet -sp_file $COCCI $OPT -dir $DIR | ||
| 46 | } | ||
| 47 | |||
| 48 | if [ "$COCCI" = "" ] ; then | ||
| 49 | for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do | ||
| 50 | coccinelle $f $srctree; | ||
| 51 | done | ||
| 52 | else | ||
| 53 | coccinelle $COCCI $srctree | ||
| 54 | fi | ||
diff --git a/scripts/coccinelle/alloc/drop_kmalloc_cast.cocci b/scripts/coccinelle/alloc/drop_kmalloc_cast.cocci new file mode 100644 index 000000000000..7d4771d449c3 --- /dev/null +++ b/scripts/coccinelle/alloc/drop_kmalloc_cast.cocci | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /// | ||
| 2 | /// Casting (void *) value returned by kmalloc is useless | ||
| 3 | /// as mentioned in Documentation/CodingStyle, Chap 14. | ||
| 4 | /// | ||
| 5 | // Confidence: High | ||
| 6 | // Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2. | ||
| 7 | // URL: http://coccinelle.lip6.fr/ | ||
| 8 | // Options: -no_includes -include_headers | ||
| 9 | // | ||
| 10 | // Keywords: kmalloc, kzalloc, kcalloc | ||
| 11 | // Version min: < 2.6.12 kmalloc | ||
| 12 | // Version min: < 2.6.12 kcalloc | ||
| 13 | // Version min: 2.6.14 kzalloc | ||
| 14 | // | ||
| 15 | |||
| 16 | virtual context | ||
| 17 | virtual patch | ||
| 18 | virtual org | ||
| 19 | virtual report | ||
| 20 | |||
| 21 | //---------------------------------------------------------- | ||
| 22 | // For context mode | ||
| 23 | //---------------------------------------------------------- | ||
| 24 | |||
| 25 | @depends on context@ | ||
| 26 | type T; | ||
| 27 | @@ | ||
| 28 | |||
| 29 | * (T *) | ||
| 30 | \(kmalloc\|kzalloc\|kcalloc\)(...) | ||
| 31 | |||
| 32 | //---------------------------------------------------------- | ||
| 33 | // For patch mode | ||
| 34 | //---------------------------------------------------------- | ||
| 35 | |||
| 36 | @depends on patch@ | ||
| 37 | type T; | ||
| 38 | @@ | ||
| 39 | |||
| 40 | - (T *) | ||
| 41 | \(kmalloc\|kzalloc\|kcalloc\)(...) | ||
| 42 | |||
| 43 | //---------------------------------------------------------- | ||
| 44 | // For org and report mode | ||
| 45 | //---------------------------------------------------------- | ||
| 46 | |||
| 47 | @r depends on org || report@ | ||
| 48 | type T; | ||
| 49 | position p; | ||
| 50 | @@ | ||
| 51 | |||
| 52 | (T@p *)\(kmalloc\|kzalloc\|kcalloc\)(...) | ||
| 53 | |||
| 54 | @script:python depends on org@ | ||
| 55 | p << r.p; | ||
| 56 | t << r.T; | ||
| 57 | @@ | ||
| 58 | |||
| 59 | coccilib.org.print_safe_todo(p[0], t) | ||
| 60 | |||
| 61 | @script:python depends on report@ | ||
| 62 | p << r.p; | ||
| 63 | t << r.T; | ||
| 64 | @@ | ||
| 65 | |||
| 66 | msg="WARNING: casting value returned by k[cmz]alloc to (%s *) is useless." % (t) | ||
| 67 | coccilib.report.print_report(p[0], msg) | ||
diff --git a/scripts/coccinelle/alloc/kzalloc-simple.cocci b/scripts/coccinelle/alloc/kzalloc-simple.cocci new file mode 100644 index 000000000000..2eae828fc657 --- /dev/null +++ b/scripts/coccinelle/alloc/kzalloc-simple.cocci | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | /// | ||
| 2 | /// kzalloc should be used rather than kmalloc followed by memset 0 | ||
| 3 | /// | ||
| 4 | // Confidence: High | ||
| 5 | // Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2. | ||
| 6 | // Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2. | ||
| 7 | // URL: http://coccinelle.lip6.fr/rules/kzalloc.html | ||
| 8 | // Options: -no_includes -include_headers | ||
| 9 | // | ||
| 10 | // Keywords: kmalloc, kzalloc | ||
| 11 | // Version min: < 2.6.12 kmalloc | ||
| 12 | // Version min: 2.6.14 kzalloc | ||
| 13 | // | ||
| 14 | |||
| 15 | virtual context | ||
| 16 | virtual patch | ||
| 17 | virtual org | ||
| 18 | virtual report | ||
| 19 | |||
| 20 | //---------------------------------------------------------- | ||
| 21 | // For context mode | ||
| 22 | //---------------------------------------------------------- | ||
| 23 | |||
| 24 | @depends on context@ | ||
| 25 | type T, T2; | ||
| 26 | expression x; | ||
| 27 | expression E1,E2; | ||
| 28 | statement S; | ||
| 29 | @@ | ||
| 30 | |||
| 31 | * x = (T)kmalloc(E1,E2); | ||
| 32 | if ((x==NULL) || ...) S | ||
| 33 | * memset((T2)x,0,E1); | ||
| 34 | |||
| 35 | //---------------------------------------------------------- | ||
| 36 | // For patch mode | ||
| 37 | //---------------------------------------------------------- | ||
| 38 | |||
| 39 | @depends on patch@ | ||
| 40 | type T, T2; | ||
| 41 | expression x; | ||
| 42 | expression E1,E2; | ||
| 43 | statement S; | ||
| 44 | @@ | ||
| 45 | |||
| 46 | - x = (T)kmalloc(E1,E2); | ||
| 47 | + x = kzalloc(E1,E2); | ||
| 48 | if ((x==NULL) || ...) S | ||
| 49 | - memset((T2)x,0,E1); | ||
| 50 | |||
| 51 | //---------------------------------------------------------- | ||
| 52 | // For org mode | ||
| 53 | //---------------------------------------------------------- | ||
| 54 | |||
| 55 | @r depends on org || report@ | ||
