X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=tools%2Fscripts%2Fcheckpatch.pl;h=0a119f1ba17e9c893bfbe11492aad7a8ddacbc0e;hb=e03de33c412b366f3dd45c447410dcc1df3b4b82;hp=cabfa6799668e760b2bd583d8da45cf8a6ef7d88;hpb=2f6f7c442d24ba296dd9447e254e34b817fd02b4;p=fw%2Fopenocd diff --git a/tools/scripts/checkpatch.pl b/tools/scripts/checkpatch.pl index cabfa6799..0a119f1ba 100755 --- a/tools/scripts/checkpatch.pl +++ b/tools/scripts/checkpatch.pl @@ -43,7 +43,7 @@ Version: $V Options: -q, --quiet quiet - --no-tree run without a kernel tree + --no-tree run without a openocd tree --no-signoff do not check for 'Signed-off-by' line --patch treat FILE as patchfile (default) --emacs emacs compile window format @@ -52,7 +52,7 @@ Options: --subjective, --strict enable more subjective tests --ignore TYPE(,TYPE2...) ignore various comma separated message types --show-types show the message "types" in the output - --root=PATH PATH to the kernel tree root + --root=PATH PATH to the openocd tree root --no-summary suppress the per-file summary --mailback only produce a report in case of warnings/errors --summary-file include the filename in summary @@ -165,14 +165,14 @@ if ($tree) { } else { if (top_of_kernel_tree('.')) { $root = '.'; - } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ && + } elsif ($0 =~ m@(.*)/tools/scripts/[^/]*$@ && top_of_kernel_tree($1)) { $root = $1; } } if (!defined $root) { - print "Must be run from the top-level dir. of a kernel tree\n"; + print "Must be run from the top-level dir. of a openocd tree\n"; exit(2); } } @@ -261,7 +261,8 @@ our $logFunctions = qr{(?x: [a-z0-9]+_(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| WARN(?:_RATELIMIT|_ONCE|)| panic| - MODULE_[A-Z_]+ + MODULE_[A-Z_]+| + LOG_(?:DEBUG|INFO|WARNING|ERROR|USER|USER_N|OUTPUT)+ )}; our $signature_tags = qr{(?xi: @@ -400,9 +401,8 @@ sub top_of_kernel_tree { my ($root) = @_; my @tree_check = ( - "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", - "README", "Documentation", "arch", "include", "drivers", - "fs", "init", "ipc", "kernel", "lib", "scripts", + "AUTHORS", "BUGS", "COPYING", "HACKING", "Makefile.am", + "README", "contrib", "doc", "src", "tcl", "testing", "tools", ); foreach my $check (@tree_check) { @@ -445,6 +445,8 @@ sub parse_email { $address = ""; $comment = ""; } + } elsif ($formatted_email eq "jenkins") { + $address = "jenkins" } $name =~ s/^\s+|\s+$//g; @@ -697,7 +699,7 @@ sub ctx_statement_block { # An else is really a conditional as long as its not else if if ($level == 0 && $coff_set == 0 && (!defined($p) || $p =~ /(?:\s|\}|\+)/) && - $remainder =~ /^(else)(?:\s|{)/ && + $remainder =~ /^(else)(?:\s|\{)/ && $remainder !~ /^else\s+if\b/) { $coff = $off + length($1) - 1; $coff_set = 1; @@ -780,7 +782,7 @@ sub statement_block_size { my ($stmt) = @_; $stmt =~ s/(^|\n)./$1/g; - $stmt =~ s/^\s*{//; + $stmt =~ s/^\s*\{//; $stmt =~ s/}\s*$//; $stmt =~ s/^\s*//; $stmt =~ s/\s*$//; @@ -1134,7 +1136,7 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N'; - } elsif ($cur =~/^(;|{|})/) { + } elsif ($cur =~/^(;|\{|})/) { print "END($1)\n" if ($dbg_values > 1); $type = 'E'; $av_pend_colon = 'O'; @@ -1629,6 +1631,16 @@ sub process { $rpt_cleaners = 1; } + if ($rawline =~ /\bwrite to the Free/i || + $rawline =~ /\b59\s+Temple\s+Pl/i || + $rawline =~ /\b51\s+Franklin\s+St/i) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + ERROR("FSF_MAILING_ADDRESS", + "Do not include the paragraph about writing to the Free Software Foundation's mailing address " . + "from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. " . + "OpenOCD already includes a copy of the GPL.\n" . $herevet) + } + # check for Kconfig help text having a real description # Only applies when adding the entry originally, after that we do not have # sufficient context to determine whether it is indeed long enough. @@ -1664,15 +1676,15 @@ sub process { # check we are in a valid source file if not then ignore this hunk next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); -#100 column limit +#120 column limit if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && $rawline !~ /^.\s*\*\s*\@$Ident\s/ && !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ || $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && - $length > 100) + $length > 120) { WARN("LONG_LINE", - "line over 100 characters\n" . $herecurr); + "line over 120 characters\n" . $herecurr); } # check for spaces before a quoted newline @@ -1721,6 +1733,9 @@ sub process { "please, no space before tabs\n" . $herevet); } +# check we are in a valid C source file if not then ignore this hunk + next if ($realfile !~ /\.(h|c)$/); + # check for spaces at the beginning of a line. # Exceptions: # 1) within comments @@ -1732,9 +1747,6 @@ sub process { "please, no spaces at the start of a line\n" . $herevet); } -# check we are in a valid C source file if not then ignore this hunk - next if ($realfile !~ /\.(h|c)$/); - # check for RCS/CVS revision markers if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { WARN("CVS_KEYWORD", @@ -1771,7 +1783,7 @@ sub process { } my $s = $stat; - $s =~ s/{.*$//s; + $s =~ s/\{.*$//s; # Ignore goto labels. if ($s =~ /$Ident:\*$/s) { @@ -1867,7 +1879,7 @@ sub process { #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n"; #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; - if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { + if ($ctx !~ /\{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*\{/) { ERROR("OPEN_BRACE", "that open brace { should be on the previous line\n" . "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); @@ -1908,7 +1920,7 @@ sub process { my $continuation = 0; my $check = 0; $s =~ s/^.*\bdo\b//; - $s =~ s/^\s*{//; + $s =~ s/^\s*\{//; if ($s =~ s/^\s*\\//) { $continuation = 1; } @@ -2012,7 +2024,7 @@ sub process { } # check for initialisation to aggregates open brace on the next line - if ($line =~ /^.\s*{/ && + if ($line =~ /^.\s*\{/ && $prevline =~ /(?:^|[^=])=\s*$/) { ERROR("OPEN_BRACE", "that open brace { should be on the previous line\n" . $hereprev); @@ -2212,14 +2224,14 @@ sub process { # function brace can't be on same line, except for #defines of do while, # or if closed on same line - if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and - !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { + if (($line=~/$Type\s*$Ident\(.*\).*\s\{/) and + !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) { ERROR("OPEN_BRACE", "open brace '{' following function declarations go on the next line\n" . $herecurr); } # open braces for enum, union and struct go on the same line. - if ($line =~ /^.\s*{/ && + if ($line =~ /^.\s*\{/ && $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { ERROR("OPEN_BRACE", "open brace '{' following $1 go on the same line\n" . $hereprev); @@ -2239,7 +2251,7 @@ sub process { my ($where, $prefix) = ($-[1], $1); if ($prefix !~ /$Type\s+$/ && ($where != 0 || $prefix !~ /^.\s+$/) && - $prefix !~ /{\s+$/) { + $prefix !~ /\{\s+$/) { ERROR("BRACKET_SPACE", "space prohibited before open square bracket '['\n" . $herecurr); } @@ -2481,8 +2493,8 @@ sub process { ## } #need space before brace following if, while, etc - if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || - $line =~ /do{/) { + if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) || + $line =~ /do\{/) { ERROR("SPACING", "space required before the open brace '{'\n" . $herecurr); } @@ -2586,7 +2598,7 @@ sub process { # Check for illegal assignment in if conditional -- and check for trailing # statements after the conditional. - if ($line =~ /do\s*(?!{)/) { + if ($line =~ /do\s*(?!\{)/) { my ($stat_next) = ctx_statement_block($line_nr_next, $remain_next, $off_next); $stat_next =~ s/\n./\n /g; @@ -2618,7 +2630,7 @@ sub process { substr($s, 0, length($c), ''); $s =~ s/\n.*//g; $s =~ s/$;//g; # Remove any comments - if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ && + if (length($c) && $s !~ /^\s*\{?\s*\\*\s*$/ && $c !~ /}\s*while\s*/) { # Find out how long the conditional actually is. @@ -2657,7 +2669,7 @@ sub process { if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { my $s = $1; $s =~ s/$;//g; # Remove any comments - if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { + if ($s !~ /^\s*(?:\sif|(?:\{|)\s*\\?\s*$)/) { ERROR("TRAILING_STATEMENTS", "trailing statements should be on next line\n" . $herecurr); } @@ -2867,7 +2879,7 @@ sub process { substr($block, 0, length($cond), ''); - $seen++ if ($block =~ /^\s*{/); + $seen++ if ($block =~ /^\s*\{/); #print "cond<$cond> block<$block> allowed<$allowed>\n"; if (statement_lines($cond) > 1) { @@ -2961,11 +2973,11 @@ sub process { } # no volatiles please - my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; - if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { - WARN("VOLATILE", - "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); - } +# my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; +# if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { +# WARN("VOLATILE", +# "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); +# } # warn about #if 0 if ($line =~ /^.\s*\#\s*if\s+0\b/) { @@ -3064,16 +3076,16 @@ sub process { } # Check for __attribute__ packed, prefer __packed - if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { - WARN("PREFER_PACKED", - "__packed is preferred over __attribute__((packed))\n" . $herecurr); - } +# if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { +# WARN("PREFER_PACKED", +# "__packed is preferred over __attribute__((packed))\n" . $herecurr); +# } # Check for __attribute__ aligned, prefer __aligned - if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { - WARN("PREFER_ALIGNED", - "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); - } +# if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { +# WARN("PREFER_ALIGNED", +# "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); +# } # check for sizeof(&) if ($line =~ /\bsizeof\s*\(\s*\&/) { @@ -3329,7 +3341,8 @@ sub process { $vname has style problems, please review. If any of these errors are false positives, please report -them to the maintainer, see CHECKPATCH in MAINTAINERS. +them to the openocd-devel mailing list or prepare a patch +and send it to Gerrit for review. EOM }