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 if ($rawline =~ /\bwrite to the Free/i ||
1635 $rawline =~ /\b59\s+Temple\s+Pl/i ||
1636 $rawline =~ /\b51\s+Franklin\s+St/i) {
1637 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1638 ERROR
("FSF_MAILING_ADDRESS",
1639 "Do not include the paragraph about writing to the Free Software Foundation's mailing address " .
1640 "from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. " .
1641 "OpenOCD already includes a copy of the GPL.\n" . $herevet)
1644 # check for Kconfig help text having a real description
1645 # Only applies when adding the entry originally, after that we do not have
1646 # sufficient context to determine whether it is indeed long enough.
1647 if ($realfile =~ /Kconfig/ &&
1648 $line =~ /\+\s*(?:---)?help(?:---)?$/) {
1651 my $ln = $linenr + 1;
1654 while ($cnt > 0 && defined $lines[$ln - 1]) {
1655 $f = $lines[$ln - 1];
1656 $cnt-- if ($lines[$ln - 1] !~ /^-/);
1657 $is_end = $lines[$ln - 1] =~ /^\+/;
1660 next if ($f =~ /^-/);
1664 next if ($f =~ /^$/);
1665 if ($f =~ /^\s*config\s/) {
1671 WARN
("CONFIG_DESCRIPTION",
1672 "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4);
1673 #print "is_end<$is_end> length<$length>\n";
1676 # check we are in a valid source file if not then ignore this hunk
1677 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
1680 if ($line =~ /^\+/ && $prevrawline !~ /\/\
*\
*/ &&
1681 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
1682 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
1683 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
1687 "line over 120 characters\n" . $herecurr);
1690 # check for spaces before a quoted newline
1691 if ($rawline =~ /^.*\".*\s\\n/) {
1692 WARN
("QUOTED_WHITESPACE_BEFORE_NEWLINE",
1693 "unnecessary whitespace before a quoted newline\n" . $herecurr);
1696 # check for adding lines without a newline.
1697 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
1698 WARN
("MISSING_EOF_NEWLINE",
1699 "adding a line without newline at end of file\n" . $herecurr);
1702 # Blackfin: use hi/lo macros
1703 if ($realfile =~ m
@arch/blackfin/.*\
.S
$@
) {
1704 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
1705 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1707 "use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
1709 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
1710 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1712 "use the HI() macro, not (... >> 16)\n" . $herevet);
1716 # check we are in a valid source file C or perl if not then ignore this hunk
1717 next if ($realfile !~ /\.(h|c|pl)$/);
1719 # at the beginning of a line any tabs must come first and anything
1720 # more than 8 must use tabs.
1721 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1722 $rawline =~ /^\+\s* \s*/) {
1723 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1724 ERROR
("CODE_INDENT",
1725 "code indent should use tabs where possible\n" . $herevet);
1729 # check for space before tabs.
1730 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1731 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1732 WARN
("SPACE_BEFORE_TAB",
1733 "please, no space before tabs\n" . $herevet);
1736 # check we are in a valid C source file if not then ignore this hunk
1737 next if ($realfile !~ /\.(h|c)$/);
1739 # check for spaces at the beginning of a line.
1741 # 1) within comments
1742 # 2) indented preprocessor commands
1744 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
1745 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1746 WARN
("LEADING_SPACE",
1747 "please, no spaces at the start of a line\n" . $herevet);
1750 # check for RCS/CVS revision markers
1751 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
1753 "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
1756 # Blackfin: don't use __builtin_bfin_[cs]sync
1757 if ($line =~ /__builtin_bfin_csync/) {
1758 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1760 "use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
1762 if ($line =~ /__builtin_bfin_ssync/) {
1763 my $herevet = "$here\n" . cat_vet
($line) . "\n";
1765 "use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
1768 # Check for potential 'bare' types
1769 my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
1771 if ($realcnt && $line =~ /.\s*\S/) {
1772 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
1773 ctx_statement_block
($linenr, $realcnt, 0);
1774 $stat =~ s/\n./\n /g;
1775 $cond =~ s/\n./\n /g;
1777 # Find the real next line.
1778 $realline_next = $line_nr_next;
1779 if (defined $realline_next &&
1780 (!defined $lines[$realline_next - 1] ||
1781 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
1788 # Ignore goto labels.
1789 if ($s =~ /$Ident:\*$/s) {
1791 # Ignore functions being called
1792 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
1794 } elsif ($s =~ /^.\s*else\b/s) {
1796 # declarations always start with types
1797 } 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) {
1800 possible
($type, "A:" . $s);
1802 # definitions in global scope can only start with types
1803 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
1804 possible
($1, "B:" . $s);
1807 # any (foo ... *) is a pointer cast, and foo is a type
1808 while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
1809 possible
($1, "C:" . $s);
1812 # Check for any sort of function declaration.
1813 # int foo(something bar, other baz);
1814 # void (*store_gdt)(x86_descr_ptr *);
1815 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
1816 my ($name_len) = length($1);
1819 substr($ctx, 0, $name_len + 1, '');
1820 $ctx =~ s/\)[^\)]*$//;
1822 for my $arg (split(/\s*,\s*/, $ctx)) {
1823 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
1825 possible
($1, "D:" . $s);
1833 # Checks which may be anchored in the context.
1836 # Check for switch () and associated case and default
1837 # statements should be at the same indent.
1838 # if ($line=~/\bswitch\s*\(.*\)/) {
1841 # my @ctx = ctx_block_outer($linenr, $realcnt);
1843 # for my $ctx (@ctx) {
1844 # my ($clen, $cindent) = line_stats($ctx);
1845 # if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
1846 # $indent != $cindent) {
1847 # $err .= "$sep$ctx\n";
1854 # ERROR("SWITCH_CASE_INDENT_LEVEL",
1855 # "switch and case should be at the same indent\n$hereline$err");
1859 # if/while/etc brace do not go on next line, unless defining a do while loop,
1860 # or if that brace on the next line is for something else
1861 if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
1862 my $pre_ctx = "$1$2";
1864 my ($level, @ctx) = ctx_statement_level
($linenr, $realcnt, 0);
1865 my $ctx_cnt = $realcnt - $#ctx - 1;
1866 my $ctx = join("\n", @ctx);
1868 my $ctx_ln = $linenr;
1869 my $ctx_skip = $realcnt;
1871 while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
1872 defined $lines[$ctx_ln - 1] &&
1873 $lines[$ctx_ln - 1] =~ /^-/)) {
1874 ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
1875 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
1879 #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
1880 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
1882 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1884 "that open brace { should be on the previous line\n" .
1885 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1887 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
1888 $ctx =~ /\)\s*\;\s*$/ &&
1889 defined $lines[$ctx_ln - 1])
1891 my ($nlength, $nindent) = line_stats
($lines[$ctx_ln - 1]);
1892 if ($nindent > $indent) {
1893 WARN
("TRAILING_SEMICOLON",
1894 "trailing semicolon indicates no statements, indent implies otherwise\n" .
1895 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1900 # Check relative indent for conditionals and blocks.
1901 if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
1902 my ($s, $c) = ($stat, $cond);
1904 substr($s, 0, length($c), '');
1906 # Make sure we remove the line prefixes as we have
1907 # none on the first line, and are going to readd them
1911 # Find out how long the conditional actually is.
1912 my @newlines = ($c =~ /\n/gs);
1913 my $cond_lines = 1 + $#newlines;
1915 # We want to check the first line inside the block
1916 # starting at the end of the conditional, so remove:
1917 # 1) any blank line termination
1918 # 2) any opening brace { on end of the line
1920 my $continuation = 0;
1922 $s =~ s/^.*\bdo\b//;
1924 if ($s =~ s/^\s*\\//) {
1927 if ($s =~ s/^\s*?\n//) {
1932 # Also ignore a loop construct at the end of a
1933 # preprocessor statement.
1934 if (($prevline =~ /^.\s*#\s*define\s/ ||
1935 $prevline =~ /\\\s*$/) && $continuation == 0) {
1941 while ($cond_ptr != $cond_lines) {
1942 $cond_ptr = $cond_lines;
1944 # If we see an #else/#elif then the code
1946 if ($s =~ /^\s*\#\s*(?:else|elif)/) {
1951 # 1) blank lines, they should be at 0,
1952 # 2) preprocessor lines, and
1954 if ($continuation ||
1956 $s =~ /^\s*#\s*?/ ||
1957 $s =~ /^\s*$Ident\s*:/) {
1958 $continuation = ($s =~ /^.*?\\\n/) ?
1 : 0;
1959 if ($s =~ s/^.*?\n//) {
1965 my (undef, $sindent) = line_stats
("+" . $s);
1966 my $stat_real = raw_line
($linenr, $cond_lines);
1968 # Check if either of these lines are modified, else
1969 # this is not this patch's fault.
1970 if (!defined($stat_real) ||
1971 $stat !~ /^\+/ && $stat_real !~ /^\+/) {
1974 if (defined($stat_real) && $cond_lines > 1) {
1975 $stat_real = "[...]\n$stat_real";
1978 #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";
1980 if ($check && (($sindent % 4) != 0 ||
1981 ($sindent <= $indent && $s ne ''))) {
1982 WARN
("SUSPECT_CODE_INDENT",
1983 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
1987 # Track the 'values' across context and added lines.
1988 my $opline = $line; $opline =~ s/^./ /;
1989 my ($curr_values, $curr_vars) =
1990 annotate_values
($opline . "\n", $prev_values);
1991 $curr_values = $prev_values . $curr_values;
1993 my $outline = $opline; $outline =~ s/\t/ /g;
1994 print "$linenr > .$outline\n";
1995 print "$linenr > $curr_values\n";
1996 print "$linenr > $curr_vars\n";
1998 $prev_values = substr($curr_values, -1);
2000 #ignore lines not being added
2001 if ($line=~/^[^\+]/) {next;}
2003 # TEST: allow direct testing of the type matcher.
2005 if ($line =~ /^.\s*$Declare\s*$/) {
2007 "TEST: is type\n" . $herecurr);
2008 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
2009 ERROR
("TEST_NOT_TYPE",
2010 "TEST: is not type ($1 is)\n". $herecurr);
2014 # TEST: allow direct testing of the attribute matcher.
2016 if ($line =~ /^.\s*$Modifier\s*$/) {
2018 "TEST: is attr\n" . $herecurr);
2019 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
2020 ERROR
("TEST_NOT_ATTR",
2021 "TEST: is not attr ($1 is)\n". $herecurr);
2026 # check for initialisation to aggregates open brace on the next line
2027 if ($line =~ /^.\s*{/ &&
2028 $prevline =~ /(?:^|[^=])=\s*$/) {
2030 "that open brace { should be on the previous line\n" . $hereprev);
2034 # Checks which are anchored on the added line.
2037 # check for malformed paths in #include statements (uses RAW line)
2038 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
2040 if ($path =~ m{//}) {
2041 ERROR
("MALFORMED_INCLUDE",
2042 "malformed #include filename\n" .
2047 # no C99 // comments
2048 if ($line =~ m{//}) {
2049 ERROR
("C99_COMMENTS",
2050 "do not use C99 // comments\n" . $herecurr);
2052 # Remove C99 comments.
2054 $opline =~ s@
//.*@@
;
2056 # EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
2057 # the whole statement.
2058 #print "APW <$lines[$realline_next - 1]>\n";
2059 if (defined $realline_next &&
2060 exists $lines[$realline_next - 1] &&
2061 !defined $suppress_export{$realline_next} &&
2062 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
2063 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
2064 # Handle definitions which produce identifiers with
2067 # EXPORT_SYMBOL(something_foo);
2069 if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ &&
2070 $name =~ /^${Ident}_$2/) {
2071 #print "FOO C name<$name>\n";
2072 $suppress_export{$realline_next} = 1;
2074 } elsif ($stat !~ /(?
:
2076 ^.DEFINE_
$Ident\
(\Q
$name\E\
)|
2077 ^.DECLARE_
$Ident\
(\Q
$name\E\
)|
2078 ^.LIST_HEAD\
(\Q
$name\E\
)|
2079 ^.(?
:$Storage\s
+)?
$Type\s
*\
(\s
*\
*\s
*\Q
$name\E\s
*\
)\s
*\
(|
2080 \b\Q
$name\E
(?
:\s
+$Attribute)*\s
*(?
:;|=|\
[|\
()
2082 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
2083 $suppress_export{$realline_next} = 2;
2085 $suppress_export{$realline_next} = 1;
2088 if (!defined $suppress_export{$linenr} &&
2089 $prevline =~ /^.\s*$/ &&
2090 ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
2091 $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
2092 #print "FOO B <$lines[$linenr - 1]>\n";
2093 $suppress_export{$linenr} = 2;
2095 if (defined $suppress_export{$linenr} &&
2096 $suppress_export{$linenr} == 2) {
2097 WARN
("EXPORT_SYMBOL",
2098 "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
2101 # check for global initialisers.
2102 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
2103 ERROR
("GLOBAL_INITIALISERS",
2104 "do not initialise globals to 0 or NULL\n" .
2107 # check for static initialisers.
2108 if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
2109 ERROR
("INITIALISED_STATIC",
2110 "do not initialise statics to 0 or NULL\n" .
2114 # check for static const char * arrays.
2115 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
2116 WARN
("STATIC_CONST_CHAR_ARRAY",
2117 "static const char * array should probably be static const char * const\n" .
2121 # check for static char foo[] = "bar" declarations.
2122 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
2123 WARN
("STATIC_CONST_CHAR_ARRAY",
2124 "static char array declaration should probably be static const char\n" .
2128 # check for declarations of struct pci_device_id
2129 if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) {
2130 WARN
("DEFINE_PCI_DEVICE_TABLE",
2131 "Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr);
2134 # check for new typedefs, only function parameters and sparse annotations
2136 # if ($line =~ /\btypedef\s/ &&
2137 # $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
2138 # $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
2139 # $line !~ /\b$typeTypedefs\b/ &&
2140 # $line !~ /\b__bitwise(?:__|)\b/) {
2141 # WARN("NEW_TYPEDEFS",
2142 # "do not add new typedefs\n" . $herecurr);
2145 # * goes on variable not on type
2147 if ($line =~ m{\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\)}) {
2148 my ($from, $to) = ($1, $1);
2150 # Should start with a space.
2151 $to =~ s/^(\S)/ $1/;
2152 # Should not end with a space.
2154 # '*'s should not have spaces between.
2155 while ($to =~ s/\*\s+\*/\*\*/) {
2158 #print "from<$from> to<$to>\n";
2160 ERROR
("POINTER_LOCATION",
2161 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
2163 } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) {
2164 my ($from, $to, $ident) = ($1, $1, $2);
2166 # Should start with a space.
2167 $to =~ s/^(\S)/ $1/;
2168 # Should not end with a space.
2170 # '*'s should not have spaces between.
2171 while ($to =~ s/\*\s+\*/\*\*/) {
2173 # Modifiers should have spaces.
2174 $to =~ s/(\b$Modifier$)/$1 /;
2176 #print "from<$from> to<$to> ident<$ident>\n";
2177 if ($from ne $to && $ident !~ /^$Modifier$/) {
2178 ERROR
("POINTER_LOCATION",
2179 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr);
2183 # # no BUG() or BUG_ON()
2184 # if ($line =~ /\b(BUG|BUG_ON)\b/) {
2185 # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
2186 # print "$herecurr";
2190 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
2191 WARN
("LINUX_VERSION_CODE",
2192 "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
2195 # check for uses of printk_ratelimit
2196 if ($line =~ /\bprintk_ratelimit\s*\(/) {
2197 WARN
("PRINTK_RATELIMITED",
2198 "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
2201 # printk should use KERN_* levels. Note that follow on printk's on the
2202 # same line do not need a level, so we use the current block context
2203 # to try and find and validate the current printk. In summary the current
2204 # printk includes all preceding printk's which have no newline on the end.
2205 # we assume the first bad printk is the one to report.
2206 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
2208 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
2209 #print "CHECK<$lines[$ln - 1]\n";
2210 # we have a preceding printk if it ends
2211 # with "\n" ignore it, else it is to blame
2212 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
2213 if ($rawlines[$ln - 1] !~ m{\\n"}) {
2220 WARN
("PRINTK_WITHOUT_KERN_LEVEL",
2221 "printk() should include KERN_ facility level\n" . $herecurr);
2225 # function brace can't be on same line, except for #defines of do while,
2226 # or if closed on same line
2227 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
2228 !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) {
2230 "open brace '{' following function declarations go on the next line\n" . $herecurr);
2233 # open braces for enum, union and struct go on the same line.
2234 if ($line =~ /^.\s*{/ &&
2235 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
2237 "open brace '{' following $1 go on the same line\n" . $hereprev);
2240 # missing space after union, struct or enum definition
2241 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
2243 "missing space after $1 definition\n" . $herecurr);
2246 # check for spacing round square brackets; allowed:
2247 # 1. with a type on the left -- int [] a;
2248 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
2249 # 3. inside a curly brace -- = { [0...10] = 5 }
2250 while ($line =~ /(.*?\s)\[/g) {
2251 my ($where, $prefix) = ($-[1], $1);
2252 if ($prefix !~ /$Type\s+$/ &&
2253 ($where != 0 || $prefix !~ /^.\s+$/) &&
2254 $prefix !~ /{\s+$/) {
2255 ERROR
("BRACKET_SPACE",
2256 "space prohibited before open square bracket '['\n" . $herecurr);
2260 # check for spaces between functions and their parentheses.
2261 while ($line =~ /($Ident)\s+\(/g) {
2263 my $ctx_before = substr($line, 0, $-[1]);
2264 my $ctx = "$ctx_before$name";
2266 # Ignore those directives where spaces _are_ permitted.
2268 if|for|while|switch
|return|case
|
2269 volatile
|__volatile__
|
2270 __attribute__
|format
|__extension__
|
2274 # cpp #define statements have non-optional spaces, ie
2275 # if there is a space between the name and the open
2276 # parenthesis it is simply not a parameter group.
2277 } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
2279 # cpp #elif statement condition may start with a (
2280 } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
2282 # If this whole things ends with a type its most
2283 # likely a typedef for a function.
2284 } elsif ($ctx =~ /$Type$/) {
2288 "space prohibited between function name and open parenthesis '('\n" . $herecurr);
2291 # Check operator spacing.
2292 if (!($line=~/\#\s*include/)) {
2294 <<=|>>=|<=|>=|==|!=|
2295 \
+=|-=|\
*=|\
/=|%=|\
^=|\
|=|&=|
2296 =>|->|<<|>>|<|>|=|!|~|
2297 &&|\
|\
||,|\
^|\
+\
+|--|&|\
||\
+|-|\
*|\
/|%|
2300 my @elements = split(/($ops|;)/, $opline);
2303 my $blank = copy_spacing
($opline);
2305 for (my $n = 0; $n < $#elements; $n += 2) {
2306 $off += length($elements[$n]);
2308 # Pick up the preceding and succeeding characters.
2309 my $ca = substr($opline, 0, $off);
2311 if (length($opline) >= ($off + length($elements[$n + 1]))) {
2312 $cc = substr($opline, $off + length($elements[$n + 1]));
2314 my $cb = "$ca$;$cc";
2317 $a = 'V' if ($elements[$n] ne '');
2318 $a = 'W' if ($elements[$n] =~ /\s$/);
2319 $a = 'C' if ($elements[$n] =~ /$;$/);
2320 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
2321 $a = 'O' if ($elements[$n] eq '');
2322 $a = 'E' if ($ca =~ /^\s*$/);
2324 my $op = $elements[$n + 1];
2327 if (defined $elements[$n + 2]) {
2328 $c = 'V' if ($elements[$n + 2] ne '');
2329 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
2330 $c = 'C' if ($elements[$n + 2] =~ /^$;/);
2331 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
2332 $c = 'O' if ($elements[$n + 2] eq '');
2333 $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
2338 my $ctx = "${a}x${c}";
2340 my $at = "(ctx:$ctx)";
2342 my $ptr = substr($blank, 0, $off) . "^";
2343 my $hereptr = "$hereline$ptr\n";
2345 # Pull out the value of this operator.
2346 my $op_type = substr($curr_values, $off + 1, 1);
2348 # Get the full operator variant.
2349 my $opv = $op . substr($curr_vars, $off, 1);
2351 # Ignore operators passed as parameters.
2352 if ($op_type ne 'V' &&
2353 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
2356 # } elsif ($op =~ /^$;+$/) {
2358 # ; should have either the end of line or a space or \ after it
2359 } elsif ($op eq ';') {
2360 if ($ctx !~ /.x[WEBC]/ &&
2361 $cc !~ /^\\/ && $cc !~ /^;/) {
2363 "space required after that '$op' $at\n" . $hereptr);
2367 } elsif ($op eq '//') {
2371 # : when part of a bitfield
2372 } elsif ($op eq '->' || $opv eq ':B') {
2373 if ($ctx =~ /Wx.|.xW/) {
2375 "spaces prohibited around that '$op' $at\n" . $hereptr);
2378 # , must have a space on the right.
2379 } elsif ($op eq ',') {
2380 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
2382 "space required after that '$op' $at\n" . $hereptr);
2385 # '*' as part of a type definition -- reported already.
2386 } elsif ($opv eq '*_') {
2387 #warn "'*' is part of type\n";
2389 # unary operators should have a space before and
2390 # none after. May be left adjacent to another
2391 # unary operator, or a cast
2392 } elsif ($op eq '!' || $op eq '~' ||
2393 $opv eq '*U' || $opv eq '-U' ||
2394 $opv eq '&U' || $opv eq '&&U') {
2395 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
2397 "space required before that '$op' $at\n" . $hereptr);
2399 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
2400 # A unary '*' may be const
2402 } elsif ($ctx =~ /.xW/) {
2404 "space prohibited after that '$op' $at\n" . $hereptr);
2407 # unary ++ and unary -- are allowed no space on one side.
2408 } elsif ($op eq '++' or $op eq '--') {
2409 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
2411 "space required one side of that '$op' $at\n" . $hereptr);
2413 if ($ctx =~ /Wx[BE]/ ||
2414 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
2416 "space prohibited before that '$op' $at\n" . $hereptr);
2418 if ($ctx =~ /ExW/) {
2420 "space prohibited after that '$op' $at\n" . $hereptr);
2424 # << and >> may either have or not have spaces both sides
2425 } elsif ($op eq '<<' or $op eq '>>' or
2426 $op eq '&' or $op eq '^' or $op eq '|' or
2427 $op eq '+' or $op eq '-' or
2428 $op eq '*' or $op eq '/' or
2431 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
2433 "need consistent spacing around '$op' $at\n" .
2437 # A colon needs no spaces before when it is
2438 # terminating a case value or a label.
2439 } elsif ($opv eq ':C' || $opv eq ':L') {
2440 if ($ctx =~ /Wx./) {
2442 "space prohibited before that '$op' $at\n" . $hereptr);
2445 # All the others need spaces both sides.
2446 } elsif ($ctx !~ /[EWC]x[CWE]/) {
2449 # Ignore email addresses <foo@bar>
2451 $cc =~ /^\S+\@\S+>/) ||
2453 $ca =~ /<\S+\@\S+$/))
2459 if (($opv eq ':O' && $ca =~ /\?$/) ||
2460 ($op eq '?' && $cc =~ /^:/)) {
2466 "spaces required around that '$op' $at\n" . $hereptr);
2469 $off += length($elements[$n + 1]);
2473 # check for multiple assignments
2474 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
2475 CHK
("MULTIPLE_ASSIGNMENTS",
2476 "multiple assignments should be avoided\n" . $herecurr);
2479 ## # check for multiple declarations, allowing for a function declaration
2481 ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
2482 ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
2484 ## # Remove any bracketed sections to ensure we do not
2485 ## # falsly report the parameters of functions.
2487 ## while ($ln =~ s/\([^\(\)]*\)//g) {
2489 ## if ($ln =~ /,/) {
2490 ## WARN("MULTIPLE_DECLARATION",
2491 ## "declaring multiple variables together should be avoided\n" . $herecurr);
2495 #need space before brace following if, while, etc
2496 if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\){/) ||
2499 "space required before the open brace '{'\n" . $herecurr);
2502 # closing brace should have a space following it when it has anything
2504 if ($line =~ /}(?!(?:,|;|\)))\S/) {
2506 "space required after that close brace '}'\n" . $herecurr);
2509 # check spacing on square brackets
2510 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
2512 "space prohibited after that open square bracket '['\n" . $herecurr);
2514 if ($line =~ /\s\]/) {
2516 "space prohibited before that close square bracket ']'\n" . $herecurr);
2519 # check spacing on parentheses
2520 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
2521 $line !~ /for\s*\(\s+;/) {
2523 "space prohibited after that open parenthesis '('\n" . $herecurr);
2525 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
2526 $line !~ /for\s*\(.*;\s+\)/ &&
2527 $line !~ /:\s+\)/) {
2529 "space prohibited before that close parenthesis ')'\n" . $herecurr);
2532 #goto labels aren't indented, allow a single space however
2533 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
2534 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
2535 WARN
("INDENTED_LABEL",
2536 "labels should not be indented\n" . $herecurr);
2539 # Return is not a function.
2540 if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) {
2544 # Flatten any parentheses
2545 $value =~ s/\(/ \(/g;
2546 $value =~ s/\)/\) /g;
2547 while ($value =~ s/\[[^\{\}]*\]/1/ ||
2548 $value !~ /(?
:$Ident|-?
$Constant)\s
*
2550 (?
:$Ident|-?
$Constant)/x
&&
2551 $value =~ s/\([^\(\)]*\)/1/) {
2553 #print "value<$value>\n";
2554 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
2555 ERROR
("RETURN_PARENTHESES",
2556 "return is not a function, parentheses are not required\n" . $herecurr);
2558 } elsif ($spacing !~ /\s+/) {
2560 "space required before the open parenthesis '('\n" . $herecurr);
2563 # Return of what appears to be an errno should normally be -'ve
2564 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
2566 if ($name ne 'EOF' && $name ne 'ERROR') {
2567 WARN
("USE_NEGATIVE_ERRNO",
2568 "return of an errno should typically be -ve (return -$1)\n" . $herecurr);
2572 # typecasts on min/max could be min_t/max_t
2573 if ($line =~ /^\+(?:.*?)\b(min|max)\s*\($Typecast{0,1}($LvalOrFunc)\s*,\s*$Typecast{0,1}($LvalOrFunc)\s*\)/) {
2574 if (defined $2 || defined $8) {
2576 my $cast1 = deparenthesize
($2);
2578 my $cast2 = deparenthesize
($8);
2582 if ($cast1 ne "" && $cast2 ne "") {
2583 $cast = "$cast1 or $cast2";
2584 } elsif ($cast1 ne "") {
2590 "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . $herecurr);
2594 # Need a space before open parenthesis after if, while etc
2595 if ($line=~/\b(if|while|for|switch)\(/) {
2596 ERROR
("SPACING", "space required before the open parenthesis '('\n" . $herecurr);
2599 # Check for illegal assignment in if conditional -- and check for trailing
2600 # statements after the conditional.
2601 if ($line =~ /do\s*(?!{)/) {
2602 my ($stat_next) = ctx_statement_block
($line_nr_next,
2603 $remain_next, $off_next);
2604 $stat_next =~ s/\n./\n /g;
2605 ##print "stat<$stat> stat_next<$stat_next>\n";
2607 if ($stat_next =~ /^\s*while\b/) {
2608 # If the statement carries leading newlines,
2609 # then count those as offsets.
2611 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
2613 statement_rawlines
($whitespace) - 1;
2615 $suppress_whiletrailers{$line_nr_next +
2619 if (!defined $suppress_whiletrailers{$linenr} &&
2620 $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
2621 my ($s, $c) = ($stat, $cond);
2623 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
2624 ERROR
("ASSIGN_IN_IF",
2625 "do not use assignment in if condition\n" . $herecurr);
2628 # Find out what is on the end of the line after the
2630 substr($s, 0, length($c), '');
2632 $s =~ s/$;//g; # Remove any comments
2633 if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
2634 $c !~ /}\s*while\s*/)
2636 # Find out how long the conditional actually is.
2637 my @newlines = ($c =~ /\n/gs);
2638 my $cond_lines = 1 + $#newlines;
2641 $stat_real = raw_line
($linenr, $cond_lines)
2642 . "\n" if ($cond_lines);
2643 if (defined($stat_real) && $cond_lines > 1) {
2644 $stat_real = "[...]\n$stat_real";
2647 ERROR
("TRAILING_STATEMENTS",
2648 "trailing statements should be on next line\n" . $herecurr . $stat_real);
2652 # Check for bitwise tests written as boolean
2664 WARN
("HEXADECIMAL_BOOLEAN_TEST",
2665 "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
2668 # if and else should not have general statements after it
2669 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
2671 $s =~ s/$;//g; # Remove any comments
2672 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
2673 ERROR
("TRAILING_STATEMENTS",
2674 "trailing statements should be on next line\n" . $herecurr);
2677 # if should not continue a brace
2678 if ($line =~ /}\s*if\b/) {
2679 ERROR
("TRAILING_STATEMENTS",
2680 "trailing statements should be on next line\n" .
2683 # case and default should not have general statements after them
2684 if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
2686 (?
:\s
*$;*)(?
:\s
*{)?
(?
:\s
*$;*)(?
:\s
*\\)?\s
*$|
2690 ERROR
("TRAILING_STATEMENTS",
2691 "trailing statements should be on next line\n" . $herecurr);
2694 # Check for }<nl>else {, these must be at the same
2695 # indent level to be relevant to each other.
2696 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
2697 $previndent == $indent) {
2698 ERROR
("ELSE_AFTER_BRACE",
2699 "else should follow close brace '}'\n" . $hereprev);
2702 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
2703 $previndent == $indent) {
2704 my ($s, $c) = ctx_statement_block
($linenr, $realcnt, 0);
2706 # Find out what is on the end of the line after the
2708 substr($s, 0, length($c), '');
2711 if ($s =~ /^\s*;/) {
2712 ERROR
("WHILE_AFTER_BRACE",
2713 "while should follow close brace '}'\n" . $hereprev);
2717 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
2718 # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
2719 # print "No studly caps, use _\n";
2720 # print "$herecurr";
2724 #no spaces allowed after \ in define
2725 if ($line=~/\#\s*define.*\\\s$/) {
2726 WARN
("WHITESPACE_AFTER_LINE_CONTINUATION",
2727 "Whitepspace after \\ makes next lines useless\n" . $herecurr);
2730 #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
2731 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
2733 my $checkfile = "include/linux/$file";
2734 if (-f
"$root/$checkfile" &&
2735 $realfile ne $checkfile &&
2736 $1 !~ /$allowed_asm_includes/)
2738 if ($realfile =~ m{^arch/}) {
2739 CHK
("ARCH_INCLUDE_LINUX",
2740 "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2742 WARN
("INCLUDE_LINUX",
2743 "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2748 # multi-statement macros should be enclosed in a do while loop, grab the
2749 # first statement and ensure its the whole macro if its not enclosed
2750 # in a known good container
2751 if ($realfile !~ m@
/vmlinux
.lds
.h
$@
&&
2752 $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
2755 my ($off, $dstat, $dcond, $rest);
2758 my $args = defined($1);
2760 # Find the end of the macro and limit our statement
2762 while ($cnt > 0 && defined $lines[$ln - 1] &&
2763 $lines[$ln - 1] =~ /^(?:-|..*\\$)/)
2765 $ctx .= $rawlines[$ln - 1] . "\n";
2766 $cnt-- if ($lines[$ln - 1] !~ /^-/);
2769 $ctx .= $rawlines[$ln - 1];
2771 ($dstat, $dcond, $ln, $cnt, $off) =
2772 ctx_statement_block
($linenr, $ln - $linenr + 1, 0);
2773 #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
2774 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
2776 # Extract the remainder of the define (if any) and
2777 # rip off surrounding spaces, and trailing \'s.
2779 while ($off != 0 || ($cnt > 0 && $rest =~ /\\\s*$/)) {
2780 #print "ADDING cnt<$cnt> $off <" . substr($lines[$ln - 1], $off) . "> rest<$rest>\n";
2781 if ($off != 0 || $lines[$ln - 1] !~ /^-/) {
2782 $rest .= substr($lines[$ln - 1], $off) . "\n";
2788 $rest =~ s/\\\n.//g;
2792 # Clean up the original statement.
2794 substr($dstat, 0, length($dcond), '');
2796 $dstat =~ s/^.\s*\#\s*define\s+$Ident\s*//;
2799 $dstat =~ s/\\\n.//g;
2800 $dstat =~ s/^\s*//s;
2801 $dstat =~ s/\s*$//s;
2803 # Flatten any parentheses and braces
2804 while ($dstat =~ s/\([^\(\)]*\)/1/ ||
2805 $dstat =~ s/\{[^\{\}]*\}/1/ ||
2806 $dstat =~ s/\[[^\{\}]*\]/1/)
2810 my $exceptions = qr{
2822 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
2823 if ($rest ne '' && $rest ne ',') {
2824 if ($rest !~ /while\s*\(/ &&
2825 $dstat !~ /$exceptions/)
2827 ERROR
("MULTISTATEMENT_MACRO_USE_DO_WHILE",
2828 "Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
2831 } elsif ($ctx !~ /;/) {
2833 $dstat !~ /^(?:$Ident|-?$Constant)$/ &&
2834 $dstat !~ /$exceptions/ &&
2835 $dstat !~ /^\.$Ident\s*=/ &&
2836 $dstat =~ /$Operators/)
2838 ERROR
("COMPLEX_MACRO",
2839 "Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
2844 # make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
2845 # all assignments may have only one of the following with an assignment:
2848 # VMLINUX_SYMBOL(...)
2849 if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
2850 WARN
("MISSING_VMLINUX_SYMBOL",
2851 "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
2854 # check for redundant bracing round if etc
2855 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
2856 my ($level, $endln, @chunks) =
2857 ctx_statement_full
($linenr, $realcnt, 1);
2858 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
2859 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
2860 if ($#chunks > 0 && $level == 0) {
2863 my $herectx = $here . "\n";
2864 my $ln = $linenr - 1;
2865 for my $chunk (@chunks) {
2866 my ($cond, $block) = @
{$chunk};
2868 # If the condition carries leading newlines, then count those as offsets.
2869 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
2870 my $offset = statement_rawlines
($whitespace) - 1;
2872 #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
2874 # We have looked at and allowed this specific line.
2875 $suppress_ifbraces{$ln + $offset} = 1;
2877 $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
2878 $ln += statement_rawlines
($block) - 1;
2880 substr($block, 0, length($cond), '');
2882 $seen++ if ($block =~ /^\s*{/);
2884 #print "cond<$cond> block<$block> allowed<$allowed>\n";
2885 if (statement_lines
($cond) > 1) {
2886 #print "APW: ALLOWED: cond<$cond>\n";
2889 if ($block =~/\b(?:if|for|while)\b/) {
2890 #print "APW: ALLOWED: block<$block>\n";
2893 if (statement_block_size
($block) > 1) {
2894 #print "APW: ALLOWED: lines block<$block>\n";
2898 if ($seen && !$allowed) {
2900 "braces {} are not necessary for any arm of this statement\n" . $herectx);
2904 if (!defined $suppress_ifbraces{$linenr - 1} &&
2905 $line =~ /\b(if|while|for|else)\b/) {
2908 # Check the pre-context.
2909 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
2910 #print "APW: ALLOWED: pre<$1>\n";
2914 my ($level, $endln, @chunks) =
2915 ctx_statement_full
($linenr, $realcnt, $-[0]);
2917 # Check the condition.
2918 my ($cond, $block) = @
{$chunks[0]};
2919 #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
2920 if (defined $cond) {
2921 substr($block, 0, length($cond), '');
2923 if (statement_lines
($cond) > 1) {
2924 #print "APW: ALLOWED: cond<$cond>\n";
2927 if ($block =~/\b(?:if|for|while)\b/) {
2928 #print "APW: ALLOWED: block<$block>\n";
2931 if (statement_block_size
($block) > 1) {
2932 #print "APW: ALLOWED: lines block<$block>\n";
2935 # Check the post-context.
2936 if (defined $chunks[1]) {
2937 my ($cond, $block) = @
{$chunks[1]};
2938 if (defined $cond) {
2939 substr($block, 0, length($cond), '');
2941 if ($block =~ /^\s*\{/) {
2942 #print "APW: ALLOWED: chunk-1 block<$block>\n";
2946 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
2947 my $herectx = $here . "\n";
2948 my $cnt = statement_rawlines
($block);
2950 for (my $n = 0; $n < $cnt; $n++) {
2951 $herectx .= raw_line
($linenr, $n) . "\n";
2955 "braces {} are not necessary for single statement blocks\n" . $herectx);
2959 # don't include deprecated include files (uses RAW line)
2960 for my $inc (@dep_includes) {
2961 if ($rawline =~ m@
^.\s
*\#\s
*include\s
*\
<$inc>@
) {
2962 ERROR
("DEPRECATED_INCLUDE",
2963 "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2967 # don't use deprecated functions
2968 for my $func (@dep_functions) {
2969 if ($line =~ /\b$func\b/) {
2970 ERROR
("DEPRECATED_FUNCTION",
2971 "Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2975 # no volatiles please
2976 # my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
2977 # if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
2979 # "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
2983 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
2984 CHK
("REDUNDANT_CODE",
2985 "if this code is redundant consider removing it\n" .
2989 # check for needless kfree() checks
2990 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2992 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
2993 WARN
("NEEDLESS_KFREE",
2994 "kfree(NULL) is safe this check is probably not required\n" . $hereprev);
2997 # check for needless usb_free_urb() checks
2998 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
3000 if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) {
3001 WARN
("NEEDLESS_USB_FREE_URB",
3002 "usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev);
3006 # prefer usleep_range over udelay
3007 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
3008 # ignore udelay's < 10, however
3009 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
3011 "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
3015 # warn about unexpectedly long msleep's
3016 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
3019 "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
3023 # warn about #ifdefs in C files
3024 # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
3025 # print "#ifdef in C files should be avoided\n";
3026 # print "$herecurr";
3030 # warn about spacing in #ifdefs
3031 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
3033 "exactly one space required after that #$1\n" . $herecurr);
3036 # check for spinlock_t definitions without a comment.
3037 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
3038 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
3040 if (!ctx_has_comment
($first_line, $linenr)) {
3041 CHK
("UNCOMMENTED_DEFINITION",
3042 "$1 definition without comment\n" . $herecurr);
3045 # check for memory barriers without a comment.
3046 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
3047 if (!ctx_has_comment
($first_line, $linenr)) {
3048 CHK
("MEMORY_BARRIER",
3049 "memory barrier without comment\n" . $herecurr);
3052 # check of hardware specific defines
3053 if ($line =~ m@
^.\s
*\#\s
*if.*\b(__i386__
|__powerpc64__
|__sun__
|__s390x__
)\b@
&& $realfile !~ m
@include/asm
-@
) {
3055 "architecture specific defines should be avoided\n" . $herecurr);
3058 # Check that the storage class is at the beginning of a declaration
3059 if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
3060 WARN
("STORAGE_CLASS",
3061 "storage class should be at the beginning of the declaration\n" . $herecurr)
3064 # check the location of the inline attribute, that it is between
3065 # storage class and type.
3066 if ($line =~ /\b$Type\s+$Inline\b/ ||
3067 $line =~ /\b$Inline\s+$Storage\b/) {
3068 ERROR
("INLINE_LOCATION",
3069 "inline keyword should sit between storage class and type\n" . $herecurr);
3072 # Check for __inline__ and __inline, prefer inline
3073 if ($line =~ /\b(__inline__|__inline)\b/) {
3075 "plain inline is preferred over $1\n" . $herecurr);
3078 # Check for __attribute__ packed, prefer __packed
3079 # if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
3080 # WARN("PREFER_PACKED",
3081 # "__packed is preferred over __attribute__((packed))\n" . $herecurr);
3084 # Check for __attribute__ aligned, prefer __aligned
3085 # if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
3086 # WARN("PREFER_ALIGNED",
3087 # "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
3090 # check for sizeof(&)
3091 if ($line =~ /\bsizeof\s*\(\s*\&/) {
3092 WARN
("SIZEOF_ADDRESS",
3093 "sizeof(& should be avoided\n" . $herecurr);
3096 # check for line continuations in quoted strings with odd counts of "
3097 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
3098 WARN
("LINE_CONTINUATIONS",
3099 "Avoid line continuations in quoted strings\n" . $herecurr);
3102 # check for new externs in .c files.
3103 # if ($realfile =~ /\.c$/ && defined $stat &&
3104 # $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
3106 # my $function_name = $1;
3107 # my $paren_space = $2;
3110 # if (defined $cond) {
3111 # substr($s, 0, length($cond), '');
3113 # if ($s =~ /^\s*;/ &&
3114 # $function_name ne 'uninitialized_var')
3116 # WARN("AVOID_EXTERNS",
3117 # "externs should be avoided in .c files\n" . $herecurr);
3120 # if ($paren_space =~ /\n/) {
3121 # WARN("FUNCTION_ARGUMENTS",
3122 # "arguments for function declarations should follow identifier\n" . $herecurr);
3125 # } elsif ($realfile =~ /\.c$/ && defined $stat &&
3126 # $stat =~ /^.\s*extern\s+/)
3128 # WARN("AVOID_EXTERNS",
3129 # "externs should be avoided in .c files\n" . $herecurr);
3132 # checks for new __setup's
3133 if ($rawline =~ /\b__setup\("([^"]*)"/) {
3136 if (!grep(/$name/, @setup_docs)) {
3137 CHK
("UNDOCUMENTED_SETUP",
3138 "__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
3142 # check for pointless casting of kmalloc return
3143 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
3144 WARN
("UNNECESSARY_CASTS",
3145 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
3148 # check for multiple semicolons
3149 if ($line =~ /;\s*;\s*$/) {
3150 WARN
("ONE_SEMICOLON",
3151 "Statements terminations use 1 semicolon\n" . $herecurr);
3154 # check for gcc specific __FUNCTION__
3155 if ($line =~ /__FUNCTION__/) {
3157 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
3160 # check for semaphores initialized locked
3161 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
3162 WARN
("CONSIDER_COMPLETION",
3163 "consider using a completion\n" . $herecurr);
3166 # recommend kstrto* over simple_strto*
3167 if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
3168 WARN
("CONSIDER_KSTRTO",
3169 "consider using kstrto* in preference to simple_$1\n" . $herecurr);
3171 # check for __initcall(), use device_initcall() explicitly please
3172 if ($line =~ /^.\s*__initcall\s*\(/) {
3173 WARN
("USE_DEVICE_INITCALL",
3174 "please use device_initcall() instead of __initcall()\n" . $herecurr);
3176 # check for various ops structs, ensure they are const.
3177 my $struct_ops = qr{acpi_dock_ops
|
3178 address_space_operations
|
3180 block_device_operations
|
3185 file_lock_operations
|
3195 lock_manager_operations
|
3201 pipe_buf_operations
|
3202 platform_hibernation_ops
|
3203 platform_suspend_ops
|
3208 soc_pcmcia_socket_ops
|
3214 if ($line !~ /\bconst\b/ &&
3215 $line =~ /\bstruct\s+($struct_ops)\b/) {
3216 WARN
("CONST_STRUCT",
3217 "struct $1 should normally be const\n" .
3221 # use of NR_CPUS is usually wrong
3222 # ignore definitions of NR_CPUS and usage to define arrays as likely right
3223 if ($line =~ /\bNR_CPUS\b/ &&
3224 $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
3225 $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
3226 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
3227 $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
3228 $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
3231 "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
3234 # check for %L{u,d,i} in strings
3236 while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
3237 $string = substr($rawline, $-[1], $+[1] - $-[1]);
3238 $string =~ s/%%/__/g;
3239 if ($string =~ /(?<!%)%L[udi]/) {
3241 "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
3246 # whine mightly about in_atomic
3247 if ($line =~ /\bin_atomic\s*\(/) {
3248 if ($realfile =~ m@
^drivers
/@
) {
3250 "do not use in_atomic in drivers\n" . $herecurr);
3251 } elsif ($realfile !~ m@
^kernel
/@
) {
3253 "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
3257 # check for lockdep_set_novalidate_class
3258 if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
3259 $line =~ /__lockdep_no_validate__\s*\)/ ) {
3260 if ($realfile !~ m@
^kernel
/lockdep@
&&
3261 $realfile !~ m@
^include
/linux/lockdep@
&&
3262 $realfile !~ m@
^drivers
/base/core@
) {
3264 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
3268 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
3269 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
3270 WARN
("EXPORTED_WORLD_WRITABLE",
3271 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
3274 # Check for memset with swapped arguments
3275 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
3277 "memset size is 3rd argument, not the second.\n" . $herecurr);
3281 # If we have no input at all, then there is nothing to report on
3282 # so just keep quiet.
3283 if ($#rawlines == -1) {
3287 # In mailback mode only produce a report in the negative, for
3288 # things that appear to be patches.
3289 if ($mailback && ($clean == 1 || !$is_patch)) {
3293 # This is not a patch, and we are are in 'no-patch' mode so
3295 if (!$chk_patch && !$is_patch) {
3300 ERROR
("NOT_UNIFIED_DIFF",
3301 "Does not appear to be a unified-diff format patch\n");
3303 if ($is_patch && $chk_signoff && $signoff == 0) {
3304 ERROR
("MISSING_SIGN_OFF",
3305 "Missing Signed-off-by: line(s)\n");
3308 print report_dump
();
3309 if ($summary && !($clean == 1 && $quiet == 1)) {
3310 print "$filename " if ($summary_file);
3311 print "total: $cnt_error errors, $cnt_warn warnings, " .
3312 (($check)?
"$cnt_chk checks, " : "") .
3313 "$cnt_lines lines checked\n";
3314 print "\n" if ($quiet == 0);
3318 # If there were whitespace errors which cleanpatch can fix
3319 # then suggest that.
3320 if ($rpt_cleaners) {
3321 print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
3322 print " scripts/cleanfile\n\n";
3327 if (keys %ignore_type) {
3328 print "NOTE: Ignored message types:";
3329 foreach my $ignore (sort keys %ignore_type) {
3333 print "\n" if ($quiet == 0);
3336 if ($clean == 1 && $quiet == 0) {
3337 print "$vname has no obvious style problems and is ready for submission.\n"
3339 if ($clean == 0 && $quiet == 0) {
3341 $vname has style problems
, please review
.
3343 If any of these errors are false positives
, please report
3344 them to the openocd
-devel mailing list
or prepare a patch
3345 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)