From dcf36a92f569b2c240129d8c6ae4c366c1658766 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 26 Oct 2009 16:49:47 -0700 Subject: scripts/get_maintainer.pl: add patch/file search for keywords Based on an idea from Wolfram Sang. Add search for MAINTAINERS line "K:" regex pattern match in a patch or file Matches are added after file pattern matches Add --keywords command line switch (default 1, on) Change version to 0.21 Signed-off-by: Joe Perches Cc: Wolfram Sang Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/get_maintainer.pl | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index cdb44b63342..102b76608f3 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl @@ -13,7 +13,7 @@ use strict; my $P = $0; -my $V = '0.20'; +my $V = '0.21'; use Getopt::Long qw(:config no_auto_abbrev); @@ -37,6 +37,7 @@ my $scm = 0; my $web = 0; my $subsystem = 0; my $status = 0; +my $keywords = 1; my $from_filename = 0; my $pattern_depth = 0; my $version = 0; @@ -84,6 +85,7 @@ if (!GetOptions( 'scm!' => \$scm, 'web!' => \$web, 'pattern-depth=i' => \$pattern_depth, + 'k|keywords!' => \$keywords, 'f|file' => \$from_filename, 'v|version' => \$version, 'h|help' => \$help, @@ -132,6 +134,8 @@ if (!top_of_kernel_tree($lk_path)) { ## Read MAINTAINERS for type/value pairs my @typevalue = (); +my %keyword_hash; + open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n"; while () { my $line = $_; @@ -149,6 +153,8 @@ while () { if ((-d $value)) { $value =~ s@([^/])$@$1/@; } + } elsif ($type eq "K") { + $keyword_hash{@typevalue} = $value; } push(@typevalue, "$type:$value"); } elsif (!/^(\s)*$/) { @@ -188,6 +194,7 @@ if ($email_remove_duplicates) { my @files = (); my @range = (); +my @keyword_tvi = (); foreach my $file (@ARGV) { ##if $file is a directory and it lacks a trailing slash, add one @@ -198,11 +205,24 @@ foreach my $file (@ARGV) { } if ($from_filename) { push(@files, $file); + if (-f $file && $keywords) { + open(FILE, "<$file") or die "$P: Can't open ${file}\n"; + while () { + my $patch_line = $_; + foreach my $line (keys %keyword_hash) { + if ($patch_line =~ m/^.*$keyword_hash{$line}/x) { + push(@keyword_tvi, $line); + } + } + } + close(FILE); + } } else { my $file_cnt = @files; my $lastfile; open(PATCH, "<$file") or die "$P: Can't open ${file}\n"; while () { + my $patch_line = $_; if (m/^\+\+\+\s+(\S+)/) { my $filename = $1; $filename =~ s@^[^/]*/@@; @@ -213,6 +233,12 @@ foreach my $file (@ARGV) { if ($email_git_blame) { push(@range, "$lastfile:$1:$2"); } + } elsif ($keywords) { + foreach my $line (keys %keyword_hash) { + if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) { + push(@keyword_tvi, $line); + } + } } } close(PATCH); @@ -286,6 +312,13 @@ foreach my $file (@files) { } } +if ($keywords) { + @keyword_tvi = sort_and_uniq(@keyword_tvi); + foreach my $line (@keyword_tvi) { + add_categories($line); + } +} + if ($email) { foreach my $chief (@penguin_chief) { if ($chief =~ m/^(.*):(.*)/) { @@ -384,6 +417,7 @@ Output type options: Other options: --pattern-depth => Number of pattern directory traversals (default: 0 (all)) + --keywords => scan patch for keywords (default: 1 (on)) --version => show version --help => show this help information @@ -486,7 +520,6 @@ sub format_email { } sub find_starting_index { - my ($index) = @_; while ($index > 0) { -- cgit v1.2.3 From 9a974fdbe3fbb4b0f6d552579dc79ac237412c61 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:12 -0700 Subject: checkpatch: possible types -- prevent illegal modifiers being added Prevent known non types being detected as modifiers. Ensure we do not look at any type which starts with a keyword. Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 87bbb8bce9b..b43e309c38f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -997,23 +997,25 @@ sub annotate_values { sub possible { my ($possible, $line) = @_; - - print "CHECK<$possible> ($line)\n" if ($dbg_possible > 2); - if ($possible !~ /(?: + my $notPermitted = qr{(?: ^(?: $Modifier| $Storage| $Type| - DEFINE_\S+| + DEFINE_\S+ + )$| + ^(?: goto| return| case| else| asm|__asm__| do - )$| + )(?:\s|$)| ^(?:typedef|struct|enum)\b - )/x) { + )}x; + warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2); + if ($possible !~ $notPermitted) { # Check for modifiers. $possible =~ s/\s*$Storage\s*//g; $possible =~ s/\s*$Sparse\s*//g; @@ -1022,8 +1024,10 @@ sub possible { } elsif ($possible =~ /\s/) { $possible =~ s/\s*$Type\s*//g; for my $modifier (split(' ', $possible)) { - warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible); - push(@modifierList, $modifier); + if ($modifier !~ $notPermitted) { + warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible); + push(@modifierList, $modifier); + } } } else { -- cgit v1.2.3 From cc77cdca5209c1199deb33f3a83df191ac32f4d6 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:13 -0700 Subject: checkpatch: correctly stop scanning at the bottom of a hunk We are allowing context scanning checks to apply against the first line of context outside at the end of the hunk. This can lead to false matches to patch names leading to various perl warnings. Correctly stop at the bottom of the hunk. Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b43e309c38f..1eca1e14358 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1234,7 +1234,6 @@ sub process { $linenr++; my $rawline = $rawlines[$linenr - 1]; - my $hunk_line = ($realcnt != 0); #extract the line range in the file after the patch is applied if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { @@ -1274,6 +1273,8 @@ sub process { $realcnt--; } + my $hunk_line = ($realcnt != 0); + #make up the handle for any error we report on this line $prefix = "$filename:$realline: " if ($emacs && $file); $prefix = "$filename:$linenr: " if ($emacs && !$file); -- cgit v1.2.3 From 131edb3418018b6da297ed389b541e697043a8b6 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:14 -0700 Subject: checkpatch: update copyright dates Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 1eca1e14358..05b10d6bc58 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2,7 +2,7 @@ # (c) 2001, Dave Jones. (the file handling bit) # (c) 2005, Joel Schopp (the ugly bit) # (c) 2007,2008, Andy Whitcroft (new conditions, test suite) -# (c) 2008, Andy Whitcroft +# (c) 2008,2009, Andy Whitcroft # Licensed under the terms of the GNU GPL License version 2 use strict; -- cgit v1.2.3 From 2ceb532b04b7a3b8f534d11a6e839f8b8bff94c1 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:14 -0700 Subject: checkpatch: fix false errors due to macro concatenation The macro concatenation (##) sequence can cause false errors when checking macro's. Checkpatch doesn't currently know about the operator. For example this line, + entry = (struct ftrace_raw_##call *)raw_data; \ is correct but it produces the following error, ERROR: need consistent spacing around '*' (ctx:WxB) + entry = (struct ftrace_raw_##call *)raw_data;\ ^ The line above doesn't have any spacing problems, and if you remove the macro concatenation sequence checkpatch doesn't give any errors. Extend identifier handling to include ## concatenation within the definition of an identifier. Reported-by: Daniel Walker Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 05b10d6bc58..cb2dac37aaf 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -130,7 +130,10 @@ if ($tree) { my $emitted_corrupt = 0; -our $Ident = qr{[A-Za-z_][A-Za-z\d_]*}; +our $Ident = qr{ + [A-Za-z_][A-Za-z\d_]* + (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)* + }x; our $Storage = qr{extern|static|asmlinkage}; our $Sparse = qr{ __user| -- cgit v1.2.3 From 99423c2065b62fee41cdbd8da7e63bf1f8f9e9b0 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:15 -0700 Subject: checkpatch: fix __attribute__ matching In the following code, union thread_union init_thread_union __attribute__((__section__(".data.init_task"))) = { INIT_THREAD_INFO(init_task) }; There is a non-conforming declaration. It should really be like the following, union thread_union init_thread_union __attribute__((__section__(".data.init_task"))) = { INIT_THREAD_INFO(init_task) }; However, checkpatch doesn't catch this right now because it doesn't correctly evaluate the "__attribute__". It is not at all clear that we care what preceeds an assignment style attribute when we find the open brace. Relax the test so we do not need to check the __attribute__. Reported-by: Daniel Walker Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index cb2dac37aaf..ba105a84839 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1669,8 +1669,8 @@ sub process { } # check for initialisation to aggregates open brace on the next line - if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ && - $line =~ /^.\s*{/) { + if ($line =~ /^.\s*{/ && + $prevline =~ /(?:^|[^=])=\s*$/) { ERROR("that open brace { should be on the previous line\n" . $hereprev); } -- cgit v1.2.3 From 2b474a1a566064b40bc7d9a45021ffbc4c894fa3 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:16 -0700 Subject: checkpatch: fix false EXPORT_SYMBOL warning Ingo reported that the following lines triggered a false warning, static struct lock_class_key rcu_lock_key; struct lockdep_map rcu_lock_map = STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key); EXPORT_SYMBOL_GPL(rcu_lock_map); from kernel/rcutree.c , and the false warning looked like this, WARNING: EXPORT_SYMBOL(foo); should immediately follow its function/variable +EXPORT_SYMBOL_GPL(rcu_lock_map); We actually should be checking the statement before the EXPORT_* for a mention of the exported object, and complain where it is not there. [akpm@linux-foundation.org: coding-style fixes] Cc: Ingo Molnar Cc: Paul E. McKenney Reported-by: Daniel Walker Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ba105a84839..88c4f6a5080 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1145,6 +1145,7 @@ sub process { # suppression flags my %suppress_ifbraces; my %suppress_whiletrailers; + my %suppress_export; # Pre-scan the patch sanitizing the lines. # Pre-scan the patch looking for any __setup documentation. @@ -1253,6 +1254,7 @@ sub process { %suppress_ifbraces = (); %suppress_whiletrailers = (); + %suppress_export = (); next; # track the line number as we move through the hunk, note that @@ -1428,13 +1430,22 @@ sub process { } # Check for potential 'bare' types - my ($stat, $cond, $line_nr_next, $remain_next, $off_next); + my ($stat, $cond, $line_nr_next, $remain_next, $off_next, + $realline_next); if ($realcnt && $line =~ /.\s*\S/) { ($stat, $cond, $line_nr_next, $remain_next, $off_next) = ctx_statement_block($linenr, $realcnt, 0); $stat =~ s/\n./\n /g; $cond =~ s/\n./\n /g; + # Find the real next line. + $realline_next = $line_nr_next; + if (defined $realline_next && + (!defined $lines[$realline_next - 1] || + substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) { + $realline_next++; + } + my $s = $stat; $s =~ s/{.*$//s; @@ -1695,21 +1706,40 @@ sub process { $line =~ s@//.*@@; $opline =~ s@//.*@@; -#EXPORT_SYMBOL should immediately follow its function closing }. - if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) || - ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { +# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider +# the whole statement. +#print "APW <$lines[$realline_next - 1]>\n"; + if (defined $realline_next && + exists $lines[$realline_next - 1] && + !defined $suppress_export{$realline_next} && + ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || + $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { my $name = $1; - if ($prevline !~ /(?: - ^.}| + if ($stat !~ /(?: + \n.}\s*$| ^.DEFINE_$Ident\(\Q$name\E\)| ^.DECLARE_$Ident\(\Q$name\E\)| ^.LIST_HEAD\(\Q$name\E\)| - ^.$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| - \b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[) + ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| + \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\() )/x) { - WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); +#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n"; + $suppress_export{$realline_next} = 2; + } else { + $suppress_export{$realline_next} = 1; } } + if (!defined $suppress_export{$linenr} && + $prevline =~ /^.\s*$/ && + ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ || + $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { +#print "FOO B <$lines[$linenr - 1]>\n"; + $suppress_export{$linenr} = 2; + } + if (defined $suppress_export{$linenr} && + $suppress_export{$linenr} == 2) { + WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); + } # check for external initialisers. if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { -- cgit v1.2.3 From 5e8d8f6f2844d4a663415c660ab5cc92e2e2477d Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Mon, 26 Oct 2009 16:50:17 -0700 Subject: checkpatch: version 0.30 Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 88c4f6a5080..bc4114f1ab3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -10,7 +10,7 @@ use strict; my $P = $0; $P =~ s@.*/@@g; -my $V = '0.29'; +my $V = '0.30'; use Getopt::Long qw(:config no_auto_abbrev); -- cgit v1.2.3