From 9f14b4201239a9779d52bdd6137583d452b38ec3 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sat, 29 Dec 2012 00:08:22 +0100 Subject: scripts/tags.sh: Fix regex syntax for etags Signed-off-by: Andreas Schwab Tested-by: Jesper Juhl Signed-off-by: Michal Marek --- scripts/tags.sh | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/scripts/tags.sh b/scripts/tags.sh index 08f06c00745..4c53b7d883d 100755 --- a/scripts/tags.sh +++ b/scripts/tags.sh @@ -201,34 +201,34 @@ exuberant() emacs() { all_target_sources | xargs $1 -a \ - --regex='/^(ENTRY|_GLOBAL)(\([^)]*\)).*/\2/' \ + --regex='/^\(ENTRY\|_GLOBAL\)(\([^)]*\)).*/\2/' \ --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' \ --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/' \ --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/' \ - --regex='/PAGEFLAG\(([^,)]*).*/Page\1/' \ - --regex='/PAGEFLAG\(([^,)]*).*/SetPage\1/' \ - --regex='/PAGEFLAG\(([^,)]*).*/ClearPage\1/' \ - --regex='/TESTSETFLAG\(([^,)]*).*/TestSetPage\1/' \ - --regex='/TESTPAGEFLAG\(([^,)]*).*/Page\1/' \ - --regex='/SETPAGEFLAG\(([^,)]*).*/SetPage\1/' \ - --regex='/__SETPAGEFLAG\(([^,)]*).*/__SetPage\1/' \ - --regex='/TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \ - --regex='/__TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \ - --regex='/CLEARPAGEFLAG\(([^,)]*).*/ClearPage\1/' \ - --regex='/__CLEARPAGEFLAG\(([^,)]*).*/__ClearPage\1/' \ - --regex='/__PAGEFLAG\(([^,)]*).*/__SetPage\1/' \ - --regex='/__PAGEFLAG\(([^,)]*).*/__ClearPage\1/' \ - --regex='/PAGEFLAG_FALSE\(([^,)]*).*/Page\1/' \ - --regex='/TESTSCFLAG\(([^,)]*).*/TestSetPage\1/' \ - --regex='/TESTSCFLAG\(([^,)]*).*/TestClearPage\1/' \ - --regex='/SETPAGEFLAG_NOOP\(([^,)]*).*/SetPage\1/' \ - --regex='/CLEARPAGEFLAG_NOOP\(([^,)]*).*/ClearPage\1/' \ - --regex='/__CLEARPAGEFLAG_NOOP\(([^,)]*).*/__ClearPage\1/' \ - --regex='/TESTCLEARFLAG_FALSE\(([^,)]*).*/TestClearPage\1/' \ - --regex='/__TESTCLEARFLAG_FALSE\(([^,)]*).*/__TestClearPage\1/' \ - --regex='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' \ - --regex='/PCI_OP_READ\(([a-z]*[a-z]).*[1-4]\)/pci_bus_read_config_\1/' \ - --regex='/PCI_OP_WRITE\(([a-z]*[a-z]).*[1-4]\)/pci_bus_write_config_\1/' + --regex='/PAGEFLAG(\([^,)]*\).*/Page\1/' \ + --regex='/PAGEFLAG(\([^,)]*\).*/SetPage\1/' \ + --regex='/PAGEFLAG(\([^,)]*\).*/ClearPage\1/' \ + --regex='/TESTSETFLAG(\([^,)]*\).*/TestSetPage\1/' \ + --regex='/TESTPAGEFLAG(\([^,)]*\).*/Page\1/' \ + --regex='/SETPAGEFLAG(\([^,)]*\).*/SetPage\1/' \ + --regex='/__SETPAGEFLAG(\([^,)]*\).*/__SetPage\1/' \ + --regex='/TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \ + --regex='/__TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \ + --regex='/CLEARPAGEFLAG(\([^,)]*\).*/ClearPage\1/' \ + --regex='/__CLEARPAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \ + --regex='/__PAGEFLAG(\([^,)]*\).*/__SetPage\1/' \ + --regex='/__PAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \ + --regex='/PAGEFLAG_FALSE(\([^,)]*\).*/Page\1/' \ + --regex='/TESTSCFLAG(\([^,)]*\).*/TestSetPage\1/' \ + --regex='/TESTSCFLAG(\([^,)]*\).*/TestClearPage\1/' \ + --regex='/SETPAGEFLAG_NOOP(\([^,)]*\).*/SetPage\1/' \ + --regex='/CLEARPAGEFLAG_NOOP(\([^,)]*\).*/ClearPage\1/' \ + --regex='/__CLEARPAGEFLAG_NOOP(\([^,)]*\).*/__ClearPage\1/' \ + --regex='/TESTCLEARFLAG_FALSE(\([^,)]*\).*/TestClearPage\1/' \ + --regex='/__TESTCLEARFLAG_FALSE(\([^,)]*\).*/__TestClearPage\1/' \ + --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' \ + --regex='/PCI_OP_READ(\([a-z]*[a-z]\).*[1-4])/pci_bus_read_config_\1/' \ + --regex='/PCI_OP_WRITE(\([a-z]*[a-z]\).*[1-4])/pci_bus_write_config_\1/' all_kconfigs | xargs $1 -a \ --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/' -- cgit v1.2.3 From 7320bfa7cfe31e9ee95a40ab8e52648066284141 Mon Sep 17 00:00:00 2001 From: Peter Senna Tschudin Date: Sat, 8 Dec 2012 15:34:34 -0200 Subject: scripts/coccinelle/misc/semicolon.cocci: Add unneeded semicolon test This semantic patch looks for semicolons that can be removed without changing the semantics of the code. The confidence is moderate because there are some false positives on cases like: b/drivers/mmc/host/cb710-mmc.c:589 break; case MMC_POWER_UP: default: - /* ignore */; } There are 37 patches accepted reported by this semantic patch and more than 300 fixes to be applied. Signed-off-by: Peter Senna Tschudin Signed-off-by: Michal Marek --- scripts/coccinelle/misc/semicolon.cocci | 83 +++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 scripts/coccinelle/misc/semicolon.cocci diff --git a/scripts/coccinelle/misc/semicolon.cocci b/scripts/coccinelle/misc/semicolon.cocci new file mode 100644 index 00000000000..a47eba2edc9 --- /dev/null +++ b/scripts/coccinelle/misc/semicolon.cocci @@ -0,0 +1,83 @@ +/// +/// Removes unneeded semicolon. +/// +// Confidence: Moderate +// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Comments: Some false positives on empty default cases in switch statements. +// Options: --no-includes --include-headers + +virtual patch +virtual report +virtual context +virtual org + +@r_default@ +position p; +@@ +switch (...) +{ +default: ...;@p +} + +@r_case@ +position p; +@@ +( +switch (...) +{ +case ...:;@p +} +| +switch (...) +{ +case ...:... +case ...:;@p +} +| +switch (...) +{ +case ...:... +case ...: +case ...:;@p +} +) + +@r1@ +statement S; +position p1; +position p != {r_default.p, r_case.p}; +identifier label; +@@ +( +label:; +| +S@p1;@p +) + +@script:python@ +p << r1.p; +p1 << r1.p1; +@@ +if p[0].line != p1[0].line_end: + cocci.include_match(False) + +@depends on patch@ +position r1.p; +@@ +-;@p + +@script:python depends on report@ +p << r1.p; +@@ +coccilib.report.print_report(p[0],"Unneeded semicolon") + +@depends on context@ +position r1.p; +@@ +*;@p + +@script:python depends on org@ +p << r1.p; +@@ +cocci.print_main("Unneeded semicolon",p) -- cgit v1.2.3 From e0367a61567de103b1946bf87115e15253194195 Mon Sep 17 00:00:00 2001 From: "David R. Bild" Date: Sat, 12 Jan 2013 10:19:19 -0500 Subject: kbuild: clear KBUILD_SRC when calling 'make' in RPM spec 'make rpm-pkg' and 'make binrpm-pkg' fail when the kernel source is read-only. Specifically, when the RPM spec generated by scripts/package/mkspec is run, KBUILD_SRC happens to be set to the source location and thus the invocation of 'make headers_install' fails when an internal call to 'filechk' tries to write a file into the source tree. The fix is to clear KBUILD_SRC for the 'make headers_install' invocation in the spec file, as is already done for the 'make modules_install' invocation. Signed-off-by: David R. Bild Signed-off-by: Michal Marek --- scripts/package/mkspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 4bf17ddf7c7..fbbfd08853d 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -95,7 +95,7 @@ echo 'cp $KBUILD_IMAGE $RPM_BUILD_ROOT'"/boot/vmlinuz-$KERNELRELEASE" echo "%endif" echo "%endif" -echo 'make %{?_smp_mflags} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr headers_install' +echo 'make %{?_smp_mflags} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install' echo 'cp System.map $RPM_BUILD_ROOT'"/boot/System.map-$KERNELRELEASE" echo 'cp .config $RPM_BUILD_ROOT'"/boot/config-$KERNELRELEASE" -- cgit v1.2.3 From ff3771cb717fd532d97f354cd169fd10da0d0339 Mon Sep 17 00:00:00 2001 From: Peter Senna Tschudin Date: Wed, 23 Jan 2013 20:06:30 -0200 Subject: scripts/coccinelle/misc/memcpy-assign.cocci: Replace memcpy with struct assignment There are error-prone memcpy() that can be replaced by struct assignment that are type-safe and much easier to read. This semantic patch looks for memcpy() that can be replaced by struct assignment. Inspired by patches sent by Ezequiel Garcia Signed-off-by: Peter Senna Tschudin Signed-off-by: Michal Marek --- scripts/coccinelle/misc/memcpy-assign.cocci | 103 ++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 scripts/coccinelle/misc/memcpy-assign.cocci diff --git a/scripts/coccinelle/misc/memcpy-assign.cocci b/scripts/coccinelle/misc/memcpy-assign.cocci new file mode 100644 index 00000000000..afd058be497 --- /dev/null +++ b/scripts/coccinelle/misc/memcpy-assign.cocci @@ -0,0 +1,103 @@ +// +// Replace memcpy with struct assignment. +// +// Confidence: High +// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Comments: +// Options: --no-includes --include-headers + +virtual patch +virtual report +virtual context +virtual org + +@r1 depends on !patch@ +identifier struct_name; +struct struct_name to; +struct struct_name from; +struct struct_name *top; +struct struct_name *fromp; +position p; +@@ +memcpy@p(\(&(to)\|top\), \(&(from)\|fromp\), \(sizeof(to)\|sizeof(from)\|sizeof(struct struct_name)\|sizeof(*top)\|sizeof(*fromp)\)) + +@script:python depends on report@ +p << r1.p; +@@ +coccilib.report.print_report(p[0],"Replace memcpy with struct assignment") + +@depends on context@ +position r1.p; +@@ +*memcpy@p(...); + +@script:python depends on org@ +p << r1.p; +@@ +cocci.print_main("Replace memcpy with struct assignment",p) + +@depends on patch@ +identifier struct_name; +struct struct_name to; +struct struct_name from; +@@ +( +-memcpy(&(to), &(from), sizeof(to)); ++to = from; +| +-memcpy(&(to), &(from), sizeof(from)); ++to = from; +| +-memcpy(&(to), &(from), sizeof(struct struct_name)); ++to = from; +) + +@depends on patch@ +identifier struct_name; +struct struct_name to; +struct struct_name *from; +@@ +( +-memcpy(&(to), from, sizeof(to)); ++to = *from; +| +-memcpy(&(to), from, sizeof(*from)); ++to = *from; +| +-memcpy(&(to), from, sizeof(struct struct_name)); ++to = *from; +) + +@depends on patch@ +identifier struct_name; +struct struct_name *to; +struct struct_name from; +@@ +( +-memcpy(to, &(from), sizeof(*to)); ++ *to = from; +| +-memcpy(to, &(from), sizeof(from)); ++ *to = from; +| +-memcpy(to, &(from), sizeof(struct struct_name)); ++ *to = from; +) + +@depends on patch@ +identifier struct_name; +struct struct_name *to; +struct struct_name *from; +@@ +( +-memcpy(to, from, sizeof(*to)); ++ *to = *from; +| +-memcpy(to, from, sizeof(*from)); ++ *to = *from; +| +-memcpy(to, from, sizeof(struct struct_name)); ++ *to = *from; +) + -- cgit v1.2.3 From 26e56720916a2a84704d46268375f204f58bebc8 Mon Sep 17 00:00:00 2001 From: Bernd Schubert Date: Tue, 29 Jan 2013 17:03:37 +0100 Subject: coccicheck: Allow the user to give a V= (verbose) argument Do not run with verbosity on/off depending on the ONLINE variable, which gets set with C=1 or C=2, but allow the user to set the verbosity using kernel default make V= paramemter. Verbosity is off by default now. Signed-off-by: Bernd Schubert CC: Julia Lawall Acked-by: Nicolas Palix Signed-off-by: Michal Marek --- Documentation/coccinelle.txt | 4 ++++ scripts/coccicheck | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/coccinelle.txt b/Documentation/coccinelle.txt index cf44eb6499b..dffa2d620d6 100644 --- a/Documentation/coccinelle.txt +++ b/Documentation/coccinelle.txt @@ -87,6 +87,10 @@ As any static code analyzer, Coccinelle produces false positives. Thus, reports must be carefully checked, and patches reviewed. +To enable verbose messages set the V= variable, for example: + + make coccicheck MODE=report V=1 + Using Coccinelle with a single semantic patch ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/scripts/coccicheck b/scripts/coccicheck index 1a49d1c7ecf..f8f15a269e1 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -2,6 +2,15 @@ SPATCH="`which ${SPATCH:=spatch}`" +# The verbosity may be set by the environmental parameter V= +# as for example with 'make V=1 coccicheck' + +if [ -n "$V" -a "$V" != "0" ]; then + VERBOSE=1 +else + VERBOSE=0 +fi + if [ "$C" = "1" -o "$C" = "2" ]; then ONLINE=1 @@ -55,7 +64,7 @@ coccinelle () { # # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null - if [ "$ONLINE" = "0" ] ; then + if [ $VERBOSE -ne 0 ] ; then FILE=`echo $COCCI | sed "s|$srctree/||"` -- cgit v1.2.3 From 5303265a48eb276b8cdee84f8e91e7f971224c5e Mon Sep 17 00:00:00 2001 From: Bernd Schubert Date: Tue, 29 Jan 2013 17:03:42 +0100 Subject: coccicheck: Allow to show the executed command line On my system one of the tests failed with "Fatal error: exception Failure("No OCaml compiler found! Install either ocamlopt or ocamlopt.opt")". Investigating such issues is easier if the executed command line is being shown. Signed-off-by: Bernd Schubert CC: Julia Lawall Acked-by: Nicolas Palix Signed-off-by: Michal Marek --- scripts/coccicheck | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/coccicheck b/scripts/coccicheck index f8f15a269e1..85d31899ad9 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -55,6 +55,14 @@ if [ "$ONLINE" = "0" ] ; then echo '' fi +run_cmd() { + if [ $VERBOSE -ne 0 ] ; then + echo "Running: $@" + fi + eval $@ +} + + coccinelle () { COCCI="$1" @@ -100,15 +108,21 @@ coccinelle () { fi if [ "$MODE" = "chain" ] ; then - $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ - $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ - $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ - $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 + run_cmd $SPATCH -D patch \ + $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ + run_cmd $SPATCH -D report \ + $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ + run_cmd $SPATCH -D context \ + $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ + run_cmd $SPATCH -D org \ + $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 elif [ "$MODE" = "rep+ctxt" ] ; then - $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ - $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 + run_cmd $SPATCH -D report \ + $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ + run_cmd $SPATCH -D context \ + $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 else - $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 + run_cmd $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 fi } -- cgit v1.2.3 From 24f0c2d6ff859fbca45fd765f0d241528bdb4365 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 2 Feb 2013 17:19:55 +0100 Subject: scripts/coccinelle: find constant additions that could be bit ors Semantic patch (http://coccinelle.lip6.fr/) to check for constants that are added but are used elsewhere as bitmasks. Signed-off-by: Julia Lawall Signed-off-by: Michal Marek --- scripts/coccinelle/misc/orplus.cocci | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/coccinelle/misc/orplus.cocci diff --git a/scripts/coccinelle/misc/orplus.cocci b/scripts/coccinelle/misc/orplus.cocci new file mode 100644 index 00000000000..4a28cef1484 --- /dev/null +++ b/scripts/coccinelle/misc/orplus.cocci @@ -0,0 +1,55 @@ +/// Check for constants that are added but are used elsewhere as bitmasks +/// The results should be checked manually to ensure that the nonzero +/// bits in the two constants are actually disjoint. +/// +// Confidence: Moderate +// Copyright: (C) 2013 Julia Lawall, INRIA/LIP6. GPLv2. +// Copyright: (C) 2013 Gilles Muller, INRIA/LIP6. GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Comments: +// Options: -no_includes -include_headers + +virtual org +virtual report +virtual context + +@r@ +constant c; +identifier i; +expression e; +@@ + +( +e | c@i +| +e & c@i +| +e |= c@i +| +e &= c@i +) + +@s@ +constant r.c,c1; +identifier i1; +position p; +@@ + +( + c1 + c - 1 +| +*c1@i1 +@p c +) + +@script:python depends on org@ +p << s.p; +@@ + +cocci.print_main("sum of probable bitmasks, consider |",p) + +@script:python depends on report@ +p << s.p; +@@ + +msg = "WARNING: sum of probable bitmasks, consider |" +coccilib.report.print_report(p[0],msg) -- cgit v1.2.3