X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=scripts%2Fcheckpatch.pl;h=bc6779398229757a94a44a4d3ef4a70dbf618a49;hb=efba91bd9066890ae93270eb3d0e55de43368f0b;hp=077a2ca33043fd7ab137798a6ecdd545f256a30b;hpb=7429c6903e3628fc2cfea65ec7e13bac030c7bfe;p=pandora-kernel.git diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 077a2ca33043..bc6779398229 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -9,7 +9,7 @@ use strict; my $P = $0; $P =~ s@.*/@@g; -my $V = '0.20'; +my $V = '0.21'; use Getopt::Long qw(:config no_auto_abbrev); @@ -168,12 +168,11 @@ our @modifierList = ( ); sub build_types { - my $mods = "(?: \n" . join("|\n ", @modifierList) . "\n)"; - my $all = "(?: \n" . join("|\n ", @typeList) . "\n)"; + my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; + my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; $NonptrType = qr{ - (?:const\s+)? - (?:$mods\s+)? + (?:$Modifier\s+|const\s+)* (?: (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\)| (?:${all}\b) @@ -690,17 +689,20 @@ sub cat_vet { my $av_preprocessor = 0; my $av_pending; my @av_paren_type; +my $av_pend_colon; sub annotate_reset { $av_preprocessor = 0; $av_pending = '_'; @av_paren_type = ('E'); + $av_pend_colon = 'O'; } sub annotate_values { my ($stream, $type) = @_; my $res; + my $var = '_' x length($stream); my $cur = $stream; print "$stream\n" if ($dbg_values > 1); @@ -716,7 +718,7 @@ sub annotate_values { $av_preprocessor = 0; } - } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\))/) { + } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\()/) { print "DECLARE($1)\n" if ($dbg_values > 1); $type = 'T'; @@ -785,7 +787,12 @@ sub annotate_values { $av_pending = 'N'; $type = 'N'; - } elsif ($cur =~/^(return|case|else|goto)/o) { + } elsif ($cur =~/^(case)/o) { + print "CASE($1)\n" if ($dbg_values > 1); + $av_pend_colon = 'C'; + $type = 'N'; + + } elsif ($cur =~/^(return|else|goto)/o) { print "KEYWORD($1)\n" if ($dbg_values > 1); $type = 'N'; @@ -810,6 +817,15 @@ sub annotate_values { $type = 'V'; $av_pending = 'V'; + } elsif ($cur =~ /^($Ident\s*):/) { + if ($type eq 'E') { + $av_pend_colon = 'L'; + } elsif ($type eq 'T') { + $av_pend_colon = 'B'; + } + print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1); + $type = 'V'; + } elsif ($cur =~ /^($Ident|$Constant)/o) { print "IDENT($1)\n" if ($dbg_values > 1); $type = 'V'; @@ -821,11 +837,40 @@ sub annotate_values { } elsif ($cur =~/^(;|{|})/) { print "END($1)\n" if ($dbg_values > 1); $type = 'E'; + $av_pend_colon = 'O'; + + } elsif ($cur =~ /^(\?)/o) { + print "QUESTION($1)\n" if ($dbg_values > 1); + $type = 'N'; + + } elsif ($cur =~ /^(:)/o) { + print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1); - } elsif ($cur =~ /^(;|\?|:|\[)/o) { + substr($var, length($res), 1, $av_pend_colon); + if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') { + $type = 'E'; + } else { + $type = 'N'; + } + $av_pend_colon = 'O'; + + } elsif ($cur =~ /^(;|\[)/o) { print "CLOSE($1)\n" if ($dbg_values > 1); $type = 'N'; + } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&(?!\&))/o) { + my $variant; + + print "OPV($1)\n" if ($dbg_values > 1); + if ($type eq 'V') { + $variant = 'B'; + } else { + $variant = 'U'; + } + + substr($var, length($res), 1, $variant); + $type = 'N'; + } elsif ($cur =~ /^($Operators)/o) { print "OP($1)\n" if ($dbg_values > 1); if ($1 ne '++' && $1 ne '--') { @@ -841,14 +886,14 @@ sub annotate_values { } } - return $res; + return ($res, $var); } sub possible { my ($possible, $line) = @_; print "CHECK<$possible> ($line)\n" if ($dbg_possible > 1); - if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ && + if ($possible !~ /^(?:$Modifier|$Storage|$Type|DEFINE_\S+)$/ && $possible ne 'goto' && $possible ne 'return' && $possible ne 'case' && $possible ne 'else' && $possible ne 'asm' && $possible ne '__asm__' && @@ -860,8 +905,10 @@ sub possible { } elsif ($possible =~ /\s/) { $possible =~ s/\s*$Type\s*//g; - warn "MODIFIER: $possible ($line)\n" if ($dbg_possible); - push(@modifierList, $possible); + for my $modifier (split(' ', $possible)) { + warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible); + push(@modifierList, $modifier); + } } else { warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); @@ -1187,7 +1234,7 @@ sub process { } elsif ($s =~ /^.\s*$Ident\s*\(/s) { # declarations always start with types - } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))\s*(?:;|=|,|\()/s) { + } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) { my $type = $1; $type =~ s/\s+/ /g; possible($type, "A:" . $s); @@ -1293,12 +1340,14 @@ sub process { # Track the 'values' across context and added lines. my $opline = $line; $opline =~ s/^./ /; - my $curr_values = annotate_values($opline . "\n", $prev_values); + my ($curr_values, $curr_vars) = + annotate_values($opline . "\n", $prev_values); $curr_values = $prev_values . $curr_values; if ($dbg_values) { my $outline = $opline; $outline =~ s/\t/ /g; print "$linenr > .$outline\n"; print "$linenr > $curr_values\n"; + print "$linenr > $curr_vars\n"; } $prev_values = substr($curr_values, -1); @@ -1386,11 +1435,11 @@ sub process { ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . $herecurr); - } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { + } elsif ($line =~ m{\b$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . $herecurr); - } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { + } elsif ($line =~ m{\b$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . $herecurr); } @@ -1489,7 +1538,8 @@ sub process { <<=|>>=|<=|>=|==|!=| \+=|-=|\*=|\/=|%=|\^=|\|=|&=| =>|->|<<|>>|<|>|=|!|~| - &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% + &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| + \?|: }x; my @elements = split(/($ops|;)/, $opline); my $off = 0; @@ -1536,22 +1586,11 @@ sub process { my $ptr = substr($blank, 0, $off) . "^"; my $hereptr = "$hereline$ptr\n"; - # Classify operators into binary, unary, or - # definitions (* only) where they have more - # than one mode. + # Pull out the value of this operator. my $op_type = substr($curr_values, $off + 1, 1); - my $op_left = substr($curr_values, $off, 1); - my $is_unary; - if ($op_type eq 'T') { - $is_unary = 2; - } elsif ($op_left eq 'V') { - $is_unary = 0; - } else { - $is_unary = 1; - } - #if ($op eq '-' || $op eq '&' || $op eq '*') { - # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; - #} + + # Get the full operator variant. + my $opv = $op . substr($curr_vars, $off, 1); # Ignore operators passed as parameters. if ($op_type ne 'V' && @@ -1570,8 +1609,10 @@ sub process { # // is a comment } elsif ($op eq '//') { - # -> should have no spaces - } elsif ($op eq '->') { + # No spaces for: + # -> + # : when part of a bitfield + } elsif ($op eq '->' || $opv eq ':B') { if ($ctx =~ /Wx.|.xW/) { ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); } @@ -1583,18 +1624,19 @@ sub process { } # '*' as part of a type definition -- reported already. - } elsif ($op eq '*' && $is_unary == 2) { + } elsif ($opv eq '*_') { #warn "'*' is part of type\n"; # unary operators should have a space before and # none after. May be left adjacent to another # unary operator, or a cast } elsif ($op eq '!' || $op eq '~' || - ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) { + $opv eq '*U' || $opv eq '-U' || + $opv eq '&U') { if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { ERROR("space required before that '$op' $at\n" . $hereptr); } - if ($op eq '*' && $cc =~/\s*const\b/) { + if ($op eq '*' && $cc =~/\s*const\b/) { # A unary '*' may be const } elsif ($ctx =~ /.xW/) { @@ -1627,11 +1669,33 @@ sub process { $hereptr); } + # A colon needs no spaces before when it is + # terminating a case value or a label. + } elsif ($opv eq ':C' || $opv eq ':L') { + if ($ctx =~ /Wx./) { + ERROR("space prohibited before that '$op' $at\n" . $hereptr); + } + # All the others need spaces both sides. } elsif ($ctx !~ /[EWC]x[CWE]/) { + my $ok = 0; + # Ignore email addresses - if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && - !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { + if (($op eq '<' && + $cc =~ /^\S+\@\S+>/) || + ($op eq '>' && + $ca =~ /<\S+\@\S+$/)) + { + $ok = 1; + } + + # Ignore ?: + if (($opv eq ':O' && $ca =~ /\?$/) || + ($op eq '?' && $cc =~ /^:/)) { + $ok = 1; + } + + if ($ok == 0) { ERROR("spaces required around that '$op' $at\n" . $hereptr); } } @@ -1861,7 +1925,8 @@ sub process { # multi-statement macros should be enclosed in a do while loop, grab the # first statement and ensure its the whole macro if its not enclosed # in a known good container - if ($line =~ /^.\s*\#\s*define\s*$Ident(\()?/) { + if ($realfile !~ m@/vmlinux.lds.h$@ && + $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) { my $ln = $linenr; my $cnt = $realcnt; my ($off, $dstat, $dcond, $rest); @@ -1907,6 +1972,7 @@ sub process { } else { $dstat =~ s/^.\s*\#\s*define\s+$Ident\s*//; } + $dstat =~ s/$;//g; $dstat =~ s/\\\n.//g; $dstat =~ s/^\s*//s; $dstat =~ s/\s*$//s;