2 # (c) 2001, Dave Jones. (the file handling bit)
3 # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
4 # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
5 # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
6 # Licensed under the terms of the GNU GPL License version 2
15 use Getopt
::Long
qw(:config no_auto_abbrev);
35 my $configuration_file = ".checkpatch.conf";
41 Usage
: $P [OPTION
]... [FILE
]...
46 --no-tree run without a openocd tree
47 --no-signoff
do not check
for 'Signed-off-by' line
48 --patch treat FILE as patchfile
(default)
49 --emacs emacs compile window format
50 --terse one line per report
51 -f
, --file treat FILE as regular source file
52 --subjective
, --strict enable more subjective tests
53 --ignore TYPE
(,TYPE2
...) ignore various comma separated message types
54 --show
-types show the message
"types" in the output
55 --root
=PATH PATH to the openocd tree root
56 --no-summary suppress the per
-file summary
57 --mailback only produce a report
in case of warnings
/errors
58 --summary
-file include the filename
in summary
59 --debug KEY
=[0|1] turn on
/off debugging of KEY
, where KEY is one of
60 'values', 'possible', 'type', and 'attr' (default
62 --test
-only
=WORD report only warnings
/errors containing WORD
64 -h
, --help
, --version display this help
and exit
66 When FILE is
- read standard input
.
72 my $conf = which_conf
($configuration_file);
75 open(my $conffile, '<', "$conf")
76 or warn "$P: Can't find a readable $configuration_file file $!\n";
81 $line =~ s/\s*\n?$//g;
85 next if ($line =~ m/^\s*#/);
86 next if ($line =~ m/^\s*$/);
88 my @words = split(" ", $line);
89 foreach my $word (@words) {
90 last if ($word =~ m/^#/);
91 push (@conf_args, $word);
95 unshift(@ARGV, @conf_args) if @conf_args;
99 'q|quiet+' => \
$quiet,
101 'signoff!' => \
$chk_signoff,
102 'patch!' => \
$chk_patch,
106 'subjective!' => \
$check,
107 'strict!' => \
$check,
108 'ignore=s' => \
@ignore,
109 'show-types!' => \
$show_types,
111 'summary!' => \
$summary,
112 'mailback!' => \
$mailback,
113 'summary-file!' => \
$summary_file,
115 'debug=s' => \
%debug,
116 'test-only=s' => \
$tst_only,
126 print "$P: no input files\n";
130 @ignore = split(/,/, join(',',@ignore));
131 foreach my $word (@ignore) {
132 $word =~ s/\s*\n?$//g;
135 $word =~ tr/[a-z]/[A-Z]/;
137 next if ($word =~ m/^\s*#/);
138 next if ($word =~ m/^\s*$/);
140 $ignore_type{$word}++;
144 my $dbg_possible = 0;
147 for my $key (keys %debug) {
149 eval "\${dbg_$key} = '$debug{$key}';";
153 my $rpt_cleaners = 0;
162 if (!top_of_kernel_tree
($root)) {
163 die "$P: $root: --root does not point at a valid tree\n";
166 if (top_of_kernel_tree
('.')) {
168 } elsif ($0 =~ m@
(.*)/tools/scripts
/[^/]*$@
&&
169 top_of_kernel_tree
($1)) {
174 if (!defined $root) {
175 print "Must be run from the top-level dir. of a openocd tree\n";
180 my $emitted_corrupt = 0;
183 [A
-Za
-z_
][A
-Za
-z\d_
]*
184 (?
:\s
*\#\#\s
*[A
-Za
-z_
][A
-Za
-z\d_
]*)*
186 our $Storage = qr{extern|static|asmlinkage};
199 # Notes to $Attribute:
200 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
219 __
(?
:mem
|cpu
|dev
|)(?
:initdata
|initconst
|init
\b)|
220 ____cacheline_aligned
|
221 ____cacheline_aligned_in_smp
|
222 ____cacheline_internodealigned_in_smp
|
226 our $Inline = qr{inline|__always_inline|noinline};
227 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
228 our $Lval = qr{$Ident(?:$Member)*};
230 our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*};
231 our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
232 our $Compare = qr{<=|>=|==|!=|<|>};
236 &&|\
|\
||,|\
^|\
+\
+|--|&|\
||\
+|-|\
*|\
/|%
244 [\x09\x0A\x0D\x20-\x7E] # ASCII
245 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
246 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
247 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
248 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
249 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
250 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
251 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
254 our $typeTypedefs = qr{(?x
:
255 (?
:__
)?
(?
:u
|s
|be
|le)(?
:8|16|32|64)|
259 our $logFunctions = qr{(?x
:
260 printk
(?
:_ratelimited
|_once
|)|
261 [a
-z0
-9]+_
(?
:printk
|emerg
|alert
|crit
|err
|warning
|warn|notice
|info
|debug
|dbg
|vdbg
|devel
|cont
|WARN
)(?
:_ratelimited
|_once
|)|
262 WARN
(?
:_RATELIMIT
|_ONCE
|)|
265 LOG_
(?
:DEBUG
|INFO
|WARNING
|ERROR
|USER
|USER_N
|OUTPUT
)+
268 our $signature_tags = qr{(?xi
:
280 qr{(?:unsigned\s+)?char},
281 qr{(?:unsigned\s+)?short},
282 qr{(?:unsigned\s+)?int},
283 qr{(?:unsigned\s+)?long},
284 qr{(?:unsigned\s+)?long\s+int},
285 qr{(?:unsigned\s+)?long\s+long},
286 qr{(?:unsigned\s+)?long\s+long\s+int},
295 qr{${Ident}_handler
},
296 qr{${Ident}_handler_fn
},
298 our @modifierList = (
302 our $allowed_asm_includes = qr{(?x
:
306 # memory.h: ARM has a custom one
309 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
310 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
311 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
313 (?
:$Modifier\s
+|const\s
+)*
315 (?
:typeof
|__typeof__
)\s
*\
(\s
*\
**\s
*$Ident\s
*\
)|
319 (?
:\s
+$Modifier|\s
+const
)*
323 (?
:[\s\
*]+\s
*const
|[\s\
*]+|(?
:\s
*\
[\s
*\
])+)?
324 (?
:\s
+$Inline|\s
+$Modifier)*
326 $Declare = qr{(?:$Storage\s+)?$Type};
330 our $match_balanced_parentheses = qr/(\((?:[^\(\)]+|(-1))*\))/;
332 our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s
*};
333 our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s
*};
337 return "" if (!defined($string));
338 $string =~ s@
^\s
*\
(\s
*@
@g;
339 $string =~ s@\s
*\
)\s
*$@
@g;
340 $string =~ s@\s
+@
@g;
344 $chk_signoff = 0 if ($file);
346 my @dep_includes = ();
347 my @dep_functions = ();
348 my $removal = "Documentation/feature-removal-schedule.txt";
349 if ($tree && -f
"$root/$removal") {
350 open(my $REMOVE, '<', "$root/$removal") ||
351 die "$P: $removal: open failed - $!\n";
353 if (/^Check:\s+(.*\S)/) {
354 for my $entry (split(/[, ]+/, $1)) {
355 if ($entry =~ m
@include/(.*)@
) {
356 push(@dep_includes, $1);
358 } elsif ($entry !~ m@
/@
) {
359 push(@dep_functions, $entry);
370 for my $filename (@ARGV) {
373 open($FILE, '-|', "diff -u /dev/null $filename") ||
374 die "$P: $filename: diff failed - $!\n";
375 } elsif ($filename eq '-') {
376 open($FILE, '<&STDIN');
378 open($FILE, '<', "$filename") ||
379 die "$P: $filename: open failed - $!\n";
381 if ($filename eq '-') {
382 $vname = 'Your patch';
391 if (!process
($filename)) {
400 sub top_of_kernel_tree
{
404 "AUTHORS", "BUGS", "COPYING", "HACKING", "Makefile.am",
405 "README", "contrib", "doc", "src", "tcl", "testing", "tools",
408 foreach my $check (@tree_check) {
409 if (! -e
$root . '/' . $check) {
417 my ($formatted_email) = @_;
423 if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
426 $comment = $3 if defined $3;
427 } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
429 $comment = $2 if defined $2;
430 } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
432 $comment = $2 if defined $2;
433 $formatted_email =~ s/$address.*$//;
434 $name = $formatted_email;
435 $name =~ s/^\s+|\s+$//g;
436 $name =~ s/^\"|\"$//g;
437 # If there's a name left after stripping spaces and
438 # leading quotes, and the address doesn't have both
439 # leading and trailing angle brackets, the address
441 # "joe smith joe@smith.com" bad
442 # "joe smith <joe@smith.com" bad
443 if ($name ne "" && $address !~ /^<[^>]+>$/) {
448 } elsif ($formatted_email eq "jenkins") {
452 $name =~ s/^\s+|\s+$//g;
453 $name =~ s/^\"|\"$//g;
454 $address =~ s/^\s+|\s+$//g;
455 $address =~ s/^\<|\>$//g;
457 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
458 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
462 return ($name, $address, $comment);
466 my ($name, $address) = @_;
470 $name =~ s/^\s+|\s+$//g;
471 $name =~ s/^\"|\"$//g;
472 $address =~ s/^\s+|\s+$//g;
474 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
475 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
480 $formatted_email = "$address";
482 $formatted_email = "$name <$address>";
485 return $formatted_email;
491 foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
492 if (-e
"$path/$conf") {
493 return "$path/$conf";
505 for my $c (split(//, $str)) {
509 for (; ($n % 4) != 0; $n++) {
521 (my $res = shift) =~ tr/\t/ /c;
528 # Drop the diff line leader and expand tabs
530 $line = expand_tabs
($line);
532 # Pick the indent from the front of the line.
533 my ($white) = ($line =~ /^(\s*)/);
535 return (length($line), length($white));
538 my $sanitise_quote = '';
540 sub sanitise_line_reset
{
541 my ($in_comment) = @_;
544 $sanitise_quote = '*/';
546 $sanitise_quote = '';
559 # Always copy over the diff marker.
560 $res = substr($line, 0, 1);
562 for ($off = 1; $off < length($line); $off++) {
563 $c = substr($line, $off, 1);
565 # Comments we are wacking completly including the begin
566 # and end, all to $;.
567 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
568 $sanitise_quote = '*/';
570 substr($res, $off, 2, "$;$;");
574 if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
575 $sanitise_quote = '';
576 substr($res, $off, 2, "$;$;");
580 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
581 $sanitise_quote = '//';
583 substr($res, $off, 2, $sanitise_quote);
588 # A \ in a string means ignore the next character.
589 if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
591 substr($res, $off, 2, 'XX');
596 if ($c eq "'" || $c eq '"') {
597 if ($sanitise_quote eq '') {
598 $sanitise_quote = $c;
600 substr($res, $off, 1, $c);
602 } elsif ($sanitise_quote eq $c) {
603 $sanitise_quote = '';
607 #print "c<$c> SQ<$sanitise_quote>\n";
608 if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
609 substr($res, $off, 1, $;);
610 } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
611 substr($res, $off, 1, $;);
612 } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
613 substr($res, $off, 1, 'X');
615 substr($res, $off, 1, $c);
619 if ($sanitise_quote eq '//') {
620 $sanitise_quote = '';
623 # The pathname on a #include may be surrounded by '<' and '>'.
624 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
625 my $clean = 'X' x
length($1);
626 $res =~ s@\
<.*\
>@
<$clean>@
;
628 # The whole of a #error is a string.
629 } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
630 my $clean = 'X' x
length($1);
631 $res =~ s@
(\#\s
*(?
:error
|warning
)\s
+).*@
$1$clean@
;
637 sub ctx_statement_block
{
638 my ($linenr, $remain, $off) = @_;
639 my $line = $linenr - 1;
656 @stack = (['', 0]) if ($#stack == -1);
658 #warn "CSB: blk<$blk> remain<$remain>\n";
659 # If we are about to drop off the end, pull in more
662 for (; $remain > 0; $line++) {
663 last if (!defined $lines[$line]);
664 next if ($lines[$line] =~ /^-/);
667 $blk .= $lines[$line] . "\n";
672 # Bail if there is no further context.
673 #warn "CSB: blk<$blk> off<$off> len<$len>\n";
679 $c = substr($blk, $off, 1);
680 $remainder = substr($blk, $off);
682 #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
684 # Handle nested #if/#else.
685 if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
686 push(@stack, [ $type, $level ]);
687 } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
688 ($type, $level) = @
{$stack[$#stack - 1]};
689 } elsif ($remainder =~ /^#\s*endif\b/) {
690 ($type, $level) = @
{pop(@stack)};
693 # Statement ends at the ';' or a close '}' at the
695 if ($level == 0 && $c eq ';') {
699 # An else is really a conditional as long as its not else if
700 if ($level == 0 && $coff_set == 0 &&
701 (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
702 $remainder =~ /^(else)(?:\s|{)/ &&
703 $remainder !~ /^else\s+if\b/) {
704 $coff = $off + length($1) - 1;
706 #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
707 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
710 if (($type eq '' || $type eq '(') && $c eq '(') {
714 if ($type eq '(' && $c eq ')') {
716 $type = ($level != 0)?
'(' : '';
718 if ($level == 0 && $coff < $soff) {
721 #warn "CSB: mark coff<$coff>\n";
724 if (($type eq '' || $type eq '{') && $c eq '{') {
728 if ($type eq '{' && $c eq '}') {
730 $type = ($level != 0)?
'{' : '';
733 if (substr($blk, $off + 1, 1) eq ';') {
741 # We are truly at the end, so shuffle to the next line.
748 my $statement = substr($blk, $soff, $off - $soff + 1);
749 my $condition = substr($blk, $soff, $coff - $soff + 1);
751 #warn "STATEMENT<$statement>\n";
752 #warn "CONDITION<$condition>\n";
754 #print "coff<$coff> soff<$off> loff<$loff>\n";
756 return ($statement, $condition,
757 $line, $remain + 1, $off - $loff + 1, $level);
760 sub statement_lines
{
763 # Strip the diff line prefixes and rip blank lines at start and end.
764 $stmt =~ s/(^|\n)./$1/g;
768 my @stmt_lines = ($stmt =~ /\n/g);
770 return $#stmt_lines + 2;
773 sub statement_rawlines
{
776 my @stmt_lines = ($stmt =~ /\n/g);
778 return $#stmt_lines + 2;
781 sub statement_block_size
{
784 $stmt =~ s/(^|\n)./$1/g;
790 my @stmt_lines = ($stmt =~ /\n/g);
791 my @stmt_statements = ($stmt =~ /;/g);
793 my $stmt_lines = $#stmt_lines + 2;
794 my $stmt_statements = $#stmt_statements + 1;
796 if ($stmt_lines > $stmt_statements) {
799 return $stmt_statements;
803 sub ctx_statement_full
{
804 my ($linenr, $remain, $off) = @_;
805 my ($statement, $condition, $level);
809 # Grab the first conditional/block pair.
810 ($statement, $condition, $linenr, $remain, $off, $level) =
811 ctx_statement_block
($linenr, $remain, $off);
812 #print "F: c<$condition> s<$statement> remain<$remain>\n";
813 push(@chunks, [ $condition, $statement ]);
814 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
815 return ($level, $linenr, @chunks);
818 # Pull in the following conditional/block pairs and see if they
819 # could continue the statement.
821 ($statement, $condition, $linenr, $remain, $off, $level) =
822 ctx_statement_block
($linenr, $remain, $off);
823 #print "C: c<$condition> s<$statement> remain<$remain>\n";
824 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
826 push(@chunks, [ $condition, $statement ]);
829 return ($level, $linenr, @chunks);
833 my ($linenr, $remain, $outer, $open, $close, $off) = @_;
835 my $start = $linenr - 1;
842 my @stack = ($level);
843 for ($line = $start; $remain > 0; $line++) {
844 next if ($rawlines[$line] =~ /^-/);
847 $blk .= $rawlines[$line];
849 # Handle nested #if/#else.
850 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
851 push(@stack, $level);
852 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
853 $level = $stack[$#stack - 1];
854 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
855 $level = pop(@stack);
858 foreach my $c (split(//, $lines[$line])) {
859 ##print "C<$c>L<$level><$open$close>O<$off>\n";
865 if ($c eq $close && $level > 0) {
867 last if ($level == 0);
868 } elsif ($c eq $open) {
873 if (!$outer || $level <= 1) {
874 push(@res, $rawlines[$line]);
877 last if ($level == 0);
880 return ($level, @res);
882 sub ctx_block_outer
{
883 my ($linenr, $remain) = @_;
885 my ($level, @r) = ctx_block_get
($linenr, $remain, 1, '{', '}', 0);
889 my ($linenr, $remain) = @_;
891 my ($level, @r) = ctx_block_get
($linenr, $remain, 0, '{', '}', 0);
895 my ($linenr, $remain, $off) = @_;
897 my ($level, @r) = ctx_block_get
($linenr, $remain, 0, '(', ')', $off);
900 sub ctx_block_level
{
901 my ($linenr, $remain) = @_;
903 return ctx_block_get
($linenr, $remain, 0, '{', '}', 0);
905 sub ctx_statement_level
{
906 my ($linenr, $remain, $off) = @_;
908 return ctx_block_get
($linenr, $remain, 0, '(', ')', $off);
911 sub ctx_locate_comment
{
912 my ($first_line, $end_line) = @_;
914 # Catch a comment on the end of the line itself.
915 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@
.*(/\*.*\*/)\s
*(?
:\\\s
*)?
$@
);
916 return $current_comment if (defined $current_comment);
918 # Look through the context and try and figure out if there is a
921 $current_comment = '';
922 for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
923 my $line = $rawlines[$linenr - 1];
925 if ($linenr == $first_line and $line =~ m@
^.\s
*\
*@
) {
928 if ($line =~ m@
/\
*@
) {
931 if (!$in_comment && $current_comment ne '') {
932 $current_comment = '';
934 $current_comment .= $line . "\n" if ($in_comment);
935 if ($line =~ m@\
*/@
) {
940 chomp($current_comment);
941 return($current_comment);
943 sub ctx_has_comment
{
944 my ($first_line, $end_line) = @_;
945 my $cmt = ctx_locate_comment
($first_line, $end_line);
947 ##print "LINE: $rawlines[$end_line - 1 ]\n";
948 ##print "CMMT: $cmt\n";
954 my ($linenr, $cnt) = @_;
956 my $offset = $linenr - 1;
961 $line = $rawlines[$offset++];
962 next if (defined($line) && $line =~ /^-/);
974 while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
977 $coded = sprintf("^%c", unpack('C', $2) + 64);
986 my $av_preprocessor = 0;
992 $av_preprocessor = 0;
994 @av_paren_type = ('E');
995 $av_pend_colon = 'O';
998 sub annotate_values
{
999 my ($stream, $type) = @_;
1002 my $var = '_' x
length($stream);
1005 print "$stream\n" if ($dbg_values > 1);
1007 while (length($cur)) {
1008 @av_paren_type = ('E') if ($#av_paren_type < 0);
1009 print " <" . join('', @av_paren_type) .
1010 "> <$type> <$av_pending>" if ($dbg_values > 1);
1011 if ($cur =~ /^(\s+)/o) {
1012 print "WS($1)\n" if ($dbg_values > 1);
1013 if ($1 =~ /\n/ && $av_preprocessor) {
1014 $type = pop(@av_paren_type);
1015 $av_preprocessor = 0;
1018 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
1019 print "CAST($1)\n" if ($dbg_values > 1);
1020 push(@av_paren_type, $type);
1023 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
1024 print "DECLARE($1)\n" if ($dbg_values > 1);
1027 } elsif ($cur =~ /^($Modifier)\s*/) {
1028 print "MODIFIER($1)\n" if ($dbg_values > 1);
1031 } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
1032 print "DEFINE($1,$2)\n" if ($dbg_values > 1);
1033 $av_preprocessor = 1;
1034 push(@av_paren_type, $type);
1040 } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
1041 print "UNDEF($1)\n" if ($dbg_values > 1);
1042 $av_preprocessor = 1;
1043 push(@av_paren_type, $type);
1045 } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
1046 print "PRE_START($1)\n" if ($dbg_values > 1);
1047 $av_preprocessor = 1;
1049 push(@av_paren_type, $type);
1050 push(@av_paren_type, $type);
1053 } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
1054 print "PRE_RESTART($1)\n" if ($dbg_values > 1);
1055 $av_preprocessor = 1;
1057 push(@av_paren_type, $av_paren_type[$#av_paren_type]);
1061 } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
1062 print "PRE_END($1)\n" if ($dbg_values > 1);
1064 $av_preprocessor = 1;
1066 # Assume all arms of the conditional end as this
1067 # one does, and continue as if the #endif was not here.
1068 pop(@av_paren_type);
1069 push(@av_paren_type, $type);
1072 } elsif ($cur =~ /^(\\\n)/o) {
1073 print "PRECONT($1)\n" if ($dbg_values > 1);
1075 } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
1076 print "ATTR($1)\n" if ($dbg_values > 1);
1077 $av_pending = $type;
1080 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
1081 print "SIZEOF($1)\n" if ($dbg_values > 1);
1087 } elsif ($cur =~ /^(if|while|for)\b/o) {
1088 print "COND($1)\n" if ($dbg_values > 1);
1092 } elsif ($cur =~/^(case)/o) {
1093 print "CASE($1)\n" if ($dbg_values > 1);
1094 $av_pend_colon = 'C';
1097 } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
1098 print "KEYWORD($1)\n" if ($dbg_values > 1);
1101 } elsif ($cur =~ /^(\()/o) {
1102 print "PAREN('$1')\n" if ($dbg_values > 1);
1103 push(@av_paren_type, $av_pending);
1107 } elsif ($cur =~ /^(\))/o) {
1108 my $new_type = pop(@av_paren_type);
1109 if ($new_type ne '_') {
1111 print "PAREN('$1') -> $type\n"
1112 if ($dbg_values > 1);
1114 print "PAREN('$1')\n" if ($dbg_values > 1);
1117 } elsif ($cur =~ /^($Ident)\s*\(/o) {
1118 print "FUNC($1)\n" if ($dbg_values > 1);
1122 } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
1123 if (defined $2 && $type eq 'C' || $type eq 'T') {
1124 $av_pend_colon = 'B';
1125 } elsif ($type eq 'E') {
1126 $av_pend_colon = 'L';
1128 print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
1131 } elsif ($cur =~ /^($Ident|$Constant)/o) {
1132 print "IDENT($1)\n" if ($dbg_values > 1);
1135 } elsif ($cur =~ /^($Assignment)/o) {
1136 print "ASSIGN($1)\n" if ($dbg_values > 1);
1139 } elsif ($cur =~/^(;|{|})/) {
1140 print "END($1)\n" if ($dbg_values > 1);
1142 $av_pend_colon = 'O';
1144 } elsif ($cur =~/^(,)/) {
1145 print "COMMA($1)\n" if ($dbg_values > 1);
1148 } elsif ($cur =~ /^(\?)/o) {
1149 print "QUESTION($1)\n" if ($dbg_values > 1);
1152 } elsif ($cur =~ /^(:)/o) {
1153 print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
1155 substr($var, length($res), 1, $av_pend_colon);
1156 if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
1161 $av_pend_colon = 'O';
1163 } elsif ($cur =~ /^(\[)/o) {
1164 print "CLOSE($1)\n" if ($dbg_values > 1);
1167 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
1170 print "OPV($1)\n" if ($dbg_values > 1);
1177 substr($var, length($res), 1, $variant);
1180 } elsif ($cur =~ /^($Operators)/o) {
1181 print "OP($1)\n" if ($dbg_values > 1);
1182 if ($1 ne '++' && $1 ne '--') {
1186 } elsif ($cur =~ /(^.)/o) {
1187 print "C($1)\n" if ($dbg_values > 1);
1190 $cur = substr($cur, length($1));
1191 $res .= $type x
length($1);
1195 return ($res, $var);
1199 my ($possible, $line) = @_;
1200 my $notPermitted = qr{(?
:
1215 ^(?
:typedef
|struct
|enum
)\b
1217 warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
1218 if ($possible !~ $notPermitted) {
1219 # Check for modifiers.
1220 $possible =~ s/\s*$Storage\s*//g;
1221 $possible =~ s/\s*$Sparse\s*//g;
1222 if ($possible =~ /^\s*$/) {
1224 } elsif ($possible =~ /\s/) {
1225 $possible =~ s/\s*$Type\s*//g;
1226 for my $modifier (split(' ', $possible)) {
1227 if ($modifier !~ $notPermitted) {
1228 warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
1229 push(@modifierList, $modifier);
1234 warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
1235 push(@typeList, $possible);
1239 warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
1246 return !defined $ignore_type{$_[0]};
1250 if (!show_type
($_[1]) ||
1251 (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) {
1256 $line = "$prefix$_[0]:$_[1]: $_[2]\n";
1258 $line = "$prefix$_[0]: $_[2]\n";
1260 $line = (split('\n', $line))[0] . "\n" if ($terse);
1262 push(our @report, $line);
1271 if (report
("ERROR", $_[0], $_[1])) {
1277 if (report
("WARNING", $_[0], $_[1])) {
1283 if ($check && report
("CHECK", $_[0], $_[1])) {
1289 sub check_absolute_file
{
1290 my ($absolute, $herecurr) = @_;
1291 my $file = $absolute;
1293 ##print "absolute<$absolute>\n";
1295 # See if any suffix of this path is a path within the tree.
1296 while ($file =~ s@
^[^/]*/@@
) {
1297 if (-f
"$root/$file") {
1298 ##print "file<$file>\n";
1306 # It is, so see if the prefix is acceptable.
1307 my $prefix = $absolute;
1308 substr($prefix, -length($file)) = '';
1310 ##print "prefix<$prefix>\n";
1311 if ($prefix ne ".../") {
1312 WARN
("USE_RELATIVE_PATH",
1313 "use relative pathname instead of absolute in changelog text\n" . $herecurr);
1318 my $filename = shift;
1324 my $stashrawline="";
1341 # Trace the real file/line as we go.
1347 my $comment_edge = 0;
1351 my $prev_values = 'E';
1354 my %suppress_ifbraces;
1355 my %suppress_whiletrailers;
1356 my %suppress_export;
1358 # Pre-scan the patch sanitizing the lines.
1359 # Pre-scan the patch looking for any __setup documentation.
1361 my @setup_docs = ();
1364 sanitise_line_reset
();
1366 foreach my $rawline (@rawlines) {
1370 if ($rawline=~/^\+\+\+\s+(\S+)/) {
1372 if ($1 =~ m
@Documentation/kernel
-parameters
.txt
$@
) {
1377 if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
1386 # Guestimate if this is a continuing comment. Run
1387 # the context looking for a comment "edge". If this
1388 # edge is a close comment then we must be in a comment
1392 for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
1393 next if (defined $rawlines[$ln - 1] &&
1394 $rawlines[$ln - 1] =~ /^-/);
1396 #print "RAW<$rawlines[$ln - 1]>\n";
1397 last if (!defined $rawlines[$ln - 1]);
1398 if ($rawlines[$ln - 1] =~ m@
(/\*|\*/)@
&&
1399 $rawlines[$ln - 1] !~ m@
"[^"]*(?
:/\*|\*/)[^"]*"@
) {
1404 if (defined $edge && $edge eq '*/') {
1408 # Guestimate if this is a continuing comment. If this
1409 # is the start of a diff block and this line starts
1410 # ' *' then it is very likely a comment.
1411 if (!defined $edge &&
1412 $rawlines[$linenr] =~ m@
^.\s
*(?
:\
*\
*+| \
*)(?
:\s
|$)@
)
1417 ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
1418 sanitise_line_reset
($in_comment);
1420 } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
1421 # Standardise the strings and chars within the input to
1422 # simplify matching -- only bother with positive lines.
1423 $line = sanitise_line
($rawline);
1425 push(@lines, $line);
1428 $realcnt-- if ($line =~ /^(?:\+| |$)/);
1433 #print "==>$rawline\n";
1434 #print "-->$line\n";
1436 if ($setup_docs && $line =~ /^\+/) {
1437 push(@setup_docs, $line);
1445 foreach my $line (@lines) {
1448 my $rawline = $rawlines[$linenr - 1];
1450 #extract the line range in the file after the patch is applied
1451 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
1453 $first_line = $linenr + 1;
1463 %suppress_ifbraces = ();
1464 %suppress_whiletrailers = ();
1465 %suppress_export = ();
1468 # track the line number as we move through the hunk, note that
1469 # new versions of GNU diff omit the leading space on completely
1470 # blank context lines so we need to count that too.
1471 } elsif ($line =~ /^( |\+|$)/) {
1473 $realcnt-- if ($realcnt != 0);
1475 # Measure the line length and indent.
1476 ($length, $indent) = line_stats
($rawline);
1478 # Track the previous line.
1479 ($prevline, $stashline) = ($stashline, $line);
1480 ($previndent, $stashindent) = ($stashindent, $indent);
1481 ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
1483 #warn "line<$line>\n";
1485 } elsif ($realcnt == 1) {
1489 my $hunk_line = ($realcnt != 0);
1491 #make up the handle for any error we report on this line
1492 $prefix = "$filename:$realline: " if ($emacs && $file);
1493 $prefix = "$filename:$linenr: " if ($emacs && !$file);
1495 $here = "#$linenr: " if (!$file);
1496 $here = "#$realline: " if ($file);
1498 # extract the filename as it passes
1499 if ($line =~ /^diff --git.*?(\S+)$/) {
1501 $realfile =~ s@
^([^/]*)/@@
;
1503 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1505 $realfile =~ s@
^([^/]*)/@@
;
1508 if (!$file && $tree && $p1_prefix ne '' &&
1509 -e
"$root/$p1_prefix") {
1510 WARN
("PATCH_PREFIX",
1511 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
1514 if ($realfile =~ m@
^include
/asm/@
) {
1515 ERROR
("MODIFIED_INCLUDE_ASM",
1516 "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
1521 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
1523 my $hereline = "$here\n$rawline\n";
1524 my $herecurr = "$here\n$rawline\n";
1525 my $hereprev = "$here\n$prevrawline\n$rawline\n";
1527 $cnt_lines++ if ($realcnt != 0);
1529 # Check for incorrect file permissions
1530 if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
1531 my $permhere = $here . "FILE: $realfile\n";
1532 if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
1533 ERROR
("EXECUTE_PERMISSIONS",
1534 "do not set execute permissions for source files\n" . $permhere);
1538 # Check the patch for a signoff:
1539 if ($line =~ /^\s*signed-off-by:/i) {
1543 # Check signature styles
1544 if ($line =~ /^(\s*)($signature_tags)(\s*)(.*)/) {
1545 my $space_before = $1;
1547 my $space_after = $3;
1549 my $ucfirst_sign_off = ucfirst(lc($sign_off));
1551 if (defined $space_before && $space_before ne "") {
1552 WARN
("BAD_SIGN_OFF",
1553 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr);
1555 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
1556 WARN
("BAD_SIGN_OFF",
1557 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr);
1559 if (!defined $space_after || $space_after ne " ") {
1560 WARN
("BAD_SIGN_OFF",
1561 "Use a single space after $ucfirst_sign_off\n" . $herecurr);
1564 my ($email_name, $email_address, $comment) = parse_email
($email);
1565 my $suggested_email = format_email
(($email_name, $email_address));
1566 if ($suggested_email eq "") {
1567 ERROR
("BAD_SIGN_OFF",
1568 "Unrecognized email address: '$email'\n" . $herecurr);
1570 my $dequoted = $suggested_email;
1571 $dequoted =~ s/^"//;
1572 $dequoted =~ s/" </ </;
1573 # Don't force email to have quotes
1574 # Allow just an angle bracketed address
1575 if ("$dequoted$comment" ne $email &&
1576 "<$email_address>$comment" ne $email &&
1577 "$suggested_email$comment" ne $email) {
1578 WARN
("BAD_SIGN_OFF",
1579 "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
1584 # Check for wrappage within a valid hunk of the file
1585 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
1586 ERROR
("CORRUPTED_PATCH",
1587 "patch seems to be corrupt (line wrapped?)\n" .
1588 $herecurr) if (!$emitted_corrupt++);
1591 # Check for absolute kernel paths.
1593 while ($line =~ m{(?:^|\s)(/\S*)}g) {
1596 if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
1597 check_absolute_file
($1, $herecurr)) {
1600 check_absolute_file
($file, $herecurr);
1605 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
1606 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
1607 $rawline !~ m/^$UTF8*$/) {
1608 my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
1610 my $blank = copy_spacing
($rawline);
1611 my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
1612 my $hereptr = "$hereline$ptr\n";
1615 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
1618 # ignore non-hunk lines and lines being removed
1619 next if (!$hunk_line || $line =~ /^-/);
1621 #trailing whitespace
1622 if ($line =~ /^\+.*\015/) {
1623 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1624 ERROR
("DOS_LINE_ENDINGS",
1625 "DOS line endings\n" . $herevet);
1627 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1628 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1629 ERROR
("TRAILING_WHITESPACE",
1630 "trailing whitespace\n" . $herevet);
1634 # check for Kconfig help text having a real description
1635 # Only applies when adding the entry originally, after that we do not have
1636 # sufficient context to determine whether it is indeed long enough.
1637 if ($realfile =~ /Kconfig/ &&
1638 $line =~ /\+\s*(?:---)?help(?:---)?$/) {
1641 my $ln = $linenr + 1;
1644 while ($cnt > 0 && defined $lines[$ln - 1]) {
1645 $f = $lines[$ln - 1];
1646 $cnt-- if ($lines[$ln - 1] !~ /^-/);
1647 $is_end = $lines[$ln - 1] =~ /^\+/;
1650 next if ($f =~ /^-/);
1654 next if ($f =~ /^$/);
1655 if ($f =~ /^\s*config\s/) {
1661 WARN
("CONFIG_DESCRIPTION",
1662 "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4);
1663 #print "is_end<$is_end> length<$length>\n";
1666 # check we are in a valid source file if not then ignore this hunk
1667 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
1670 if ($line =~ /^\+/ && $prevrawline !~ /\/\
*\
*/ &&
1671 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
1672 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
1673 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
1677 "line over 120 characters\n" . $herecurr);
1680 # check for spaces before a quoted newline
1681 if ($rawline =~ /^.*\".*\s\\n/) {
1682 WARN
("QUOTED_WHITESPACE_BEFORE_NEWLINE",
1683 "unnecessary whitespace before a quoted newline\n" . $herecurr);
1686 # check for adding lines without a newline.
1687 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
1688 WARN
("MISSING_EOF_NEWLINE",
1689 "adding a line without newline at end of file\n" . $herecurr);
1692 # Blackfin: use hi/lo macros
1693 if ($realfile =~ m
@arch/blackfin/.*\
.S
$@
) {
1694 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
1695 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1697 "use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
1699 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
1700 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1702 "use the HI() macro, not (... >> 16)\n" . $herevet);
1706 # check we are in a valid source file C or perl if not then ignore this hunk
1707 next if ($realfile !~ /\.(h|c|pl)$/);
1709 # at the beginning of a line any tabs must come first and anything
1710 # more than 8 must use tabs.
1711 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1712 $rawline =~ /^\+\s* \s*/) {
1713 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1714 ERROR
("CODE_INDENT",
1715 "code indent should use tabs where possible\n" . $herevet);
1719 # check for space before tabs.
1720 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1721 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1722 WARN
("SPACE_BEFORE_TAB",
1723 "please, no space before tabs\n" . $herevet);
1726 # check we are in a valid C source file if not then ignore this hunk
1727 next if ($realfile !~ /\.(h|c)$/);
1729 # check for spaces at the beginning of a line.
1731 # 1) within comments
1732 # 2) indented preprocessor commands
1734 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
1735 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1736 WARN
("LEADING_SPACE",
1737 "please, no spaces at the start of a line\n" . $herevet);
1740 # check for RCS/CVS revision markers
1741 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
1743 "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
1746 # Blackfin: don't use __builtin_bfin_[cs]sync
1747 if ($line =~ /__builtin_bfin_csync/) {
1748 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1750 "use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
1752 if ($line =~ /__builtin_bfin_ssync/) {
1753 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1755 "use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
1758 # Check for potential 'bare' types
1759 my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
1761 if ($realcnt && $line =~ /.\s*\S/) {
1762 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
1763 ctx_statement_block
($linenr, $realcnt, 0);
1764 $stat =~ s/\n./\n /g;
1765 $cond =~ s/\n./\n /g;
1767 # Find the real next line.
1768 $realline_next = $line_nr_next;
1769 if (defined $realline_next &&
1770 (!defined $lines[$realline_next - 1] ||
1771 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
1778 # Ignore goto labels.
1779 if ($s =~ /$Ident:\*$/s) {
1781 # Ignore functions being called
1782 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
1784 } elsif ($s =~ /^.\s*else\b/s) {
1786 # declarations always start with types
1787 } 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) {
1790 possible
($type, "A:" . $s);
1792 # definitions in global scope can only start with types
1793 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
1794 possible
($1, "B:" . $s);
1797 # any (foo ... *) is a pointer cast, and foo is a type
1798 while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
1799 possible
($1, "C:" . $s);
1802 # Check for any sort of function declaration.
1803 # int foo(something bar, other baz);
1804 # void (*store_gdt)(x86_descr_ptr *);
1805 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
1806 my ($name_len) = length($1);
1809 substr($ctx, 0, $name_len + 1, '');
1810 $ctx =~ s/\)[^\)]*$//;
1812 for my $arg (split(/\s*,\s*/, $ctx)) {
1813 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
1815 possible
($1, "D:" . $s);
1823 # Checks which may be anchored in the context.
1826 # Check for switch () and associated case and default
1827 # statements should be at the same indent.
1828 # if ($line=~/\bswitch\s*\(.*\)/) {
1831 # my @ctx = ctx_block_outer($linenr, $realcnt);
1833 # for my $ctx (@ctx) {
1834 # my ($clen, $cindent) = line_stats($ctx);
1835 # if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
1836 # $indent != $cindent) {
1837 # $err .= "$sep$ctx\n";
1844 # ERROR("SWITCH_CASE_INDENT_LEVEL",
1845 # "switch and case should be at the same indent\n$hereline$err");
1849 # if/while/etc brace do not go on next line, unless defining a do while loop,
1850 # or if that brace on the next line is for something else
1851 if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
1852 my $pre_ctx = "$1$2";
1854 my ($level, @ctx) = ctx_statement_level
($linenr, $realcnt, 0);
1855 my $ctx_cnt = $realcnt - $#ctx - 1;
1856 my $ctx = join("\n", @ctx);
1858 my $ctx_ln = $linenr;
1859 my $ctx_skip = $realcnt;
1861 while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
1862 defined $lines[$ctx_ln - 1] &&
1863 $lines[$ctx_ln - 1] =~ /^-/)) {
1864 ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
1865 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
1869 #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
1870 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
1872 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1874 "that open brace { should be on the previous line\n" .
1875 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1877 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
1878 $ctx =~ /\)\s*\;\s*$/ &&
1879 defined $lines[$ctx_ln - 1])
1881 my ($nlength, $nindent) = line_stats
($lines[$ctx_ln - 1]);
1882 if ($nindent > $indent) {
1883 WARN
("TRAILING_SEMICOLON",
1884 "trailing semicolon indicates no statements, indent implies otherwise\n" .
1885 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1890 # Check relative indent for conditionals and blocks.
1891 if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
1892 my ($s, $c) = ($stat, $cond);
1894 substr($s, 0, length($c), '');
1896 # Make sure we remove the line prefixes as we have
1897 # none on the first line, and are going to readd them
1901 # Find out how long the conditional actually is.
1902 my @newlines = ($c =~ /\n/gs);
1903 my $cond_lines = 1 + $#newlines;
1905 # We want to check the first line inside the block
1906 # starting at the end of the conditional, so remove:
1907 # 1) any blank line termination
1908 # 2) any opening brace { on end of the line
1910 my $continuation = 0;
1912 $s =~ s/^.*\bdo\b//;
1914 if ($s =~ s/^\s*\\//) {
1917 if ($s =~ s/^\s*?\n//) {
1922 # Also ignore a loop construct at the end of a
1923 # preprocessor statement.
1924 if (($prevline =~ /^.\s*#\s*define\s/ ||
1925 $prevline =~ /\\\s*$/) && $continuation == 0) {
1931 while ($cond_ptr != $cond_lines) {
1932 $cond_ptr = $cond_lines;
1934 # If we see an #else/#elif then the code
1936 if ($s =~ /^\s*\#\s*(?:else|elif)/) {
1941 # 1) blank lines, they should be at 0,
1942 # 2) preprocessor lines, and
1944 if ($continuation ||
1946 $s =~ /^\s*#\s*?/ ||
1947 $s =~ /^\s*$Ident\s*:/) {
1948 $continuation = ($s =~ /^.*?\\\n/) ?
1 : 0;
1949 if ($s =~ s/^.*?\n//) {
1955 my (undef, $sindent) = line_stats
("+" . $s);
1956 my $stat_real = raw_line
($linenr, $cond_lines);
1958 # Check if either of these lines are modified, else
1959 # this is not this patch's fault.
1960 if (!defined($stat_real) ||
1961 $stat !~ /^\+/ && $stat_real !~ /^\+/) {
1964 if (defined($stat_real) && $cond_lines > 1) {
1965 $stat_real = "[...]\n$stat_real";
1968 #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
1970 if ($check && (($sindent % 4) != 0 ||
1971 ($sindent <= $indent && $s ne ''))) {
1972 WARN
("SUSPECT_CODE_INDENT",
1973 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
1977 # Track the 'values' across context and added lines.
1978 my $opline = $line; $opline =~ s/^./ /;
1979 my ($curr_values, $curr_vars) =
1980 annotate_values
($opline . "\n", $prev_values);
1981 $curr_values = $prev_values . $curr_values;
1983 my $outline = $opline; $outline =~ s/\t/ /g;
1984 print "$linenr > .$outline\n";
1985 print "$linenr > $curr_values\n";
1986 print "$linenr > $curr_vars\n";
1988 $prev_values = substr($curr_values, -1);
1990 #ignore lines not being added
1991 if ($line=~/^[^\+]/) {next;}
1993 # TEST: allow direct testing of the type matcher.
1995 if ($line =~ /^.\s*$Declare\s*$/) {
1997 "TEST: is type\n" . $herecurr);
1998 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
1999 ERROR
("TEST_NOT_TYPE",
2000 "TEST: is not type ($1 is)\n". $herecurr);
2004 # TEST: allow direct testing of the attribute matcher.
2006 if ($line =~ /^.\s*$Modifier\s*$/) {
2008 "TEST: is attr\n" . $herecurr);
2009 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
2010 ERROR
("TEST_NOT_ATTR",
2011 "TEST: is not attr ($1 is)\n". $herecurr);
2016 # check for initialisation to aggregates open brace on the next line
2017 if ($line =~ /^.\s*{/ &&
2018 $prevline =~ /(?:^|[^=])=\s*$/) {
2020 "that open brace { should be on the previous line\n" . $hereprev);
2024 # Checks which are anchored on the added line.
2027 # check for malformed paths in #include statements (uses RAW line)
2028 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
2030 if ($path =~ m{//}) {
2031 ERROR
("MALFORMED_INCLUDE",
2032 "malformed #include filename\n" .
2037 # no C99 // comments
2038 if ($line =~ m{//}) {
2039 ERROR
("C99_COMMENTS",
2040 "do not use C99 // comments\n" . $herecurr);
2042 # Remove C99 comments.
2044 $opline =~ s@
//.*@@
;
2046 # EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
2047 # the whole statement.
2048 #print "APW <$lines[$realline_next - 1]>\n";
2049 if (defined $realline_next &&
2050 exists $lines[$realline_next - 1] &&
2051 !defined $suppress_export{$realline_next} &&
2052 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
2053 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
2054 # Handle definitions which produce identifiers with
2057 # EXPORT_SYMBOL(something_foo);
2059 if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ &&
2060 $name =~ /^${Ident}_$2/) {
2061 #print "FOO C name<$name>\n";
2062 $suppress_export{$realline_next} = 1;
2064 } elsif ($stat !~ /(?
:
2066 ^.DEFINE_
$Ident\
(\Q
$name\E\
)|
2067 ^.DECLARE_
$Ident\
(\Q
$name\E\
)|
2068 ^.LIST_HEAD\
(\Q
$name\E\
)|
2069 ^.(?
:$Storage\s
+)?
$Type\s
*\
(\s
*\
*\s
*\Q
$name\E\s
*\
)\s
*\
(|
2070 \b\Q
$name\E
(?
:\s
+$Attribute)*\s
*(?
:;|=|\
[|\
()
2072 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
2073 $suppress_export{$realline_next} = 2;
2075 $suppress_export{$realline_next} = 1;
2078 if (!defined $suppress_export{$linenr} &&
2079 $prevline =~ /^.\s*$/ &&
2080 ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
2081 $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
2082 #print "FOO B <$lines[$linenr - 1]>\n";
2083 $suppress_export{$linenr} = 2;
2085 if (defined $suppress_export{$linenr} &&
2086 $suppress_export{$linenr} == 2) {
2087 WARN
("EXPORT_SYMBOL",
2088 "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
2091 # check for global initialisers.
2092 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
2093 ERROR
("GLOBAL_INITIALISERS",
2094 "do not initialise globals to 0 or NULL\n" .
2097 # check for static initialisers.
2098 if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
2099 ERROR
("INITIALISED_STATIC",
2100 "do not initialise statics to 0 or NULL\n" .
2104 # check for static const char * arrays.
2105 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
2106 WARN
("STATIC_CONST_CHAR_ARRAY",
2107 "static const char * array should probably be static const char * const\n" .
2111 # check for static char foo[] = "bar" declarations.
2112 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
2113 WARN
("STATIC_CONST_CHAR_ARRAY",
2114 "static char array declaration should probably be static const char\n" .
2118 # check for declarations of struct pci_device_id
2119 if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) {
2120 WARN
("DEFINE_PCI_DEVICE_TABLE",
2121 "Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr);
2124 # check for new typedefs, only function parameters and sparse annotations
2126 # if ($line =~ /\btypedef\s/ &&
2127 # $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
2128 # $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
2129 # $line !~ /\b$typeTypedefs\b/ &&
2130 # $line !~ /\b__bitwise(?:__|)\b/) {
2131 # WARN("NEW_TYPEDEFS",
2132 # "do not add new typedefs\n" . $herecurr);
2135 # * goes on variable not on type
2137 if ($line =~ m{\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\)}) {
2138 my ($from, $to) = ($1, $1);
2140 # Should start with a space.
2141 $to =~ s/^(\S)/ $1/;
2142 # Should not end with a space.
2144 # '*'s should not have spaces between.
2145 while ($to =~ s/\*\s+\*/\*\*/) {
2148 #print "from<$from> to<$to>\n";
2150 ERROR
("POINTER_LOCATION",
2151 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
2153 } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) {
2154 my ($from, $to, $ident) = ($1, $1, $2);
2156 # Should start with a space.
2157 $to =~ s/^(\S)/ $1/;
2158 # Should not end with a space.
2160 # '*'s should not have spaces between.
2161 while ($to =~ s/\*\s+\*/\*\*/) {
2163 # Modifiers should have spaces.
2164 $to =~ s/(\b$Modifier$)/$1 /;
2166 #print "from<$from> to<$to> ident<$ident>\n";
2167 if ($from ne $to && $ident !~ /^$Modifier$/) {
2168 ERROR
("POINTER_LOCATION",
2169 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr);
2173 # # no BUG() or BUG_ON()
2174 # if ($line =~ /\b(BUG|BUG_ON)\b/) {
2175 # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
2176 # print "$herecurr";
2180 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
2181 WARN
("LINUX_VERSION_CODE",
2182 "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
2185 # check for uses of printk_ratelimit
2186 if ($line =~ /\bprintk_ratelimit\s*\(/) {
2187 WARN
("PRINTK_RATELIMITED",
2188 "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
2191 # printk should use KERN_* levels. Note that follow on printk's on the
2192 # same line do not need a level, so we use the current block context
2193 # to try and find and validate the current printk. In summary the current
2194 # printk includes all preceding printk's which have no newline on the end.
2195 # we assume the first bad printk is the one to report.
2196 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
2198 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
2199 #print "CHECK<$lines[$ln - 1]\n";
2200 # we have a preceding printk if it ends
2201 # with "\n" ignore it, else it is to blame
2202 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
2203 if ($rawlines[$ln - 1] !~ m{\\n"}) {
2210 WARN
("PRINTK_WITHOUT_KERN_LEVEL",
2211 "printk() should include KERN_ facility level\n" . $herecurr);
2215 # function brace can't be on same line, except for #defines of do while,
2216 # or if closed on same line
2217 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
2218 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
2220 "open brace '{' following function declarations go on the next line\n" . $herecurr);
2223 # open braces for enum, union and struct go on the same line.
2224 if ($line =~ /^.\s*{/ &&
2225 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
2227 "open brace '{' following $1 go on the same line\n" . $hereprev);
2230 # missing space after union, struct or enum definition
2231 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
2233 "missing space after $1 definition\n" . $herecurr);
2236 # check for spacing round square brackets; allowed:
2237 # 1. with a type on the left -- int [] a;
2238 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
2239 # 3. inside a curly brace -- = { [0...10] = 5 }
2240 while ($line =~ /(.*?\s)\[/g) {
2241 my ($where, $prefix) = ($-[1], $1);
2242 if ($prefix !~ /$Type\s+$/ &&
2243 ($where != 0 || $prefix !~ /^.\s+$/) &&
2244 $prefix !~ /{\s+$/) {
2245 ERROR
("BRACKET_SPACE",
2246 "space prohibited before open square bracket '['\n" . $herecurr);
2250 # check for spaces between functions and their parentheses.
2251 while ($line =~ /($Ident)\s+\(/g) {
2253 my $ctx_before = substr($line, 0, $-[1]);
2254 my $ctx = "$ctx_before$name";
2256 # Ignore those directives where spaces _are_ permitted.
2258 if|for|while|switch
|return|case
|
2259 volatile
|__volatile__
|
2260 __attribute__
|format
|__extension__
|
2264 # cpp #define statements have non-optional spaces, ie
2265 # if there is a space between the name and the open
2266 # parenthesis it is simply not a parameter group.
2267 } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
2269 # cpp #elif statement condition may start with a (
2270 } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
2272 # If this whole things ends with a type its most
2273 # likely a typedef for a function.
2274 } elsif ($ctx =~ /$Type$/) {
2278 "space prohibited between function name and open parenthesis '('\n" . $herecurr);
2281 # Check operator spacing.
2282 if (!($line=~/\#\s*include/)) {
2284 <<=|>>=|<=|>=|==|!=|
2285 \
+=|-=|\
*=|\
/=|%=|\
^=|\
|=|&=|
2286 =>|->|<<|>>|<|>|=|!|~|
2287 &&|\
|\
||,|\
^|\
+\
+|--|&|\
||\
+|-|\
*|\
/|%|
2290 my @elements = split(/($ops|;)/, $opline);
2293 my $blank = copy_spacing
($opline);
2295 for (my $n = 0; $n < $#elements; $n += 2) {
2296 $off += length($elements[$n]);
2298 # Pick up the preceding and succeeding characters.
2299 my $ca = substr($opline, 0, $off);
2301 if (length($opline) >= ($off + length($elements[$n + 1]))) {
2302 $cc = substr($opline, $off + length($elements[$n + 1]));
2304 my $cb = "$ca$;$cc";
2307 $a = 'V' if ($elements[$n] ne '');
2308 $a = 'W' if ($elements[$n] =~ /\s$/);
2309 $a = 'C' if ($elements[$n] =~ /$;$/);
2310 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
2311 $a = 'O' if ($elements[$n] eq '');
2312 $a = 'E' if ($ca =~ /^\s*$/);
2314 my $op = $elements[$n + 1];
2317 if (defined $elements[$n + 2]) {
2318 $c = 'V' if ($elements[$n + 2] ne '');
2319 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
2320 $c = 'C' if ($elements[$n + 2] =~ /^$;/);
2321 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
2322 $c = 'O' if ($elements[$n + 2] eq '');
2323 $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
2328 my $ctx = "${a}x${c}";
2330 my $at = "(ctx:$ctx)";
2332 my $ptr = substr($blank, 0, $off) . "^";
2333 my $hereptr = "$hereline$ptr\n";
2335 # Pull out the value of this operator.
2336 my $op_type = substr($curr_values, $off + 1, 1);
2338 # Get the full operator variant.
2339 my $opv = $op . substr($curr_vars, $off, 1);
2341 # Ignore operators passed as parameters.
2342 if ($op_type ne 'V' &&
2343 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
2346 # } elsif ($op =~ /^$;+$/) {
2348 # ; should have either the end of line or a space or \ after it
2349 } elsif ($op eq ';') {
2350 if ($ctx !~ /.x[WEBC]/ &&
2351 $cc !~ /^\\/ && $cc !~ /^;/) {
2353 "space required after that '$op' $at\n" . $hereptr);
2357 } elsif ($op eq '//') {
2361 # : when part of a bitfield
2362 } elsif ($op eq '->' || $opv eq ':B') {
2363 if ($ctx =~ /Wx.|.xW/) {
2365 "spaces prohibited around that '$op' $at\n" . $hereptr);
2368 # , must have a space on the right.
2369 } elsif ($op eq ',') {
2370 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
2372 "space required after that '$op' $at\n" . $hereptr);
2375 # '*' as part of a type definition -- reported already.
2376 } elsif ($opv eq '*_') {
2377 #warn "'*' is part of type\n";
2379 # unary operators should have a space before and
2380 # none after. May be left adjacent to another
2381 # unary operator, or a cast
2382 } elsif ($op eq '!' || $op eq '~' ||
2383 $opv eq '*U' || $opv eq '-U' ||
2384 $opv eq '&U' || $opv eq '&&U') {
2385 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
2387 "space required before that '$op' $at\n" . $hereptr);
2389 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
2390 # A unary '*' may be const
2392 } elsif ($ctx =~ /.xW/) {
2394 "space prohibited after that '$op' $at\n" . $hereptr);
2397 # unary ++ and unary -- are allowed no space on one side.
2398 } elsif ($op eq '++' or $op eq '--') {
2399 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
2401 "space required one side of that '$op' $at\n" . $hereptr);
2403 if ($ctx =~ /Wx[BE]/ ||
2404 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
2406 "space prohibited before that '$op' $at\n" . $hereptr);
2408 if ($ctx =~ /ExW/) {
2410 "space prohibited after that '$op' $at\n" . $hereptr);
2414 # << and >> may either have or not have spaces both sides
2415 } elsif ($op eq '<<' or $op eq '>>' or
2416 $op eq '&' or $op eq '^' or $op eq '|' or
2417 $op eq '+' or $op eq '-' or
2418 $op eq '*' or $op eq '/' or
2421 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
2423 "need consistent spacing around '$op' $at\n" .
2427 # A colon needs no spaces before when it is
2428 # terminating a case value or a label.
2429 } elsif ($opv eq ':C' || $opv eq ':L') {
2430 if ($ctx =~ /Wx./) {
2432 "space prohibited before that '$op' $at\n" . $hereptr);
2435 # All the others need spaces both sides.
2436 } elsif ($ctx !~ /[EWC]x[CWE]/) {
2439 # Ignore email addresses <foo@bar>
2441 $cc =~ /^\S+\@\S+>/) ||
2443 $ca =~ /<\S+\@\S+$/))
2449 if (($opv eq ':O' && $ca =~ /\?$/) ||
2450 ($op eq '?' && $cc =~ /^:/)) {
2456 "spaces required around that '$op' $at\n" . $hereptr);
2459 $off += length($elements[$n + 1]);
2463 # check for multiple assignments
2464 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
2465 CHK
("MULTIPLE_ASSIGNMENTS",
2466 "multiple assignments should be avoided\n" . $herecurr);
2469 ## # check for multiple declarations, allowing for a function declaration
2471 ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
2472 ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
2474 ## # Remove any bracketed sections to ensure we do not
2475 ## # falsly report the parameters of functions.
2477 ## while ($ln =~ s/\([^\(\)]*\)//g) {
2479 ## if ($ln =~ /,/) {
2480 ## WARN("MULTIPLE_DECLARATION",
2481 ## "declaring multiple variables together should be avoided\n" . $herecurr);
2485 #need space before brace following if, while, etc
2486 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
2489 "space required before the open brace '{'\n" . $herecurr);
2492 # closing brace should have a space following it when it has anything
2494 if ($line =~ /}(?!(?:,|;|\)))\S/) {
2496 "space required after that close brace '}'\n" . $herecurr);
2499 # check spacing on square brackets
2500 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
2502 "space prohibited after that open square bracket '['\n" . $herecurr);
2504 if ($line =~ /\s\]/) {
2506 "space prohibited before that close square bracket ']'\n" . $herecurr);
2509 # check spacing on parentheses
2510 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
2511 $line !~ /for\s*\(\s+;/) {
2513 "space prohibited after that open parenthesis '('\n" . $herecurr);
2515 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
2516 $line !~ /for\s*\(.*;\s+\)/ &&
2517 $line !~ /:\s+\)/) {
2519 "space prohibited before that close parenthesis ')'\n" . $herecurr);
2522 #goto labels aren't indented, allow a single space however
2523 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
2524 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
2525 WARN
("INDENTED_LABEL",
2526 "labels should not be indented\n" . $herecurr);
2529 # Return is not a function.
2530 if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) {
2534 # Flatten any parentheses
2535 $value =~ s/\(/ \(/g;
2536 $value =~ s/\)/\) /g;
2537 while ($value =~ s/\[[^\{\}]*\]/1/ ||
2538 $value !~ /(?
:$Ident|-?
$Constant)\s
*
2540 (?
:$Ident|-?
$Constant)/x
&&
2541 $value =~ s/\([^\(\)]*\)/1/) {
2543 #print "value<$value>\n";
2544 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
2545 ERROR
("RETURN_PARENTHESES",
2546 "return is not a function, parentheses are not required\n" . $herecurr);
2548 } elsif ($spacing !~ /\s+/) {
2550 "space required before the open parenthesis '('\n" . $herecurr);
2553 # Return of what appears to be an errno should normally be -'ve
2554 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
2556 if ($name ne 'EOF' && $name ne 'ERROR') {
2557 WARN
("USE_NEGATIVE_ERRNO",
2558 "return of an errno should typically be -ve (return -$1)\n" . $herecurr);
2562 # typecasts on min/max could be min_t/max_t
2563 if ($line =~ /^\+(?:.*?)\b(min|max)\s*\($Typecast{0,1}($LvalOrFunc)\s*,\s*$Typecast{0,1}($LvalOrFunc)\s*\)/) {
2564 if (defined $2 || defined $8) {
2566 my $cast1 = deparenthesize
($2);
2568 my $cast2 = deparenthesize
($8);
2572 if ($cast1 ne "" && $cast2 ne "") {
2573 $cast = "$cast1 or $cast2";
2574 } elsif ($cast1 ne "") {
2580 "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . $herecurr);
2584 # Need a space before open parenthesis after if, while etc
2585 if ($line=~/\b(if|while|for|switch)\(/) {
2586 ERROR
("SPACING", "space required before the open parenthesis '('\n" . $herecurr);
2589 # Check for illegal assignment in if conditional -- and check for trailing
2590 # statements after the conditional.
2591 if ($line =~ /do\s*(?!{)/) {
2592 my ($stat_next) = ctx_statement_block
($line_nr_next,
2593 $remain_next, $off_next);
2594 $stat_next =~ s/\n./\n /g;
2595 ##print "stat<$stat> stat_next<$stat_next>\n";
2597 if ($stat_next =~ /^\s*while\b/) {
2598 # If the statement carries leading newlines,
2599 # then count those as offsets.
2601 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
2603 statement_rawlines
($whitespace) - 1;
2605 $suppress_whiletrailers{$line_nr_next +
2609 if (!defined $suppress_whiletrailers{$linenr} &&
2610 $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
2611 my ($s, $c) = ($stat, $cond);
2613 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
2614 ERROR
("ASSIGN_IN_IF",
2615 "do not use assignment in if condition\n" . $herecurr);
2618 # Find out what is on the end of the line after the
2620 substr($s, 0, length($c), '');
2622 $s =~ s/$;//g; # Remove any comments
2623 if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
2624 $c !~ /}\s*while\s*/)
2626 # Find out how long the conditional actually is.
2627 my @newlines = ($c =~ /\n/gs);
2628 my $cond_lines = 1 + $#newlines;
2631 $stat_real = raw_line
($linenr, $cond_lines)
2632 . "\n" if ($cond_lines);
2633 if (defined($stat_real) && $cond_lines > 1) {
2634 $stat_real = "[...]\n$stat_real";
2637 ERROR
("TRAILING_STATEMENTS",
2638 "trailing statements should be on next line\n" . $herecurr . $stat_real);
2642 # Check for bitwise tests written as boolean
2654 WARN
("HEXADECIMAL_BOOLEAN_TEST",
2655 "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
2658 # if and else should not have general statements after it
2659 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
2661 $s =~ s/$;//g; # Remove any comments
2662 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
2663 ERROR
("TRAILING_STATEMENTS",
2664 "trailing statements should be on next line\n" . $herecurr);
2667 # if should not continue a brace
2668 if ($line =~ /}\s*if\b/) {
2669 ERROR
("TRAILING_STATEMENTS",
2670 "trailing statements should be on next line\n" .
2673 # case and default should not have general statements after them
2674 if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
2676 (?
:\s
*$;*)(?
:\s
*{)?
(?
:\s
*$;*)(?
:\s
*\\)?\s
*$|
2680 ERROR
("TRAILING_STATEMENTS",
2681 "trailing statements should be on next line\n" . $herecurr);
2684 # Check for }<nl>else {, these must be at the same
2685 # indent level to be relevant to each other.
2686 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
2687 $previndent == $indent) {
2688 ERROR
("ELSE_AFTER_BRACE",
2689 "else should follow close brace '}'\n" . $hereprev);
2692 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
2693 $previndent == $indent) {
2694 my ($s, $c) = ctx_statement_block
($linenr, $realcnt, 0);
2696 # Find out what is on the end of the line after the
2698 substr($s, 0, length($c), '');
2701 if ($s =~ /^\s*;/) {
2702 ERROR
("WHILE_AFTER_BRACE",
2703 "while should follow close brace '}'\n" . $hereprev);
2707 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
2708 # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
2709 # print "No studly caps, use _\n";
2710 # print "$herecurr";
2714 #no spaces allowed after \ in define
2715 if ($line=~/\#\s*define.*\\\s$/) {
2716 WARN
("WHITESPACE_AFTER_LINE_CONTINUATION",
2717 "Whitepspace after \\ makes next lines useless\n" . $herecurr);
2720 #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
2721 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
2723 my $checkfile = "include/linux/$file";
2724 if (-f
"$root/$checkfile" &&
2725 $realfile ne $checkfile &&
2726 $1 !~ /$allowed_asm_includes/)
2728 if ($realfile =~ m{^arch/}) {
2729 CHK
("ARCH_INCLUDE_LINUX",
2730 "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2732 WARN
("INCLUDE_LINUX",
2733 "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2738 # multi-statement macros should be enclosed in a do while loop, grab the
2739 # first statement and ensure its the whole macro if its not enclosed
2740 # in a known good container
2741 if ($realfile !~ m@
/vmlinux
.lds
.h
$@
&&
2742 $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
2745 my ($off, $dstat, $dcond, $rest);
2748 my $args = defined($1);
2750 # Find the end of the macro and limit our statement
2752 while ($cnt > 0 && defined $lines[$ln - 1] &&
2753 $lines[$ln - 1] =~ /^(?:-|..*\\$)/)
2755 $ctx .= $rawlines[$ln - 1] . "\n";
2756 $cnt-- if ($lines[$ln - 1] !~ /^-/);
2759 $ctx .= $rawlines[$ln - 1];
2761 ($dstat, $dcond, $ln, $cnt, $off) =
2762 ctx_statement_block
($linenr, $ln - $linenr + 1, 0);
2763 #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
2764 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
2766 # Extract the remainder of the define (if any) and
2767 # rip off surrounding spaces, and trailing \'s.
2769 while ($off != 0 || ($cnt > 0 && $rest =~ /\\\s*$/)) {
2770 #print "ADDING cnt<$cnt> $off <" . substr($lines[$ln - 1], $off) . "> rest<$rest>\n";
2771 if ($off != 0 || $lines[$ln - 1] !~ /^-/) {
2772 $rest .= substr($lines[$ln - 1], $off) . "\n";
2778 $rest =~ s/\\\n.//g;
2782 # Clean up the original statement.
2784 substr($dstat, 0, length($dcond), '');
2786 $dstat =~ s/^.\s*\#\s*define\s+$Ident\s*//;
2789 $dstat =~ s/\\\n.//g;
2790 $dstat =~ s/^\s*//s;
2791 $dstat =~ s/\s*$//s;
2793 # Flatten any parentheses and braces
2794 while ($dstat =~ s/\([^\(\)]*\)/1/ ||
2795 $dstat =~ s/\{[^\{\}]*\}/1/ ||
2796 $dstat =~ s/\[[^\{\}]*\]/1/)
2800 my $exceptions = qr{
2812 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
2813 if ($rest ne '' && $rest ne ',') {
2814 if ($rest !~ /while\s*\(/ &&
2815 $dstat !~ /$exceptions/)
2817 ERROR
("MULTISTATEMENT_MACRO_USE_DO_WHILE",
2818 "Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
2821 } elsif ($ctx !~ /;/) {
2823 $dstat !~ /^(?:$Ident|-?$Constant)$/ &&
2824 $dstat !~ /$exceptions/ &&
2825 $dstat !~ /^\.$Ident\s*=/ &&
2826 $dstat =~ /$Operators/)
2828 ERROR
("COMPLEX_MACRO",
2829 "Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
2834 # make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
2835 # all assignments may have only one of the following with an assignment:
2838 # VMLINUX_SYMBOL(...)
2839 if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
2840 WARN
("MISSING_VMLINUX_SYMBOL",
2841 "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
2844 # check for redundant bracing round if etc
2845 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
2846 my ($level, $endln, @chunks) =
2847 ctx_statement_full
($linenr, $realcnt, 1);
2848 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
2849 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
2850 if ($#chunks > 0 && $level == 0) {
2853 my $herectx = $here . "\n";
2854 my $ln = $linenr - 1;
2855 for my $chunk (@chunks) {
2856 my ($cond, $block) = @
{$chunk};
2858 # If the condition carries leading newlines, then count those as offsets.
2859 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
2860 my $offset = statement_rawlines
($whitespace) - 1;
2862 #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
2864 # We have looked at and allowed this specific line.
2865 $suppress_ifbraces{$ln + $offset} = 1;
2867 $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
2868 $ln += statement_rawlines
($block) - 1;
2870 substr($block, 0, length($cond), '');
2872 $seen++ if ($block =~ /^\s*{/);
2874 #print "cond<$cond> block<$block> allowed<$allowed>\n";
2875 if (statement_lines
($cond) > 1) {
2876 #print "APW: ALLOWED: cond<$cond>\n";
2879 if ($block =~/\b(?:if|for|while)\b/) {
2880 #print "APW: ALLOWED: block<$block>\n";
2883 if (statement_block_size
($block) > 1) {
2884 #print "APW: ALLOWED: lines block<$block>\n";
2888 if ($seen && !$allowed) {
2890 "braces {} are not necessary for any arm of this statement\n" . $herectx);
2894 if (!defined $suppress_ifbraces{$linenr - 1} &&
2895 $line =~ /\b(if|while|for|else)\b/) {
2898 # Check the pre-context.
2899 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
2900 #print "APW: ALLOWED: pre<$1>\n";
2904 my ($level, $endln, @chunks) =
2905 ctx_statement_full
($linenr, $realcnt, $-[0]);
2907 # Check the condition.
2908 my ($cond, $block) = @
{$chunks[0]};
2909 #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
2910 if (defined $cond) {
2911 substr($block, 0, length($cond), '');
2913 if (statement_lines
($cond) > 1) {
2914 #print "APW: ALLOWED: cond<$cond>\n";
2917 if ($block =~/\b(?:if|for|while)\b/) {
2918 #print "APW: ALLOWED: block<$block>\n";
2921 if (statement_block_size
($block) > 1) {
2922 #print "APW: ALLOWED: lines block<$block>\n";
2925 # Check the post-context.
2926 if (defined $chunks[1]) {
2927 my ($cond, $block) = @
{$chunks[1]};
2928 if (defined $cond) {
2929 substr($block, 0, length($cond), '');
2931 if ($block =~ /^\s*\{/) {
2932 #print "APW: ALLOWED: chunk-1 block<$block>\n";
2936 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
2937 my $herectx = $here . "\n";
2938 my $cnt = statement_rawlines
($block);
2940 for (my $n = 0; $n < $cnt; $n++) {
2941 $herectx .= raw_line
($linenr, $n) . "\n";
2945 "braces {} are not necessary for single statement blocks\n" . $herectx);
2949 # don't include deprecated include files (uses RAW line)
2950 for my $inc (@dep_includes) {
2951 if ($rawline =~ m@
^.\s
*\#\s
*include\s
*\
<$inc>@
) {
2952 ERROR
("DEPRECATED_INCLUDE",
2953 "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2957 # don't use deprecated functions
2958 for my $func (@dep_functions) {
2959 if ($line =~ /\b$func\b/) {
2960 ERROR
("DEPRECATED_FUNCTION",
2961 "Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2965 # no volatiles please
2966 # my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
2967 # if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
2969 # "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
2973 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
2974 CHK
("REDUNDANT_CODE",
2975 "if this code is redundant consider removing it\n" .
2979 # check for needless kfree() checks
2980 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2982 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
2983 WARN
("NEEDLESS_KFREE",
2984 "kfree(NULL) is safe this check is probably not required\n" . $hereprev);
2987 # check for needless usb_free_urb() checks
2988 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2990 if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) {
2991 WARN
("NEEDLESS_USB_FREE_URB",
2992 "usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev);
2996 # prefer usleep_range over udelay
2997 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
2998 # ignore udelay's < 10, however
2999 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
3001 "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
3005 # warn about unexpectedly long msleep's
3006 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
3009 "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
3013 # warn about #ifdefs in C files
3014 # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
3015 # print "#ifdef in C files should be avoided\n";
3016 # print "$herecurr";
3020 # warn about spacing in #ifdefs
3021 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
3023 "exactly one space required after that #$1\n" . $herecurr);
3026 # check for spinlock_t definitions without a comment.
3027 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
3028 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
3030 if (!ctx_has_comment
($first_line, $linenr)) {
3031 CHK
("UNCOMMENTED_DEFINITION",
3032 "$1 definition without comment\n" . $herecurr);
3035 # check for memory barriers without a comment.
3036 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
3037 if (!ctx_has_comment
($first_line, $linenr)) {
3038 CHK
("MEMORY_BARRIER",
3039 "memory barrier without comment\n" . $herecurr);
3042 # check of hardware specific defines
3043 if ($line =~ m@
^.\s
*\#\s
*if.*\b(__i386__
|__powerpc64__
|__sun__
|__s390x__
)\b@
&& $realfile !~ m
@include/asm
-@
) {
3045 "architecture specific defines should be avoided\n" . $herecurr);
3048 # Check that the storage class is at the beginning of a declaration
3049 if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
3050 WARN
("STORAGE_CLASS",
3051 "storage class should be at the beginning of the declaration\n" . $herecurr)
3054 # check the location of the inline attribute, that it is between
3055 # storage class and type.
3056 if ($line =~ /\b$Type\s+$Inline\b/ ||
3057 $line =~ /\b$Inline\s+$Storage\b/) {
3058 ERROR
("INLINE_LOCATION",
3059 "inline keyword should sit between storage class and type\n" . $herecurr);
3062 # Check for __inline__ and __inline, prefer inline
3063 if ($line =~ /\b(__inline__|__inline)\b/) {
3065 "plain inline is preferred over $1\n" . $herecurr);
3068 # Check for __attribute__ packed, prefer __packed
3069 # if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
3070 # WARN("PREFER_PACKED",
3071 # "__packed is preferred over __attribute__((packed))\n" . $herecurr);
3074 # Check for __attribute__ aligned, prefer __aligned
3075 # if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
3076 # WARN("PREFER_ALIGNED",
3077 # "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
3080 # check for sizeof(&)
3081 if ($line =~ /\bsizeof\s*\(\s*\&/) {
3082 WARN
("SIZEOF_ADDRESS",
3083 "sizeof(& should be avoided\n" . $herecurr);
3086 # check for line continuations in quoted strings with odd counts of "
3087 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
3088 WARN
("LINE_CONTINUATIONS",
3089 "Avoid line continuations in quoted strings\n" . $herecurr);
3092 # check for new externs in .c files.
3093 # if ($realfile =~ /\.c$/ && defined $stat &&
3094 # $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
3096 # my $function_name = $1;
3097 # my $paren_space = $2;
3100 # if (defined $cond) {
3101 # substr($s, 0, length($cond), '');
3103 # if ($s =~ /^\s*;/ &&
3104 # $function_name ne 'uninitialized_var')
3106 # WARN("AVOID_EXTERNS",
3107 # "externs should be avoided in .c files\n" . $herecurr);
3110 # if ($paren_space =~ /\n/) {
3111 # WARN("FUNCTION_ARGUMENTS",
3112 # "arguments for function declarations should follow identifier\n" . $herecurr);
3115 # } elsif ($realfile =~ /\.c$/ && defined $stat &&
3116 # $stat =~ /^.\s*extern\s+/)
3118 # WARN("AVOID_EXTERNS",
3119 # "externs should be avoided in .c files\n" . $herecurr);
3122 # checks for new __setup's
3123 if ($rawline =~ /\b__setup\("([^"]*)"/) {
3126 if (!grep(/$name/, @setup_docs)) {
3127 CHK
("UNDOCUMENTED_SETUP",
3128 "__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
3132 # check for pointless casting of kmalloc return
3133 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
3134 WARN
("UNNECESSARY_CASTS",
3135 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
3138 # check for multiple semicolons
3139 if ($line =~ /;\s*;\s*$/) {
3140 WARN
("ONE_SEMICOLON",
3141 "Statements terminations use 1 semicolon\n" . $herecurr);
3144 # check for gcc specific __FUNCTION__
3145 if ($line =~ /__FUNCTION__/) {
3147 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
3150 # check for semaphores initialized locked
3151 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
3152 WARN
("CONSIDER_COMPLETION",
3153 "consider using a completion\n" . $herecurr);
3156 # recommend kstrto* over simple_strto*
3157 if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
3158 WARN
("CONSIDER_KSTRTO",
3159 "consider using kstrto* in preference to simple_$1\n" . $herecurr);
3161 # check for __initcall(), use device_initcall() explicitly please
3162 if ($line =~ /^.\s*__initcall\s*\(/) {
3163 WARN
("USE_DEVICE_INITCALL",
3164 "please use device_initcall() instead of __initcall()\n" . $herecurr);
3166 # check for various ops structs, ensure they are const.
3167 my $struct_ops = qr{acpi_dock_ops
|
3168 address_space_operations
|
3170 block_device_operations
|
3175 file_lock_operations
|
3185 lock_manager_operations
|
3191 pipe_buf_operations
|
3192 platform_hibernation_ops
|
3193 platform_suspend_ops
|
3198 soc_pcmcia_socket_ops
|
3204 if ($line !~ /\bconst\b/ &&
3205 $line =~ /\bstruct\s+($struct_ops)\b/) {
3206 WARN
("CONST_STRUCT",
3207 "struct $1 should normally be const\n" .
3211 # use of NR_CPUS is usually wrong
3212 # ignore definitions of NR_CPUS and usage to define arrays as likely right
3213 if ($line =~ /\bNR_CPUS\b/ &&
3214 $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
3215 $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
3216 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
3217 $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
3218 $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
3221 "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
3224 # check for %L{u,d,i} in strings
3226 while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
3227 $string = substr($rawline, $-[1], $+[1] - $-[1]);
3228 $string =~ s/%%/__/g;
3229 if ($string =~ /(?<!%)%L[udi]/) {
3231 "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
3236 # whine mightly about in_atomic
3237 if ($line =~ /\bin_atomic\s*\(/) {
3238 if ($realfile =~ m@
^drivers
/@
) {
3240 "do not use in_atomic in drivers\n" . $herecurr);
3241 } elsif ($realfile !~ m@
^kernel
/@
) {
3243 "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
3247 # check for lockdep_set_novalidate_class
3248 if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
3249 $line =~ /__lockdep_no_validate__\s*\)/ ) {
3250 if ($realfile !~ m@
^kernel
/lockdep@
&&
3251 $realfile !~ m@
^include
/linux/lockdep@
&&
3252 $realfile !~ m@
^drivers
/base/core@
) {
3254 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
3258 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
3259 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
3260 WARN
("EXPORTED_WORLD_WRITABLE",
3261 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
3264 # Check for memset with swapped arguments
3265 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
3267 "memset size is 3rd argument, not the second.\n" . $herecurr);
3271 # If we have no input at all, then there is nothing to report on
3272 # so just keep quiet.
3273 if ($#rawlines == -1) {
3277 # In mailback mode only produce a report in the negative, for
3278 # things that appear to be patches.
3279 if ($mailback && ($clean == 1 || !$is_patch)) {
3283 # This is not a patch, and we are are in 'no-patch' mode so
3285 if (!$chk_patch && !$is_patch) {
3290 ERROR
("NOT_UNIFIED_DIFF",
3291 "Does not appear to be a unified-diff format patch\n");
3293 if ($is_patch && $chk_signoff && $signoff == 0) {
3294 ERROR
("MISSING_SIGN_OFF",
3295 "Missing Signed-off-by: line(s)\n");
3298 print report_dump
();
3299 if ($summary && !($clean == 1 && $quiet == 1)) {
3300 print "$filename " if ($summary_file);
3301 print "total: $cnt_error errors, $cnt_warn warnings, " .
3302 (($check)?
"$cnt_chk checks, " : "") .
3303 "$cnt_lines lines checked\n";
3304 print "\n" if ($quiet == 0);
3308 # If there were whitespace errors which cleanpatch can fix
3309 # then suggest that.
3310 if ($rpt_cleaners) {
3311 print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
3312 print " scripts/cleanfile\n\n";
3317 if (keys %ignore_type) {
3318 print "NOTE: Ignored message types:";
3319 foreach my $ignore (sort keys %ignore_type) {
3323 print "\n" if ($quiet == 0);
3326 if ($clean == 1 && $quiet == 0) {
3327 print "$vname has no obvious style problems and is ready for submission.\n"
3329 if ($clean == 0 && $quiet == 0) {
3331 $vname has style problems
, please review
.
3333 If any of these errors are false positives
, please report
3334 them to the openocd
-devel mailing list
or prepare a patch
3335 and send it to Gerrit
for review
.
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)