blob: 63cca81b1105dd951eec3d6b12c0735682b8003b [file] [log] [blame]
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001#!/usr/bin/perl -w
Dave Jonesdbf004d2010-01-12 16:59:52 -05002# (c) 2001, Dave Jones. (the file handling bit)
Andy Whitcroft00df3442007-06-08 13:47:06 -07003# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
Andy Whitcroft2a5a2c22009-01-06 14:41:23 -08004# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
Andy Whitcroft015830b2010-10-26 14:23:17 -07005# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
Andy Whitcroft0a920b52007-06-01 00:46:48 -07006# Licensed under the terms of the GNU GPL License version 2
7
8use strict;
9
10my $P = $0;
Andy Whitcroft00df3442007-06-08 13:47:06 -070011$P =~ s@.*/@@g;
Andy Whitcroft0a920b52007-06-01 00:46:48 -070012
Andy Whitcroft267ad8f2010-10-26 14:23:19 -070013my $V = '0.31';
Andy Whitcroft0a920b52007-06-01 00:46:48 -070014
15use Getopt::Long qw(:config no_auto_abbrev);
16
17my $quiet = 0;
18my $tree = 1;
19my $chk_signoff = 1;
20my $chk_patch = 1;
Andy Whitcroft773647a2008-03-28 14:15:58 -070021my $tst_only;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -070022my $emacs = 0;
Andy Whitcroft8905a672007-11-28 16:21:06 -080023my $terse = 0;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -070024my $file = 0;
25my $check = 0;
Andy Whitcroft8905a672007-11-28 16:21:06 -080026my $summary = 1;
27my $mailback = 0;
Andy Whitcroft13214ad2008-02-08 04:22:03 -080028my $summary_file = 0;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -070029my $root;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -080030my %debug;
Hannes Eder77f5b102009-09-21 17:04:37 -070031my $help = 0;
32
33sub help {
34 my ($exitcode) = @_;
35
36 print << "EOM";
37Usage: $P [OPTION]... [FILE]...
38Version: $V
39
40Options:
41 -q, --quiet quiet
42 --no-tree run without a kernel tree
43 --no-signoff do not check for 'Signed-off-by' line
44 --patch treat FILE as patchfile (default)
45 --emacs emacs compile window format
46 --terse one line per report
47 -f, --file treat FILE as regular source file
48 --subjective, --strict enable more subjective tests
49 --root=PATH PATH to the kernel tree root
50 --no-summary suppress the per-file summary
51 --mailback only produce a report in case of warnings/errors
52 --summary-file include the filename in summary
53 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
54 'values', 'possible', 'type', and 'attr' (default
55 is all off)
56 --test-only=WORD report only warnings/errors containing WORD
57 literally
58 -h, --help, --version display this help and exit
59
60When FILE is - read standard input.
61EOM
62
63 exit($exitcode);
64}
65
Andy Whitcroft0a920b52007-06-01 00:46:48 -070066GetOptions(
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -070067 'q|quiet+' => \$quiet,
Andy Whitcroft0a920b52007-06-01 00:46:48 -070068 'tree!' => \$tree,
69 'signoff!' => \$chk_signoff,
70 'patch!' => \$chk_patch,
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -070071 'emacs!' => \$emacs,
Andy Whitcroft8905a672007-11-28 16:21:06 -080072 'terse!' => \$terse,
Hannes Eder77f5b102009-09-21 17:04:37 -070073 'f|file!' => \$file,
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -070074 'subjective!' => \$check,
75 'strict!' => \$check,
76 'root=s' => \$root,
Andy Whitcroft8905a672007-11-28 16:21:06 -080077 'summary!' => \$summary,
78 'mailback!' => \$mailback,
Andy Whitcroft13214ad2008-02-08 04:22:03 -080079 'summary-file!' => \$summary_file,
80
Andy Whitcroftc2fdda02008-02-08 04:20:54 -080081 'debug=s' => \%debug,
Andy Whitcroft773647a2008-03-28 14:15:58 -070082 'test-only=s' => \$tst_only,
Hannes Eder77f5b102009-09-21 17:04:37 -070083 'h|help' => \$help,
84 'version' => \$help
85) or help(1);
86
87help(0) if ($help);
Andy Whitcroft0a920b52007-06-01 00:46:48 -070088
89my $exit = 0;
90
91if ($#ARGV < 0) {
Hannes Eder77f5b102009-09-21 17:04:37 -070092 print "$P: no input files\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -070093 exit(1);
94}
95
Andy Whitcroftc2fdda02008-02-08 04:20:54 -080096my $dbg_values = 0;
97my $dbg_possible = 0;
Andy Whitcroft7429c692008-07-23 21:29:06 -070098my $dbg_type = 0;
Andy Whitcrofta1ef2772008-10-15 22:02:17 -070099my $dbg_attr = 0;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800100for my $key (keys %debug) {
Andy Whitcroft21caa132009-01-06 14:41:30 -0800101 ## no critic
102 eval "\${dbg_$key} = '$debug{$key}';";
103 die "$@" if ($@);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800104}
105
Andy Whitcroftd2c0a232010-10-26 14:23:12 -0700106my $rpt_cleaners = 0;
107
Andy Whitcroft8905a672007-11-28 16:21:06 -0800108if ($terse) {
109 $emacs = 1;
110 $quiet++;
111}
112
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700113if ($tree) {
114 if (defined $root) {
115 if (!top_of_kernel_tree($root)) {
116 die "$P: $root: --root does not point at a valid tree\n";
117 }
118 } else {
119 if (top_of_kernel_tree('.')) {
120 $root = '.';
121 } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
122 top_of_kernel_tree($1)) {
123 $root = $1;
124 }
125 }
126
127 if (!defined $root) {
128 print "Must be run from the top-level dir. of a kernel tree\n";
129 exit(2);
130 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700131}
132
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700133my $emitted_corrupt = 0;
134
Andy Whitcroft2ceb5322009-10-26 16:50:14 -0700135our $Ident = qr{
136 [A-Za-z_][A-Za-z\d_]*
137 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
138 }x;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700139our $Storage = qr{extern|static|asmlinkage};
140our $Sparse = qr{
141 __user|
142 __kernel|
143 __force|
144 __iomem|
145 __must_check|
146 __init_refok|
Andy Whitcroft417495e2009-02-27 14:03:08 -0800147 __kprobes|
Sven Eckelmann165e72a2011-07-25 17:13:23 -0700148 __ref|
149 __rcu
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700150 }x;
Wolfram Sang52131292010-03-05 13:43:51 -0800151
152# Notes to $Attribute:
153# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700154our $Attribute = qr{
155 const|
Joe Perches03f1df72010-10-26 14:23:16 -0700156 __percpu|
157 __nocast|
158 __safe|
159 __bitwise__|
160 __packed__|
161 __packed2__|
162 __naked|
163 __maybe_unused|
164 __always_unused|
165 __noreturn|
166 __used|
167 __cold|
168 __noclone|
169 __deprecated|
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700170 __read_mostly|
171 __kprobes|
Wolfram Sang52131292010-03-05 13:43:51 -0800172 __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
Andy Whitcroft24e1d812008-10-15 22:02:18 -0700173 ____cacheline_aligned|
174 ____cacheline_aligned_in_smp|
Andy Whitcroft5fe3af12009-01-06 14:41:18 -0800175 ____cacheline_internodealigned_in_smp|
176 __weak
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700177 }x;
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700178our $Modifier;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700179our $Inline = qr{inline|__always_inline|noinline};
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700180our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
181our $Lval = qr{$Ident(?:$Member)*};
182
183our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*};
184our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
Andy Whitcroft86f9d052009-01-06 14:41:24 -0800185our $Compare = qr{<=|>=|==|!=|<|>};
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700186our $Operators = qr{
187 <=|>=|==|!=|
188 =>|->|<<|>>|<|>|!|~|
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800189 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700190 }x;
191
Andy Whitcroft8905a672007-11-28 16:21:06 -0800192our $NonptrType;
193our $Type;
194our $Declare;
195
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700196our $UTF8 = qr {
197 [\x09\x0A\x0D\x20-\x7E] # ASCII
198 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
199 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
200 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
201 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
202 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
203 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
204 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
205}x;
206
Andy Whitcroft8ed22ca2008-10-15 22:02:32 -0700207our $typeTypedefs = qr{(?x:
Andy Whitcroftfb9e9092009-09-21 17:04:38 -0700208 (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
Andy Whitcroft8ed22ca2008-10-15 22:02:32 -0700209 atomic_t
210)};
211
Joe Perches691e6692010-03-05 13:43:51 -0800212our $logFunctions = qr{(?x:
213 printk|
Joe Perchesb0531722011-05-24 17:13:40 -0700214 [a-z]+_(emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)|
Joe Perches691e6692010-03-05 13:43:51 -0800215 WARN|
Joe Perchesb0531722011-05-24 17:13:40 -0700216 panic|
217 MODULE_[A-Z_]+
Joe Perches691e6692010-03-05 13:43:51 -0800218)};
219
Andy Whitcroft8905a672007-11-28 16:21:06 -0800220our @typeList = (
221 qr{void},
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700222 qr{(?:unsigned\s+)?char},
223 qr{(?:unsigned\s+)?short},
224 qr{(?:unsigned\s+)?int},
225 qr{(?:unsigned\s+)?long},
226 qr{(?:unsigned\s+)?long\s+int},
227 qr{(?:unsigned\s+)?long\s+long},
228 qr{(?:unsigned\s+)?long\s+long\s+int},
Andy Whitcroft8905a672007-11-28 16:21:06 -0800229 qr{unsigned},
230 qr{float},
231 qr{double},
232 qr{bool},
Andy Whitcroft8905a672007-11-28 16:21:06 -0800233 qr{struct\s+$Ident},
234 qr{union\s+$Ident},
235 qr{enum\s+$Ident},
236 qr{${Ident}_t},
237 qr{${Ident}_handler},
238 qr{${Ident}_handler_fn},
239);
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700240our @modifierList = (
241 qr{fastcall},
242);
Andy Whitcroft8905a672007-11-28 16:21:06 -0800243
Wolfram Sang7840a942010-08-09 17:20:57 -0700244our $allowed_asm_includes = qr{(?x:
245 irq|
246 memory
247)};
248# memory.h: ARM has a custom one
249
Andy Whitcroft8905a672007-11-28 16:21:06 -0800250sub build_types {
Andy Whitcroftd2172eb2008-07-23 21:29:07 -0700251 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
252 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
Andy Whitcroftc8cb2ca2008-07-23 21:28:57 -0700253 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
Andy Whitcroft8905a672007-11-28 16:21:06 -0800254 $NonptrType = qr{
Andy Whitcroftd2172eb2008-07-23 21:29:07 -0700255 (?:$Modifier\s+|const\s+)*
Andy Whitcroftcf655042008-03-04 14:28:20 -0800256 (?:
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700257 (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\)|
Andy Whitcroft8ed22ca2008-10-15 22:02:32 -0700258 (?:$typeTypedefs\b)|
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700259 (?:${all}\b)
Andy Whitcroftcf655042008-03-04 14:28:20 -0800260 )
Andy Whitcroftc8cb2ca2008-07-23 21:28:57 -0700261 (?:\s+$Modifier|\s+const)*
Andy Whitcroft8905a672007-11-28 16:21:06 -0800262 }x;
263 $Type = qr{
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700264 $NonptrType
Andy Whitcroft65863862009-01-06 14:41:21 -0800265 (?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)?
Andy Whitcroftc8cb2ca2008-07-23 21:28:57 -0700266 (?:\s+$Inline|\s+$Modifier)*
Andy Whitcroft8905a672007-11-28 16:21:06 -0800267 }x;
268 $Declare = qr{(?:$Storage\s+)?$Type};
269}
270build_types();
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700271
Joe Perches7d2367a2011-07-25 17:13:22 -0700272our $match_balanced_parentheses = qr/(\((?:[^\(\)]+|(-1))*\))/;
273
274our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
275our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s*};
276
277sub deparenthesize {
278 my ($string) = @_;
279 return "" if (!defined($string));
280 $string =~ s@^\s*\(\s*@@g;
281 $string =~ s@\s*\)\s*$@@g;
282 $string =~ s@\s+@ @g;
283 return $string;
284}
285
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700286$chk_signoff = 0 if ($file);
287
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700288my @dep_includes = ();
289my @dep_functions = ();
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700290my $removal = "Documentation/feature-removal-schedule.txt";
291if ($tree && -f "$root/$removal") {
Andy Whitcroft21caa132009-01-06 14:41:30 -0800292 open(my $REMOVE, '<', "$root/$removal") ||
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700293 die "$P: $removal: open failed - $!\n";
Andy Whitcroft21caa132009-01-06 14:41:30 -0800294 while (<$REMOVE>) {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700295 if (/^Check:\s+(.*\S)/) {
296 for my $entry (split(/[, ]+/, $1)) {
297 if ($entry =~ m@include/(.*)@) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700298 push(@dep_includes, $1);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700299
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700300 } elsif ($entry !~ m@/@) {
301 push(@dep_functions, $entry);
302 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700303 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700304 }
305 }
Andy Whitcroft21caa132009-01-06 14:41:30 -0800306 close($REMOVE);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700307}
308
Andy Whitcroft00df3442007-06-08 13:47:06 -0700309my @rawlines = ();
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800310my @lines = ();
311my $vname;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700312for my $filename (@ARGV) {
Andy Whitcroft21caa132009-01-06 14:41:30 -0800313 my $FILE;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700314 if ($file) {
Andy Whitcroft21caa132009-01-06 14:41:30 -0800315 open($FILE, '-|', "diff -u /dev/null $filename") ||
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700316 die "$P: $filename: diff failed - $!\n";
Andy Whitcroft21caa132009-01-06 14:41:30 -0800317 } elsif ($filename eq '-') {
318 open($FILE, '<&STDIN');
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700319 } else {
Andy Whitcroft21caa132009-01-06 14:41:30 -0800320 open($FILE, '<', "$filename") ||
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700321 die "$P: $filename: open failed - $!\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700322 }
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800323 if ($filename eq '-') {
324 $vname = 'Your patch';
325 } else {
326 $vname = $filename;
327 }
Andy Whitcroft21caa132009-01-06 14:41:30 -0800328 while (<$FILE>) {
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700329 chomp;
330 push(@rawlines, $_);
331 }
Andy Whitcroft21caa132009-01-06 14:41:30 -0800332 close($FILE);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800333 if (!process($filename)) {
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700334 $exit = 1;
335 }
336 @rawlines = ();
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800337 @lines = ();
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700338}
339
340exit($exit);
341
342sub top_of_kernel_tree {
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700343 my ($root) = @_;
344
345 my @tree_check = (
346 "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
347 "README", "Documentation", "arch", "include", "drivers",
348 "fs", "init", "ipc", "kernel", "lib", "scripts",
349 );
350
351 foreach my $check (@tree_check) {
352 if (! -e $root . '/' . $check) {
353 return 0;
354 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700355 }
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700356 return 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700357}
358
359sub expand_tabs {
360 my ($str) = @_;
361
362 my $res = '';
363 my $n = 0;
364 for my $c (split(//, $str)) {
365 if ($c eq "\t") {
366 $res .= ' ';
367 $n++;
368 for (; ($n % 8) != 0; $n++) {
369 $res .= ' ';
370 }
371 next;
372 }
373 $res .= $c;
374 $n++;
375 }
376
377 return $res;
378}
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700379sub copy_spacing {
Andy Whitcroft773647a2008-03-28 14:15:58 -0700380 (my $res = shift) =~ tr/\t/ /c;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700381 return $res;
382}
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700383
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700384sub line_stats {
385 my ($line) = @_;
386
387 # Drop the diff line leader and expand tabs
388 $line =~ s/^.//;
389 $line = expand_tabs($line);
390
391 # Pick the indent from the front of the line.
392 my ($white) = ($line =~ /^(\s*)/);
393
394 return (length($line), length($white));
395}
396
Andy Whitcroft773647a2008-03-28 14:15:58 -0700397my $sanitise_quote = '';
398
399sub sanitise_line_reset {
400 my ($in_comment) = @_;
401
402 if ($in_comment) {
403 $sanitise_quote = '*/';
404 } else {
405 $sanitise_quote = '';
406 }
407}
Andy Whitcroft00df3442007-06-08 13:47:06 -0700408sub sanitise_line {
409 my ($line) = @_;
410
411 my $res = '';
412 my $l = '';
413
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800414 my $qlen = 0;
Andy Whitcroft773647a2008-03-28 14:15:58 -0700415 my $off = 0;
416 my $c;
Andy Whitcroft00df3442007-06-08 13:47:06 -0700417
Andy Whitcroft773647a2008-03-28 14:15:58 -0700418 # Always copy over the diff marker.
419 $res = substr($line, 0, 1);
420
421 for ($off = 1; $off < length($line); $off++) {
422 $c = substr($line, $off, 1);
423
424 # Comments we are wacking completly including the begin
425 # and end, all to $;.
426 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
427 $sanitise_quote = '*/';
428
429 substr($res, $off, 2, "$;$;");
430 $off++;
431 next;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800432 }
Andy Whitcroft81bc0e02008-10-15 22:02:26 -0700433 if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
Andy Whitcroft773647a2008-03-28 14:15:58 -0700434 $sanitise_quote = '';
435 substr($res, $off, 2, "$;$;");
436 $off++;
437 next;
438 }
Daniel Walker113f04a2009-09-21 17:04:35 -0700439 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
440 $sanitise_quote = '//';
441
442 substr($res, $off, 2, $sanitise_quote);
443 $off++;
444 next;
445 }
Andy Whitcroft773647a2008-03-28 14:15:58 -0700446
447 # A \ in a string means ignore the next character.
448 if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
449 $c eq "\\") {
450 substr($res, $off, 2, 'XX');
451 $off++;
452 next;
453 }
454 # Regular quotes.
455 if ($c eq "'" || $c eq '"') {
456 if ($sanitise_quote eq '') {
457 $sanitise_quote = $c;
458
459 substr($res, $off, 1, $c);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700460 next;
Andy Whitcroft773647a2008-03-28 14:15:58 -0700461 } elsif ($sanitise_quote eq $c) {
462 $sanitise_quote = '';
Andy Whitcroft00df3442007-06-08 13:47:06 -0700463 }
464 }
Andy Whitcroft773647a2008-03-28 14:15:58 -0700465
Andy Whitcroftfae17da2009-01-06 14:41:20 -0800466 #print "c<$c> SQ<$sanitise_quote>\n";
Andy Whitcroft773647a2008-03-28 14:15:58 -0700467 if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
468 substr($res, $off, 1, $;);
Daniel Walker113f04a2009-09-21 17:04:35 -0700469 } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
470 substr($res, $off, 1, $;);
Andy Whitcroft773647a2008-03-28 14:15:58 -0700471 } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
472 substr($res, $off, 1, 'X');
Andy Whitcroft00df3442007-06-08 13:47:06 -0700473 } else {
Andy Whitcroft773647a2008-03-28 14:15:58 -0700474 substr($res, $off, 1, $c);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700475 }
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800476 }
477
Daniel Walker113f04a2009-09-21 17:04:35 -0700478 if ($sanitise_quote eq '//') {
479 $sanitise_quote = '';
480 }
481
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800482 # The pathname on a #include may be surrounded by '<' and '>'.
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700483 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800484 my $clean = 'X' x length($1);
485 $res =~ s@\<.*\>@<$clean>@;
486
487 # The whole of a #error is a string.
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700488 } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800489 my $clean = 'X' x length($1);
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700490 $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800491 }
492
Andy Whitcroft00df3442007-06-08 13:47:06 -0700493 return $res;
494}
495
Andy Whitcroft8905a672007-11-28 16:21:06 -0800496sub ctx_statement_block {
497 my ($linenr, $remain, $off) = @_;
498 my $line = $linenr - 1;
499 my $blk = '';
500 my $soff = $off;
501 my $coff = $off - 1;
Andy Whitcroft773647a2008-03-28 14:15:58 -0700502 my $coff_set = 0;
Andy Whitcroft8905a672007-11-28 16:21:06 -0800503
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800504 my $loff = 0;
505
Andy Whitcroft8905a672007-11-28 16:21:06 -0800506 my $type = '';
507 my $level = 0;
Andy Whitcrofta2750642009-01-15 13:51:04 -0800508 my @stack = ();
Andy Whitcroftcf655042008-03-04 14:28:20 -0800509 my $p;
Andy Whitcroft8905a672007-11-28 16:21:06 -0800510 my $c;
511 my $len = 0;
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800512
513 my $remainder;
Andy Whitcroft8905a672007-11-28 16:21:06 -0800514 while (1) {
Andy Whitcrofta2750642009-01-15 13:51:04 -0800515 @stack = (['', 0]) if ($#stack == -1);
516
Andy Whitcroft773647a2008-03-28 14:15:58 -0700517 #warn "CSB: blk<$blk> remain<$remain>\n";
Andy Whitcroft8905a672007-11-28 16:21:06 -0800518 # If we are about to drop off the end, pull in more
519 # context.
520 if ($off >= $len) {
521 for (; $remain > 0; $line++) {
Andy Whitcroftdea33492008-10-15 22:02:25 -0700522 last if (!defined $lines[$line]);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800523 next if ($lines[$line] =~ /^-/);
Andy Whitcroft8905a672007-11-28 16:21:06 -0800524 $remain--;
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800525 $loff = $len;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800526 $blk .= $lines[$line] . "\n";
Andy Whitcroft8905a672007-11-28 16:21:06 -0800527 $len = length($blk);
528 $line++;
529 last;
530 }
531 # Bail if there is no further context.
532 #warn "CSB: blk<$blk> off<$off> len<$len>\n";
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800533 if ($off >= $len) {
Andy Whitcroft8905a672007-11-28 16:21:06 -0800534 last;
535 }
536 }
Andy Whitcroftcf655042008-03-04 14:28:20 -0800537 $p = $c;
Andy Whitcroft8905a672007-11-28 16:21:06 -0800538 $c = substr($blk, $off, 1);
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800539 $remainder = substr($blk, $off);
Andy Whitcroft8905a672007-11-28 16:21:06 -0800540
Andy Whitcroft773647a2008-03-28 14:15:58 -0700541 #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
Andy Whitcroft4635f4f2009-01-06 14:41:27 -0800542
543 # Handle nested #if/#else.
544 if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
545 push(@stack, [ $type, $level ]);
546 } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
547 ($type, $level) = @{$stack[$#stack - 1]};
548 } elsif ($remainder =~ /^#\s*endif\b/) {
549 ($type, $level) = @{pop(@stack)};
550 }
551
Andy Whitcroft8905a672007-11-28 16:21:06 -0800552 # Statement ends at the ';' or a close '}' at the
553 # outermost level.
554 if ($level == 0 && $c eq ';') {
555 last;
556 }
557
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800558 # An else is really a conditional as long as its not else if
Andy Whitcroft773647a2008-03-28 14:15:58 -0700559 if ($level == 0 && $coff_set == 0 &&
560 (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
561 $remainder =~ /^(else)(?:\s|{)/ &&
562 $remainder !~ /^else\s+if\b/) {
563 $coff = $off + length($1) - 1;
564 $coff_set = 1;
565 #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
566 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800567 }
568
Andy Whitcroft8905a672007-11-28 16:21:06 -0800569 if (($type eq '' || $type eq '(') && $c eq '(') {
570 $level++;
571 $type = '(';
572 }
573 if ($type eq '(' && $c eq ')') {
574 $level--;
575 $type = ($level != 0)? '(' : '';
576
577 if ($level == 0 && $coff < $soff) {
578 $coff = $off;
Andy Whitcroft773647a2008-03-28 14:15:58 -0700579 $coff_set = 1;
580 #warn "CSB: mark coff<$coff>\n";
Andy Whitcroft8905a672007-11-28 16:21:06 -0800581 }
582 }
583 if (($type eq '' || $type eq '{') && $c eq '{') {
584 $level++;
585 $type = '{';
586 }
587 if ($type eq '{' && $c eq '}') {
588 $level--;
589 $type = ($level != 0)? '{' : '';
590
591 if ($level == 0) {
Patrick Pannutob998e002010-08-09 17:21:03 -0700592 if (substr($blk, $off + 1, 1) eq ';') {
593 $off++;
594 }
Andy Whitcroft8905a672007-11-28 16:21:06 -0800595 last;
596 }
597 }
598 $off++;
599 }
Andy Whitcrofta3bb97a2008-07-23 21:29:00 -0700600 # We are truly at the end, so shuffle to the next line.
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800601 if ($off == $len) {
Andy Whitcrofta3bb97a2008-07-23 21:29:00 -0700602 $loff = $len + 1;
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800603 $line++;
604 $remain--;
605 }
Andy Whitcroft8905a672007-11-28 16:21:06 -0800606
607 my $statement = substr($blk, $soff, $off - $soff + 1);
608 my $condition = substr($blk, $soff, $coff - $soff + 1);
609
610 #warn "STATEMENT<$statement>\n";
611 #warn "CONDITION<$condition>\n";
612
Andy Whitcroft773647a2008-03-28 14:15:58 -0700613 #print "coff<$coff> soff<$off> loff<$loff>\n";
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800614
615 return ($statement, $condition,
616 $line, $remain + 1, $off - $loff + 1, $level);
617}
618
Andy Whitcroftcf655042008-03-04 14:28:20 -0800619sub statement_lines {
620 my ($stmt) = @_;
621
622 # Strip the diff line prefixes and rip blank lines at start and end.
623 $stmt =~ s/(^|\n)./$1/g;
624 $stmt =~ s/^\s*//;
625 $stmt =~ s/\s*$//;
626
627 my @stmt_lines = ($stmt =~ /\n/g);
628
629 return $#stmt_lines + 2;
630}
631
632sub statement_rawlines {
633 my ($stmt) = @_;
634
635 my @stmt_lines = ($stmt =~ /\n/g);
636
637 return $#stmt_lines + 2;
638}
639
640sub statement_block_size {
641 my ($stmt) = @_;
642
643 $stmt =~ s/(^|\n)./$1/g;
644 $stmt =~ s/^\s*{//;
645 $stmt =~ s/}\s*$//;
646 $stmt =~ s/^\s*//;
647 $stmt =~ s/\s*$//;
648
649 my @stmt_lines = ($stmt =~ /\n/g);
650 my @stmt_statements = ($stmt =~ /;/g);
651
652 my $stmt_lines = $#stmt_lines + 2;
653 my $stmt_statements = $#stmt_statements + 1;
654
655 if ($stmt_lines > $stmt_statements) {
656 return $stmt_lines;
657 } else {
658 return $stmt_statements;
659 }
660}
661
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800662sub ctx_statement_full {
663 my ($linenr, $remain, $off) = @_;
664 my ($statement, $condition, $level);
665
666 my (@chunks);
667
Andy Whitcroftcf655042008-03-04 14:28:20 -0800668 # Grab the first conditional/block pair.
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800669 ($statement, $condition, $linenr, $remain, $off, $level) =
670 ctx_statement_block($linenr, $remain, $off);
Andy Whitcroft773647a2008-03-28 14:15:58 -0700671 #print "F: c<$condition> s<$statement> remain<$remain>\n";
Andy Whitcroftcf655042008-03-04 14:28:20 -0800672 push(@chunks, [ $condition, $statement ]);
673 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
674 return ($level, $linenr, @chunks);
675 }
676
677 # Pull in the following conditional/block pairs and see if they
678 # could continue the statement.
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800679 for (;;) {
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800680 ($statement, $condition, $linenr, $remain, $off, $level) =
681 ctx_statement_block($linenr, $remain, $off);
Andy Whitcroftcf655042008-03-04 14:28:20 -0800682 #print "C: c<$condition> s<$statement> remain<$remain>\n";
Andy Whitcroft773647a2008-03-28 14:15:58 -0700683 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
Andy Whitcroftcf655042008-03-04 14:28:20 -0800684 #print "C: push\n";
685 push(@chunks, [ $condition, $statement ]);
Andy Whitcroft13214ad2008-02-08 04:22:03 -0800686 }
687
688 return ($level, $linenr, @chunks);
Andy Whitcroft8905a672007-11-28 16:21:06 -0800689}
690
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700691sub ctx_block_get {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700692 my ($linenr, $remain, $outer, $open, $close, $off) = @_;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700693 my $line;
694 my $start = $linenr - 1;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700695 my $blk = '';
696 my @o;
697 my @c;
698 my @res = ();
699
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700700 my $level = 0;
Andy Whitcroft4635f4f2009-01-06 14:41:27 -0800701 my @stack = ($level);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700702 for ($line = $start; $remain > 0; $line++) {
703 next if ($rawlines[$line] =~ /^-/);
704 $remain--;
705
706 $blk .= $rawlines[$line];
Andy Whitcroft4635f4f2009-01-06 14:41:27 -0800707
708 # Handle nested #if/#else.
Andy Whitcroft01464f32010-10-26 14:23:19 -0700709 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
Andy Whitcroft4635f4f2009-01-06 14:41:27 -0800710 push(@stack, $level);
Andy Whitcroft01464f32010-10-26 14:23:19 -0700711 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
Andy Whitcroft4635f4f2009-01-06 14:41:27 -0800712 $level = $stack[$#stack - 1];
Andy Whitcroft01464f32010-10-26 14:23:19 -0700713 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
Andy Whitcroft4635f4f2009-01-06 14:41:27 -0800714 $level = pop(@stack);
715 }
716
Andy Whitcroft01464f32010-10-26 14:23:19 -0700717 foreach my $c (split(//, $lines[$line])) {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700718 ##print "C<$c>L<$level><$open$close>O<$off>\n";
719 if ($off > 0) {
720 $off--;
721 next;
722 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700723
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700724 if ($c eq $close && $level > 0) {
725 $level--;
726 last if ($level == 0);
727 } elsif ($c eq $open) {
728 $level++;
729 }
730 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700731
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700732 if (!$outer || $level <= 1) {
Andy Whitcroft00df3442007-06-08 13:47:06 -0700733 push(@res, $rawlines[$line]);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700734 }
735
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700736 last if ($level == 0);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700737 }
738
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700739 return ($level, @res);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700740}
741sub ctx_block_outer {
742 my ($linenr, $remain) = @_;
743
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700744 my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
745 return @r;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700746}
747sub ctx_block {
748 my ($linenr, $remain) = @_;
749
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700750 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
751 return @r;
Andy Whitcroft653d4872007-06-23 17:16:34 -0700752}
753sub ctx_statement {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700754 my ($linenr, $remain, $off) = @_;
755
756 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
757 return @r;
758}
759sub ctx_block_level {
Andy Whitcroft653d4872007-06-23 17:16:34 -0700760 my ($linenr, $remain) = @_;
761
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700762 return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700763}
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700764sub ctx_statement_level {
765 my ($linenr, $remain, $off) = @_;
766
767 return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
768}
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700769
770sub ctx_locate_comment {
771 my ($first_line, $end_line) = @_;
772
773 # Catch a comment on the end of the line itself.
Andy Whitcroftbeae6332008-07-23 21:28:59 -0700774 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700775 return $current_comment if (defined $current_comment);
776
777 # Look through the context and try and figure out if there is a
778 # comment.
779 my $in_comment = 0;
780 $current_comment = '';
781 for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
Andy Whitcroft00df3442007-06-08 13:47:06 -0700782 my $line = $rawlines[$linenr - 1];
783 #warn " $line\n";
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700784 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
785 $in_comment = 1;
786 }
787 if ($line =~ m@/\*@) {
788 $in_comment = 1;
789 }
790 if (!$in_comment && $current_comment ne '') {
791 $current_comment = '';
792 }
793 $current_comment .= $line . "\n" if ($in_comment);
794 if ($line =~ m@\*/@) {
795 $in_comment = 0;
796 }
797 }
798
799 chomp($current_comment);
800 return($current_comment);
801}
802sub ctx_has_comment {
803 my ($first_line, $end_line) = @_;
804 my $cmt = ctx_locate_comment($first_line, $end_line);
805
Andy Whitcroft00df3442007-06-08 13:47:06 -0700806 ##print "LINE: $rawlines[$end_line - 1 ]\n";
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700807 ##print "CMMT: $cmt\n";
808
809 return ($cmt ne '');
810}
811
Andy Whitcroft4d001e42008-10-15 22:02:21 -0700812sub raw_line {
813 my ($linenr, $cnt) = @_;
814
815 my $offset = $linenr - 1;
816 $cnt++;
817
818 my $line;
819 while ($cnt) {
820 $line = $rawlines[$offset++];
821 next if (defined($line) && $line =~ /^-/);
822 $cnt--;
823 }
824
825 return $line;
826}
827
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700828sub cat_vet {
829 my ($vet) = @_;
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700830 my ($res, $coded);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700831
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700832 $res = '';
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700833 while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
834 $res .= $1;
835 if ($2 ne '') {
836 $coded = sprintf("^%c", unpack('C', $2) + 64);
837 $res .= $coded;
838 }
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700839 }
840 $res =~ s/$/\$/;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700841
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700842 return $res;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700843}
844
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800845my $av_preprocessor = 0;
Andy Whitcroftcf655042008-03-04 14:28:20 -0800846my $av_pending;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800847my @av_paren_type;
Andy Whitcroft1f65f942008-07-23 21:29:10 -0700848my $av_pend_colon;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800849
850sub annotate_reset {
851 $av_preprocessor = 0;
Andy Whitcroftcf655042008-03-04 14:28:20 -0800852 $av_pending = '_';
853 @av_paren_type = ('E');
Andy Whitcroft1f65f942008-07-23 21:29:10 -0700854 $av_pend_colon = 'O';
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800855}
856
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700857sub annotate_values {
858 my ($stream, $type) = @_;
859
860 my $res;
Andy Whitcroft1f65f942008-07-23 21:29:10 -0700861 my $var = '_' x length($stream);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700862 my $cur = $stream;
863
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800864 print "$stream\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700865
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700866 while (length($cur)) {
Andy Whitcroft773647a2008-03-28 14:15:58 -0700867 @av_paren_type = ('E') if ($#av_paren_type < 0);
Andy Whitcroftcf655042008-03-04 14:28:20 -0800868 print " <" . join('', @av_paren_type) .
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700869 "> <$type> <$av_pending>" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700870 if ($cur =~ /^(\s+)/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800871 print "WS($1)\n" if ($dbg_values > 1);
872 if ($1 =~ /\n/ && $av_preprocessor) {
Andy Whitcroftcf655042008-03-04 14:28:20 -0800873 $type = pop(@av_paren_type);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800874 $av_preprocessor = 0;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700875 }
876
Florian Micklerc023e4732011-01-12 16:59:58 -0800877 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
Andy Whitcroft9446ef52010-10-26 14:23:13 -0700878 print "CAST($1)\n" if ($dbg_values > 1);
879 push(@av_paren_type, $type);
880 $type = 'C';
881
Andy Whitcrofte91b6e22010-10-26 14:23:11 -0700882 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800883 print "DECLARE($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700884 $type = 'T';
885
Andy Whitcroft389a2fe2008-07-23 21:29:05 -0700886 } elsif ($cur =~ /^($Modifier)\s*/) {
887 print "MODIFIER($1)\n" if ($dbg_values > 1);
888 $type = 'T';
889
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700890 } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700891 print "DEFINE($1,$2)\n" if ($dbg_values > 1);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800892 $av_preprocessor = 1;
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700893 push(@av_paren_type, $type);
894 if ($2 ne '') {
895 $av_pending = 'N';
896 }
897 $type = 'E';
898
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700899 } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700900 print "UNDEF($1)\n" if ($dbg_values > 1);
901 $av_preprocessor = 1;
902 push(@av_paren_type, $type);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700903
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700904 } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
Andy Whitcroftcf655042008-03-04 14:28:20 -0800905 print "PRE_START($1)\n" if ($dbg_values > 1);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800906 $av_preprocessor = 1;
Andy Whitcroftcf655042008-03-04 14:28:20 -0800907
908 push(@av_paren_type, $type);
909 push(@av_paren_type, $type);
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700910 $type = 'E';
Andy Whitcroftcf655042008-03-04 14:28:20 -0800911
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700912 } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
Andy Whitcroftcf655042008-03-04 14:28:20 -0800913 print "PRE_RESTART($1)\n" if ($dbg_values > 1);
914 $av_preprocessor = 1;
915
916 push(@av_paren_type, $av_paren_type[$#av_paren_type]);
917
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700918 $type = 'E';
Andy Whitcroftcf655042008-03-04 14:28:20 -0800919
Andy Whitcroftc45dcab2008-06-05 22:46:01 -0700920 } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
Andy Whitcroftcf655042008-03-04 14:28:20 -0800921 print "PRE_END($1)\n" if ($dbg_values > 1);
922
923 $av_preprocessor = 1;
924
925 # Assume all arms of the conditional end as this
926 # one does, and continue as if the #endif was not here.
927 pop(@av_paren_type);
928 push(@av_paren_type, $type);
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700929 $type = 'E';
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700930
931 } elsif ($cur =~ /^(\\\n)/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800932 print "PRECONT($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700933
Andy Whitcroft171ae1a2008-04-29 00:59:32 -0700934 } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
935 print "ATTR($1)\n" if ($dbg_values > 1);
936 $av_pending = $type;
937 $type = 'N';
938
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700939 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800940 print "SIZEOF($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700941 if (defined $2) {
Andy Whitcroftcf655042008-03-04 14:28:20 -0800942 $av_pending = 'V';
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700943 }
944 $type = 'N';
945
Andy Whitcroft14b111c2008-10-15 22:02:16 -0700946 } elsif ($cur =~ /^(if|while|for)\b/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800947 print "COND($1)\n" if ($dbg_values > 1);
Andy Whitcroft14b111c2008-10-15 22:02:16 -0700948 $av_pending = 'E';
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700949 $type = 'N';
950
Andy Whitcroft1f65f942008-07-23 21:29:10 -0700951 } elsif ($cur =~/^(case)/o) {
952 print "CASE($1)\n" if ($dbg_values > 1);
953 $av_pend_colon = 'C';
954 $type = 'N';
955
Andy Whitcroft14b111c2008-10-15 22:02:16 -0700956 } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800957 print "KEYWORD($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700958 $type = 'N';
959
960 } elsif ($cur =~ /^(\()/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800961 print "PAREN('$1')\n" if ($dbg_values > 1);
Andy Whitcroftcf655042008-03-04 14:28:20 -0800962 push(@av_paren_type, $av_pending);
963 $av_pending = '_';
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700964 $type = 'N';
965
966 } elsif ($cur =~ /^(\))/o) {
Andy Whitcroftcf655042008-03-04 14:28:20 -0800967 my $new_type = pop(@av_paren_type);
968 if ($new_type ne '_') {
969 $type = $new_type;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800970 print "PAREN('$1') -> $type\n"
971 if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700972 } else {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800973 print "PAREN('$1')\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700974 }
975
Andy Whitcroftc8cb2ca2008-07-23 21:28:57 -0700976 } elsif ($cur =~ /^($Ident)\s*\(/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800977 print "FUNC($1)\n" if ($dbg_values > 1);
Andy Whitcroftc8cb2ca2008-07-23 21:28:57 -0700978 $type = 'V';
Andy Whitcroftcf655042008-03-04 14:28:20 -0800979 $av_pending = 'V';
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700980
Andy Whitcroft8e761b02009-01-06 14:41:19 -0800981 } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
982 if (defined $2 && $type eq 'C' || $type eq 'T') {
Andy Whitcroft1f65f942008-07-23 21:29:10 -0700983 $av_pend_colon = 'B';
Andy Whitcroft8e761b02009-01-06 14:41:19 -0800984 } elsif ($type eq 'E') {
985 $av_pend_colon = 'L';
Andy Whitcroft1f65f942008-07-23 21:29:10 -0700986 }
987 print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
988 $type = 'V';
989
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700990 } elsif ($cur =~ /^($Ident|$Constant)/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800991 print "IDENT($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700992 $type = 'V';
993
994 } elsif ($cur =~ /^($Assignment)/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800995 print "ASSIGN($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -0700996 $type = 'N';
997
Andy Whitcroftcf655042008-03-04 14:28:20 -0800998 } elsif ($cur =~/^(;|{|})/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -0800999 print "END($1)\n" if ($dbg_values > 1);
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001000 $type = 'E';
Andy Whitcroft1f65f942008-07-23 21:29:10 -07001001 $av_pend_colon = 'O';
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001002
Andy Whitcroft8e761b02009-01-06 14:41:19 -08001003 } elsif ($cur =~/^(,)/) {
1004 print "COMMA($1)\n" if ($dbg_values > 1);
1005 $type = 'C';
1006
Andy Whitcroft1f65f942008-07-23 21:29:10 -07001007 } elsif ($cur =~ /^(\?)/o) {
1008 print "QUESTION($1)\n" if ($dbg_values > 1);
1009 $type = 'N';
1010
1011 } elsif ($cur =~ /^(:)/o) {
1012 print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
1013
1014 substr($var, length($res), 1, $av_pend_colon);
1015 if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
1016 $type = 'E';
1017 } else {
1018 $type = 'N';
1019 }
1020 $av_pend_colon = 'O';
1021
Andy Whitcroft8e761b02009-01-06 14:41:19 -08001022 } elsif ($cur =~ /^(\[)/o) {
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001023 print "CLOSE($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001024 $type = 'N';
1025
Andy Whitcroft0d413862008-10-15 22:02:16 -07001026 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
Andy Whitcroft74048ed2008-07-23 21:29:10 -07001027 my $variant;
1028
1029 print "OPV($1)\n" if ($dbg_values > 1);
1030 if ($type eq 'V') {
1031 $variant = 'B';
1032 } else {
1033 $variant = 'U';
1034 }
1035
1036 substr($var, length($res), 1, $variant);
1037 $type = 'N';
1038
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001039 } elsif ($cur =~ /^($Operators)/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001040 print "OP($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001041 if ($1 ne '++' && $1 ne '--') {
1042 $type = 'N';
1043 }
1044
1045 } elsif ($cur =~ /(^.)/o) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001046 print "C($1)\n" if ($dbg_values > 1);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001047 }
1048 if (defined $1) {
1049 $cur = substr($cur, length($1));
1050 $res .= $type x length($1);
1051 }
1052 }
1053
Andy Whitcroft1f65f942008-07-23 21:29:10 -07001054 return ($res, $var);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001055}
1056
Andy Whitcroft8905a672007-11-28 16:21:06 -08001057sub possible {
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001058 my ($possible, $line) = @_;
Andy Whitcroft9a974fd2009-10-26 16:50:12 -07001059 my $notPermitted = qr{(?:
Andy Whitcroft0776e592008-10-15 22:02:29 -07001060 ^(?:
1061 $Modifier|
1062 $Storage|
1063 $Type|
Andy Whitcroft9a974fd2009-10-26 16:50:12 -07001064 DEFINE_\S+
1065 )$|
1066 ^(?:
Andy Whitcroft0776e592008-10-15 22:02:29 -07001067 goto|
1068 return|
1069 case|
1070 else|
1071 asm|__asm__|
1072 do
Andy Whitcroft9a974fd2009-10-26 16:50:12 -07001073 )(?:\s|$)|
Andy Whitcroft0776e592008-10-15 22:02:29 -07001074 ^(?:typedef|struct|enum)\b
Andy Whitcroft9a974fd2009-10-26 16:50:12 -07001075 )}x;
1076 warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
1077 if ($possible !~ $notPermitted) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001078 # Check for modifiers.
1079 $possible =~ s/\s*$Storage\s*//g;
1080 $possible =~ s/\s*$Sparse\s*//g;
1081 if ($possible =~ /^\s*$/) {
1082
1083 } elsif ($possible =~ /\s/) {
1084 $possible =~ s/\s*$Type\s*//g;
Andy Whitcroftd2506582008-07-23 21:29:09 -07001085 for my $modifier (split(' ', $possible)) {
Andy Whitcroft9a974fd2009-10-26 16:50:12 -07001086 if ($modifier !~ $notPermitted) {
1087 warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
1088 push(@modifierList, $modifier);
1089 }
Andy Whitcroftd2506582008-07-23 21:29:09 -07001090 }
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001091
1092 } else {
1093 warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
1094 push(@typeList, $possible);
1095 }
Andy Whitcroft8905a672007-11-28 16:21:06 -08001096 build_types();
Andy Whitcroft0776e592008-10-15 22:02:29 -07001097 } else {
1098 warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
Andy Whitcroft8905a672007-11-28 16:21:06 -08001099 }
1100}
1101
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001102my $prefix = '';
1103
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001104sub report {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001105 if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) {
1106 return 0;
1107 }
Andy Whitcroft8905a672007-11-28 16:21:06 -08001108 my $line = $prefix . $_[0];
1109
1110 $line = (split('\n', $line))[0] . "\n" if ($terse);
1111
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001112 push(our @report, $line);
Andy Whitcroft773647a2008-03-28 14:15:58 -07001113
1114 return 1;
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001115}
1116sub report_dump {
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001117 our @report;
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001118}
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001119sub ERROR {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001120 if (report("ERROR: $_[0]\n")) {
1121 our $clean = 0;
1122 our $cnt_error++;
1123 }
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001124}
1125sub WARN {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001126 if (report("WARNING: $_[0]\n")) {
1127 our $clean = 0;
1128 our $cnt_warn++;
1129 }
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001130}
1131sub CHK {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001132 if ($check && report("CHECK: $_[0]\n")) {
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001133 our $clean = 0;
1134 our $cnt_chk++;
1135 }
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001136}
1137
Andy Whitcroft6ecd9672008-10-15 22:02:21 -07001138sub check_absolute_file {
1139 my ($absolute, $herecurr) = @_;
1140 my $file = $absolute;
1141
1142 ##print "absolute<$absolute>\n";
1143
1144 # See if any suffix of this path is a path within the tree.
1145 while ($file =~ s@^[^/]*/@@) {
1146 if (-f "$root/$file") {
1147 ##print "file<$file>\n";
1148 last;
1149 }
1150 }
1151 if (! -f _) {
1152 return 0;
1153 }
1154
1155 # It is, so see if the prefix is acceptable.
1156 my $prefix = $absolute;
1157 substr($prefix, -length($file)) = '';
1158
1159 ##print "prefix<$prefix>\n";
1160 if ($prefix ne ".../") {
1161 WARN("use relative pathname instead of absolute in changelog text\n" . $herecurr);
1162 }
1163}
1164
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001165sub process {
1166 my $filename = shift;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001167
1168 my $linenr=0;
1169 my $prevline="";
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001170 my $prevrawline="";
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001171 my $stashline="";
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001172 my $stashrawline="";
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001173
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001174 my $length;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001175 my $indent;
1176 my $previndent=0;
1177 my $stashindent=0;
1178
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001179 our $clean = 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001180 my $signoff = 0;
1181 my $is_patch = 0;
1182
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001183 our @report = ();
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001184 our $cnt_lines = 0;
1185 our $cnt_error = 0;
1186 our $cnt_warn = 0;
1187 our $cnt_chk = 0;
1188
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001189 # Trace the real file/line as we go.
1190 my $realfile = '';
1191 my $realline = 0;
1192 my $realcnt = 0;
1193 my $here = '';
1194 my $in_comment = 0;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001195 my $comment_edge = 0;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001196 my $first_line = 0;
Wolfram Sang1e855722009-01-06 14:41:24 -08001197 my $p1_prefix = '';
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001198
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001199 my $prev_values = 'E';
1200
1201 # suppression flags
Andy Whitcroft773647a2008-03-28 14:15:58 -07001202 my %suppress_ifbraces;
Andy Whitcroft170d3a22008-10-15 22:02:30 -07001203 my %suppress_whiletrailers;
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001204 my %suppress_export;
Andy Whitcroft653d4872007-06-23 17:16:34 -07001205
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001206 # Pre-scan the patch sanitizing the lines.
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001207 # Pre-scan the patch looking for any __setup documentation.
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001208 #
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001209 my @setup_docs = ();
1210 my $setup_docs = 0;
Andy Whitcroft773647a2008-03-28 14:15:58 -07001211
1212 sanitise_line_reset();
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001213 my $line;
1214 foreach my $rawline (@rawlines) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001215 $linenr++;
1216 $line = $rawline;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001217
Andy Whitcroft773647a2008-03-28 14:15:58 -07001218 if ($rawline=~/^\+\+\+\s+(\S+)/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001219 $setup_docs = 0;
1220 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
1221 $setup_docs = 1;
1222 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07001223 #next;
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001224 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07001225 if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
1226 $realline=$1-1;
1227 if (defined $2) {
1228 $realcnt=$3+1;
1229 } else {
1230 $realcnt=1+1;
1231 }
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001232 $in_comment = 0;
Andy Whitcroft773647a2008-03-28 14:15:58 -07001233
1234 # Guestimate if this is a continuing comment. Run
1235 # the context looking for a comment "edge". If this
1236 # edge is a close comment then we must be in a comment
1237 # at context start.
1238 my $edge;
Andy Whitcroft01fa9142008-10-15 22:02:19 -07001239 my $cnt = $realcnt;
1240 for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
1241 next if (defined $rawlines[$ln - 1] &&
1242 $rawlines[$ln - 1] =~ /^-/);
1243 $cnt--;
1244 #print "RAW<$rawlines[$ln - 1]>\n";
Andy Whitcroft721c1cb2009-01-06 14:41:16 -08001245 last if (!defined $rawlines[$ln - 1]);
Andy Whitcroftfae17da2009-01-06 14:41:20 -08001246 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
1247 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
1248 ($edge) = $1;
1249 last;
1250 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07001251 }
1252 if (defined $edge && $edge eq '*/') {
1253 $in_comment = 1;
1254 }
1255
1256 # Guestimate if this is a continuing comment. If this
1257 # is the start of a diff block and this line starts
1258 # ' *' then it is very likely a comment.
1259 if (!defined $edge &&
Andy Whitcroft83242e02009-01-06 14:41:17 -08001260 $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
Andy Whitcroft773647a2008-03-28 14:15:58 -07001261 {
1262 $in_comment = 1;
1263 }
1264
1265 ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
1266 sanitise_line_reset($in_comment);
1267
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001268 } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001269 # Standardise the strings and chars within the input to
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001270 # simplify matching -- only bother with positive lines.
Andy Whitcroft773647a2008-03-28 14:15:58 -07001271 $line = sanitise_line($rawline);
1272 }
1273 push(@lines, $line);
1274
1275 if ($realcnt > 1) {
1276 $realcnt-- if ($line =~ /^(?:\+| |$)/);
1277 } else {
1278 $realcnt = 0;
1279 }
1280
1281 #print "==>$rawline\n";
1282 #print "-->$line\n";
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001283
1284 if ($setup_docs && $line =~ /^\+/) {
1285 push(@setup_docs, $line);
1286 }
1287 }
1288
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001289 $prefix = '';
1290
Andy Whitcroft773647a2008-03-28 14:15:58 -07001291 $realcnt = 0;
1292 $linenr = 0;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001293 foreach my $line (@lines) {
1294 $linenr++;
1295
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001296 my $rawline = $rawlines[$linenr - 1];
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001297
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001298#extract the line range in the file after the patch is applied
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001299 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001300 $is_patch = 1;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001301 $first_line = $linenr + 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001302 $realline=$1-1;
1303 if (defined $2) {
1304 $realcnt=$3+1;
1305 } else {
1306 $realcnt=1+1;
1307 }
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001308 annotate_reset();
Andy Whitcroft13214ad2008-02-08 04:22:03 -08001309 $prev_values = 'E';
1310
Andy Whitcroft773647a2008-03-28 14:15:58 -07001311 %suppress_ifbraces = ();
Andy Whitcroft170d3a22008-10-15 22:02:30 -07001312 %suppress_whiletrailers = ();
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001313 %suppress_export = ();
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001314 next;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001315
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001316# track the line number as we move through the hunk, note that
1317# new versions of GNU diff omit the leading space on completely
1318# blank context lines so we need to count that too.
Andy Whitcroft773647a2008-03-28 14:15:58 -07001319 } elsif ($line =~ /^( |\+|$)/) {
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001320 $realline++;
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001321 $realcnt-- if ($realcnt != 0);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001322
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001323 # Measure the line length and indent.
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001324 ($length, $indent) = line_stats($rawline);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001325
1326 # Track the previous line.
1327 ($prevline, $stashline) = ($stashline, $line);
1328 ($previndent, $stashindent) = ($stashindent, $indent);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001329 ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
1330
Andy Whitcroft773647a2008-03-28 14:15:58 -07001331 #warn "line<$line>\n";
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001332
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001333 } elsif ($realcnt == 1) {
1334 $realcnt--;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001335 }
1336
Andy Whitcroftcc77cdc2009-10-26 16:50:13 -07001337 my $hunk_line = ($realcnt != 0);
1338
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001339#make up the handle for any error we report on this line
Andy Whitcroft773647a2008-03-28 14:15:58 -07001340 $prefix = "$filename:$realline: " if ($emacs && $file);
1341 $prefix = "$filename:$linenr: " if ($emacs && !$file);
1342
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001343 $here = "#$linenr: " if (!$file);
1344 $here = "#$realline: " if ($file);
Andy Whitcroft773647a2008-03-28 14:15:58 -07001345
1346 # extract the filename as it passes
Rabin Vincent3bf9a002010-10-26 14:23:16 -07001347 if ($line =~ /^diff --git.*?(\S+)$/) {
1348 $realfile = $1;
1349 $realfile =~ s@^([^/]*)/@@;
1350
1351 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001352 $realfile = $1;
Wolfram Sang1e855722009-01-06 14:41:24 -08001353 $realfile =~ s@^([^/]*)/@@;
1354
1355 $p1_prefix = $1;
Andy Whitcrofte2f7aa42009-02-27 14:03:06 -08001356 if (!$file && $tree && $p1_prefix ne '' &&
1357 -e "$root/$p1_prefix") {
Wolfram Sang1e855722009-01-06 14:41:24 -08001358 WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
1359 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07001360
Andy Whitcroftc1ab3322008-10-15 22:02:20 -07001361 if ($realfile =~ m@^include/asm/@) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001362 ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
1363 }
1364 next;
1365 }
1366
Randy Dunlap389834b2007-06-08 13:47:03 -07001367 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001368
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001369 my $hereline = "$here\n$rawline\n";
1370 my $herecurr = "$here\n$rawline\n";
1371 my $hereprev = "$here\n$prevrawline\n$rawline\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001372
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001373 $cnt_lines++ if ($realcnt != 0);
1374
Rabin Vincent3bf9a002010-10-26 14:23:16 -07001375# Check for incorrect file permissions
1376 if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
1377 my $permhere = $here . "FILE: $realfile\n";
1378 if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
1379 ERROR("do not set execute permissions for source files\n" . $permhere);
1380 }
1381 }
1382
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001383#check the patch for a signoff:
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001384 if ($line =~ /^\s*signed-off-by:/i) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001385 # This is a signoff, if ugly, so do not double report.
1386 $signoff++;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001387 if (!($line =~ /^\s*Signed-off-by:/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001388 WARN("Signed-off-by: is the preferred form\n" .
1389 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001390 }
1391 if ($line =~ /^\s*signed-off-by:\S/i) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001392 WARN("space required after Signed-off-by:\n" .
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001393 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001394 }
1395 }
1396
Andy Whitcroft00df3442007-06-08 13:47:06 -07001397# Check for wrappage within a valid hunk of the file
Andy Whitcroft8905a672007-11-28 16:21:06 -08001398 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001399 ERROR("patch seems to be corrupt (line wrapped?)\n" .
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001400 $herecurr) if (!$emitted_corrupt++);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001401 }
1402
Andy Whitcroft6ecd9672008-10-15 22:02:21 -07001403# Check for absolute kernel paths.
1404 if ($tree) {
1405 while ($line =~ m{(?:^|\s)(/\S*)}g) {
1406 my $file = $1;
1407
1408 if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
1409 check_absolute_file($1, $herecurr)) {
1410 #
1411 } else {
1412 check_absolute_file($file, $herecurr);
1413 }
1414 }
1415 }
1416
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001417# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
1418 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001419 $rawline !~ m/^$UTF8*$/) {
1420 my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
1421
1422 my $blank = copy_spacing($rawline);
1423 my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
1424 my $hereptr = "$hereline$ptr\n";
1425
1426 ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
Andy Whitcroft00df3442007-06-08 13:47:06 -07001427 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001428
Andy Whitcroft306708542008-10-15 22:02:28 -07001429# ignore non-hunk lines and lines being removed
1430 next if (!$hunk_line || $line =~ /^-/);
Andy Whitcroft00df3442007-06-08 13:47:06 -07001431
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001432#trailing whitespace
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001433 if ($line =~ /^\+.*\015/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001434 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001435 ERROR("DOS line endings\n" . $herevet);
1436
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001437 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1438 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001439 ERROR("trailing whitespace\n" . $herevet);
Andy Whitcroftd2c0a232010-10-26 14:23:12 -07001440 $rpt_cleaners = 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001441 }
Andy Whitcroft5368df22008-10-15 22:02:27 -07001442
Andi Kleen33549572010-05-24 14:33:29 -07001443# check for Kconfig help text having a real description
Andy Whitcroft9fe287d72010-10-26 14:23:15 -07001444# Only applies when adding the entry originally, after that we do not have
1445# sufficient context to determine whether it is indeed long enough.
Andi Kleen33549572010-05-24 14:33:29 -07001446 if ($realfile =~ /Kconfig/ &&
Andy Whitcroft9fe287d72010-10-26 14:23:15 -07001447 $line =~ /\+\s*(?:---)?help(?:---)?$/) {
Andi Kleen33549572010-05-24 14:33:29 -07001448 my $length = 0;
Andy Whitcroft9fe287d72010-10-26 14:23:15 -07001449 my $cnt = $realcnt;
1450 my $ln = $linenr + 1;
1451 my $f;
1452 my $is_end = 0;
1453 while ($cnt > 0 && defined $lines[$ln - 1]) {
1454 $f = $lines[$ln - 1];
1455 $cnt-- if ($lines[$ln - 1] !~ /^-/);
1456 $is_end = $lines[$ln - 1] =~ /^\+/;
1457 $ln++;
1458
1459 next if ($f =~ /^-/);
1460 $f =~ s/^.//;
Andi Kleen33549572010-05-24 14:33:29 -07001461 $f =~ s/#.*//;
1462 $f =~ s/^\s+//;
1463 next if ($f =~ /^$/);
Andy Whitcroft9fe287d72010-10-26 14:23:15 -07001464 if ($f =~ /^\s*config\s/) {
1465 $is_end = 1;
1466 last;
1467 }
Andi Kleen33549572010-05-24 14:33:29 -07001468 $length++;
1469 }
Andy Whitcroft9fe287d72010-10-26 14:23:15 -07001470 WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4);
1471 #print "is_end<$is_end> length<$length>\n";
Andi Kleen33549572010-05-24 14:33:29 -07001472 }
1473
Andy Whitcroft5368df22008-10-15 22:02:27 -07001474# check we are in a valid source file if not then ignore this hunk
1475 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
1476
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001477#80 column limit
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001478 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
Andy Whitcroftf4c014c2008-07-23 21:29:01 -07001479 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
Joe Perches0fccc622011-05-24 17:13:41 -07001480 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
Joe Perches8bbea962010-08-09 17:21:01 -07001481 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
Andy Whitcroftf4c014c2008-07-23 21:29:01 -07001482 $length > 80)
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001483 {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001484 WARN("line over 80 characters\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001485 }
1486
Joe Perches5e79d962010-03-05 13:43:55 -08001487# check for spaces before a quoted newline
1488 if ($rawline =~ /^.*\".*\s\\n/) {
1489 WARN("unnecessary whitespace before a quoted newline\n" . $herecurr);
1490 }
1491
Andy Whitcroft8905a672007-11-28 16:21:06 -08001492# check for adding lines without a newline.
1493 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
1494 WARN("adding a line without newline at end of file\n" . $herecurr);
1495 }
1496
Mike Frysinger42e41c52009-09-21 17:04:40 -07001497# Blackfin: use hi/lo macros
1498 if ($realfile =~ m@arch/blackfin/.*\.S$@) {
1499 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
1500 my $herevet = "$here\n" . cat_vet($line) . "\n";
1501 ERROR("use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
1502 }
1503 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
1504 my $herevet = "$here\n" . cat_vet($line) . "\n";
1505 ERROR("use the HI() macro, not (... >> 16)\n" . $herevet);
1506 }
1507 }
1508
Andy Whitcroftb9ea10d2008-10-15 22:02:24 -07001509# check we are in a valid source file C or perl if not then ignore this hunk
1510 next if ($realfile !~ /\.(h|c|pl)$/);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001511
1512# at the beginning of a line any tabs must come first and anything
1513# more than 8 must use tabs.
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001514 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1515 $rawline =~ /^\+\s* \s*/) {
1516 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001517 ERROR("code indent should use tabs where possible\n" . $herevet);
Andy Whitcroftd2c0a232010-10-26 14:23:12 -07001518 $rpt_cleaners = 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001519 }
1520
Alberto Panizzo08e44362010-03-05 13:43:54 -08001521# check for space before tabs.
1522 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1523 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1524 WARN("please, no space before tabs\n" . $herevet);
1525 }
1526
Raffaele Recalcati5f7ddae2010-08-09 17:20:59 -07001527# check for spaces at the beginning of a line.
Andy Whitcroft6b4c5be2010-10-26 14:23:11 -07001528# Exceptions:
1529# 1) within comments
1530# 2) indented preprocessor commands
1531# 3) hanging labels
1532 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
Raffaele Recalcati5f7ddae2010-08-09 17:20:59 -07001533 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
Andy Whitcroft6b4c5be2010-10-26 14:23:11 -07001534 WARN("please, no spaces at the start of a line\n" . $herevet);
Raffaele Recalcati5f7ddae2010-08-09 17:20:59 -07001535 }
1536
Andy Whitcroftb9ea10d2008-10-15 22:02:24 -07001537# check we are in a valid C source file if not then ignore this hunk
1538 next if ($realfile !~ /\.(h|c)$/);
1539
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001540# check for RCS/CVS revision markers
Andy Whitcroftcf655042008-03-04 14:28:20 -08001541 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001542 WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
1543 }
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001544
Mike Frysinger42e41c52009-09-21 17:04:40 -07001545# Blackfin: don't use __builtin_bfin_[cs]sync
1546 if ($line =~ /__builtin_bfin_csync/) {
1547 my $herevet = "$here\n" . cat_vet($line) . "\n";
1548 ERROR("use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
1549 }
1550 if ($line =~ /__builtin_bfin_ssync/) {
1551 my $herevet = "$here\n" . cat_vet($line) . "\n";
1552 ERROR("use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
1553 }
1554
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001555# Check for potential 'bare' types
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001556 my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
1557 $realline_next);
Andy Whitcroft9c9ba342008-04-29 00:59:33 -07001558 if ($realcnt && $line =~ /.\s*\S/) {
Andy Whitcroft170d3a22008-10-15 22:02:30 -07001559 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
Andy Whitcroftf5fe35d2008-07-23 21:29:03 -07001560 ctx_statement_block($linenr, $realcnt, 0);
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001561 $stat =~ s/\n./\n /g;
1562 $cond =~ s/\n./\n /g;
1563
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001564 # Find the real next line.
1565 $realline_next = $line_nr_next;
1566 if (defined $realline_next &&
1567 (!defined $lines[$realline_next - 1] ||
1568 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
1569 $realline_next++;
1570 }
1571
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001572 my $s = $stat;
1573 $s =~ s/{.*$//s;
Andy Whitcroftcf655042008-03-04 14:28:20 -08001574
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001575 # Ignore goto labels.
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001576 if ($s =~ /$Ident:\*$/s) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001577
1578 # Ignore functions being called
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001579 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001580
Andy Whitcroft463f2862009-09-21 17:04:34 -07001581 } elsif ($s =~ /^.\s*else\b/s) {
1582
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001583 # declarations always start with types
Andy Whitcroftd2506582008-07-23 21:29:09 -07001584 } 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) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001585 my $type = $1;
1586 $type =~ s/\s+/ /g;
1587 possible($type, "A:" . $s);
1588
Andy Whitcroft8905a672007-11-28 16:21:06 -08001589 # definitions in global scope can only start with types
Andy Whitcrofta6a84062008-10-15 22:02:30 -07001590 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001591 possible($1, "B:" . $s);
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001592 }
Andy Whitcroft8905a672007-11-28 16:21:06 -08001593
1594 # any (foo ... *) is a pointer cast, and foo is a type
Andy Whitcroft65863862009-01-06 14:41:21 -08001595 while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001596 possible($1, "C:" . $s);
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001597 }
Andy Whitcroft8905a672007-11-28 16:21:06 -08001598
1599 # Check for any sort of function declaration.
1600 # int foo(something bar, other baz);
1601 # void (*store_gdt)(x86_descr_ptr *);
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07001602 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
Andy Whitcroft8905a672007-11-28 16:21:06 -08001603 my ($name_len) = length($1);
Andy Whitcroft8905a672007-11-28 16:21:06 -08001604
Andy Whitcroftcf655042008-03-04 14:28:20 -08001605 my $ctx = $s;
Andy Whitcroft773647a2008-03-28 14:15:58 -07001606 substr($ctx, 0, $name_len + 1, '');
Andy Whitcroft8905a672007-11-28 16:21:06 -08001607 $ctx =~ s/\)[^\)]*$//;
Andy Whitcroftcf655042008-03-04 14:28:20 -08001608
Andy Whitcroft8905a672007-11-28 16:21:06 -08001609 for my $arg (split(/\s*,\s*/, $ctx)) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001610 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
Andy Whitcroft8905a672007-11-28 16:21:06 -08001611
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001612 possible($1, "D:" . $s);
Andy Whitcroft8905a672007-11-28 16:21:06 -08001613 }
1614 }
1615 }
1616
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001617 }
1618
Andy Whitcroft653d4872007-06-23 17:16:34 -07001619#
1620# Checks which may be anchored in the context.
1621#
1622
1623# Check for switch () and associated case and default
1624# statements should be at the same indent.
Andy Whitcroft00df3442007-06-08 13:47:06 -07001625 if ($line=~/\bswitch\s*\(.*\)/) {
1626 my $err = '';
1627 my $sep = '';
1628 my @ctx = ctx_block_outer($linenr, $realcnt);
1629 shift(@ctx);
1630 for my $ctx (@ctx) {
1631 my ($clen, $cindent) = line_stats($ctx);
1632 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
1633 $indent != $cindent) {
1634 $err .= "$sep$ctx\n";
1635 $sep = '';
1636 } else {
1637 $sep = "[...]\n";
1638 }
1639 }
1640 if ($err ne '') {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001641 ERROR("switch and case should be at the same indent\n$hereline$err");
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001642 }
1643 }
1644
1645# if/while/etc brace do not go on next line, unless defining a do while loop,
1646# or if that brace on the next line is for something else
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001647 if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001648 my $pre_ctx = "$1$2";
1649
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001650 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001651 my $ctx_cnt = $realcnt - $#ctx - 1;
1652 my $ctx = join("\n", @ctx);
1653
Andy Whitcroft548596d2008-07-23 21:29:01 -07001654 my $ctx_ln = $linenr;
1655 my $ctx_skip = $realcnt;
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001656
Andy Whitcroft548596d2008-07-23 21:29:01 -07001657 while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
1658 defined $lines[$ctx_ln - 1] &&
1659 $lines[$ctx_ln - 1] =~ /^-/)) {
1660 ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
1661 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
Andy Whitcroft773647a2008-03-28 14:15:58 -07001662 $ctx_ln++;
1663 }
Andy Whitcroft548596d2008-07-23 21:29:01 -07001664
Andy Whitcroft53210162008-07-23 21:29:03 -07001665 #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
1666 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
Andy Whitcroft773647a2008-03-28 14:15:58 -07001667
1668 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1669 ERROR("that open brace { should be on the previous line\n" .
Andy Whitcroft01464f32010-10-26 14:23:19 -07001670 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
Andy Whitcroft00df3442007-06-08 13:47:06 -07001671 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07001672 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
1673 $ctx =~ /\)\s*\;\s*$/ &&
1674 defined $lines[$ctx_ln - 1])
1675 {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001676 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
1677 if ($nindent > $indent) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001678 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" .
Andy Whitcroft01464f32010-10-26 14:23:19 -07001679 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001680 }
1681 }
Andy Whitcroft00df3442007-06-08 13:47:06 -07001682 }
1683
Andy Whitcroft4d001e42008-10-15 22:02:21 -07001684# Check relative indent for conditionals and blocks.
1685 if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
1686 my ($s, $c) = ($stat, $cond);
1687
1688 substr($s, 0, length($c), '');
1689
1690 # Make sure we remove the line prefixes as we have
1691 # none on the first line, and are going to readd them
1692 # where necessary.
1693 $s =~ s/\n./\n/gs;
1694
1695 # Find out how long the conditional actually is.
Andy Whitcroft6f779c12008-10-15 22:02:27 -07001696 my @newlines = ($c =~ /\n/gs);
1697 my $cond_lines = 1 + $#newlines;
Andy Whitcroft4d001e42008-10-15 22:02:21 -07001698
1699 # We want to check the first line inside the block
1700 # starting at the end of the conditional, so remove:
1701 # 1) any blank line termination
1702 # 2) any opening brace { on end of the line
1703 # 3) any do (...) {
1704 my $continuation = 0;
1705 my $check = 0;
1706 $s =~ s/^.*\bdo\b//;
1707 $s =~ s/^\s*{//;
1708 if ($s =~ s/^\s*\\//) {
1709 $continuation = 1;
1710 }
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001711 if ($s =~ s/^\s*?\n//) {
Andy Whitcroft4d001e42008-10-15 22:02:21 -07001712 $check = 1;
1713 $cond_lines++;
1714 }
1715
1716 # Also ignore a loop construct at the end of a
1717 # preprocessor statement.
1718 if (($prevline =~ /^.\s*#\s*define\s/ ||
1719 $prevline =~ /\\\s*$/) && $continuation == 0) {
1720 $check = 0;
1721 }
1722
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001723 my $cond_ptr = -1;
Andy Whitcroft740504c2008-10-15 22:02:35 -07001724 $continuation = 0;
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001725 while ($cond_ptr != $cond_lines) {
1726 $cond_ptr = $cond_lines;
Andy Whitcroft4d001e42008-10-15 22:02:21 -07001727
Andy Whitcroftf16fa282008-10-15 22:02:32 -07001728 # If we see an #else/#elif then the code
1729 # is not linear.
1730 if ($s =~ /^\s*\#\s*(?:else|elif)/) {
1731 $check = 0;
1732 }
1733
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001734 # Ignore:
1735 # 1) blank lines, they should be at 0,
1736 # 2) preprocessor lines, and
1737 # 3) labels.
Andy Whitcroft740504c2008-10-15 22:02:35 -07001738 if ($continuation ||
1739 $s =~ /^\s*?\n/ ||
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001740 $s =~ /^\s*#\s*?/ ||
1741 $s =~ /^\s*$Ident\s*:/) {
Andy Whitcroft740504c2008-10-15 22:02:35 -07001742 $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
Andy Whitcroft30dad6e2009-09-21 17:04:36 -07001743 if ($s =~ s/^.*?\n//) {
1744 $cond_lines++;
1745 }
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001746 }
Andy Whitcroft4d001e42008-10-15 22:02:21 -07001747 }
1748
1749 my (undef, $sindent) = line_stats("+" . $s);
1750 my $stat_real = raw_line($linenr, $cond_lines);
1751
1752 # Check if either of these lines are modified, else
1753 # this is not this patch's fault.
1754 if (!defined($stat_real) ||
1755 $stat !~ /^\+/ && $stat_real !~ /^\+/) {
1756 $check = 0;
1757 }
1758 if (defined($stat_real) && $cond_lines > 1) {
1759 $stat_real = "[...]\n$stat_real";
1760 }
1761
Andy Whitcroft9bd49ef2008-10-15 22:02:22 -07001762 #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";
Andy Whitcroft4d001e42008-10-15 22:02:21 -07001763
1764 if ($check && (($sindent % 8) != 0 ||
1765 ($sindent <= $indent && $s ne ''))) {
1766 WARN("suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
1767 }
1768 }
1769
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001770 # Track the 'values' across context and added lines.
1771 my $opline = $line; $opline =~ s/^./ /;
Andy Whitcroft1f65f942008-07-23 21:29:10 -07001772 my ($curr_values, $curr_vars) =
1773 annotate_values($opline . "\n", $prev_values);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001774 $curr_values = $prev_values . $curr_values;
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001775 if ($dbg_values) {
1776 my $outline = $opline; $outline =~ s/\t/ /g;
Andy Whitcroftcf655042008-03-04 14:28:20 -08001777 print "$linenr > .$outline\n";
1778 print "$linenr > $curr_values\n";
Andy Whitcroft1f65f942008-07-23 21:29:10 -07001779 print "$linenr > $curr_vars\n";
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001780 }
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001781 $prev_values = substr($curr_values, -1);
1782
Andy Whitcroft00df3442007-06-08 13:47:06 -07001783#ignore lines not being added
1784 if ($line=~/^[^\+]/) {next;}
1785
Andy Whitcroft653d4872007-06-23 17:16:34 -07001786# TEST: allow direct testing of the type matcher.
Andy Whitcroft7429c692008-07-23 21:29:06 -07001787 if ($dbg_type) {
1788 if ($line =~ /^.\s*$Declare\s*$/) {
1789 ERROR("TEST: is type\n" . $herecurr);
1790 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
1791 ERROR("TEST: is not type ($1 is)\n". $herecurr);
1792 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001793 next;
1794 }
Andy Whitcrofta1ef2772008-10-15 22:02:17 -07001795# TEST: allow direct testing of the attribute matcher.
1796 if ($dbg_attr) {
Andy Whitcroft9360b0e2009-02-27 14:03:08 -08001797 if ($line =~ /^.\s*$Modifier\s*$/) {
Andy Whitcrofta1ef2772008-10-15 22:02:17 -07001798 ERROR("TEST: is attr\n" . $herecurr);
Andy Whitcroft9360b0e2009-02-27 14:03:08 -08001799 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
Andy Whitcrofta1ef2772008-10-15 22:02:17 -07001800 ERROR("TEST: is not attr ($1 is)\n". $herecurr);
1801 }
1802 next;
1803 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001804
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001805# check for initialisation to aggregates open brace on the next line
Andy Whitcroft99423c22009-10-26 16:50:15 -07001806 if ($line =~ /^.\s*{/ &&
1807 $prevline =~ /(?:^|[^=])=\s*$/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07001808 ERROR("that open brace { should be on the previous line\n" . $hereprev);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001809 }
1810
Andy Whitcroft653d4872007-06-23 17:16:34 -07001811#
1812# Checks which are anchored on the added line.
1813#
1814
1815# check for malformed paths in #include statements (uses RAW line)
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001816 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
Andy Whitcroft653d4872007-06-23 17:16:34 -07001817 my $path = $1;
1818 if ($path =~ m{//}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001819 ERROR("malformed #include filename\n" .
1820 $herecurr);
Andy Whitcroft653d4872007-06-23 17:16:34 -07001821 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001822 }
Andy Whitcroft00df3442007-06-08 13:47:06 -07001823
1824# no C99 // comments
1825 if ($line =~ m{//}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001826 ERROR("do not use C99 // comments\n" . $herecurr);
Andy Whitcroft00df3442007-06-08 13:47:06 -07001827 }
1828 # Remove C99 comments.
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001829 $line =~ s@//.*@@;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07001830 $opline =~ s@//.*@@;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001831
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001832# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
1833# the whole statement.
1834#print "APW <$lines[$realline_next - 1]>\n";
1835 if (defined $realline_next &&
1836 exists $lines[$realline_next - 1] &&
1837 !defined $suppress_export{$realline_next} &&
1838 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
1839 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
Andy Whitcroft3cbf62d2010-10-26 14:23:18 -07001840 # Handle definitions which produce identifiers with
1841 # a prefix:
1842 # XXX(foo);
1843 # EXPORT_SYMBOL(something_foo);
Andy Whitcroft653d4872007-06-23 17:16:34 -07001844 my $name = $1;
Andy Whitcroft3cbf62d2010-10-26 14:23:18 -07001845 if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ &&
1846 $name =~ /^${Ident}_$2/) {
1847#print "FOO C name<$name>\n";
1848 $suppress_export{$realline_next} = 1;
1849
1850 } elsif ($stat !~ /(?:
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001851 \n.}\s*$|
Andy Whitcroft48012052008-10-15 22:02:34 -07001852 ^.DEFINE_$Ident\(\Q$name\E\)|
1853 ^.DECLARE_$Ident\(\Q$name\E\)|
1854 ^.LIST_HEAD\(\Q$name\E\)|
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001855 ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
1856 \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
Andy Whitcroft48012052008-10-15 22:02:34 -07001857 )/x) {
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001858#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
1859 $suppress_export{$realline_next} = 2;
1860 } else {
1861 $suppress_export{$realline_next} = 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001862 }
1863 }
Andy Whitcroft2b474a12009-10-26 16:50:16 -07001864 if (!defined $suppress_export{$linenr} &&
1865 $prevline =~ /^.\s*$/ &&
1866 ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
1867 $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
1868#print "FOO B <$lines[$linenr - 1]>\n";
1869 $suppress_export{$linenr} = 2;
1870 }
1871 if (defined $suppress_export{$linenr} &&
1872 $suppress_export{$linenr} == 2) {
1873 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1874 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001875
Joe Eloff5150bda2010-08-09 17:21:00 -07001876# check for global initialisers.
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001877 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
Joe Eloff5150bda2010-08-09 17:21:00 -07001878 ERROR("do not initialise globals to 0 or NULL\n" .
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001879 $herecurr);
1880 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001881# check for static initialisers.
Andy Whitcroft2d1bafd2009-01-06 14:41:28 -08001882 if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001883 ERROR("do not initialise statics to 0 or NULL\n" .
1884 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001885 }
1886
Joe Perchescb710ec2010-10-26 14:23:20 -07001887# check for static const char * arrays.
1888 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
1889 WARN("static const char * array should probably be static const char * const\n" .
1890 $herecurr);
1891 }
1892
1893# check for static char foo[] = "bar" declarations.
1894 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
1895 WARN("static char array declaration should probably be static const char\n" .
1896 $herecurr);
1897 }
1898
Joe Perches93ed0e22010-10-26 14:23:21 -07001899# check for declarations of struct pci_device_id
1900 if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) {
1901 WARN("Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr);
1902 }
1903
Andy Whitcroft653d4872007-06-23 17:16:34 -07001904# check for new typedefs, only function parameters and sparse annotations
1905# make sense.
1906 if ($line =~ /\btypedef\s/ &&
Andy Whitcroft80545762009-01-06 14:41:26 -08001907 $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001908 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
Andy Whitcroft8ed22ca2008-10-15 22:02:32 -07001909 $line !~ /\b$typeTypedefs\b/ &&
Andy Whitcroft653d4872007-06-23 17:16:34 -07001910 $line !~ /\b__bitwise(?:__|)\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001911 WARN("do not add new typedefs\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001912 }
1913
1914# * goes on variable not on type
Andy Whitcroft65863862009-01-06 14:41:21 -08001915 # (char*[ const])
Andy Whitcroft00ef4ec2009-02-27 14:03:07 -08001916 if ($line =~ m{\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\)}) {
Andy Whitcroft65863862009-01-06 14:41:21 -08001917 my ($from, $to) = ($1, $1);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001918
Andy Whitcroft65863862009-01-06 14:41:21 -08001919 # Should start with a space.
1920 $to =~ s/^(\S)/ $1/;
1921 # Should not end with a space.
1922 $to =~ s/\s+$//;
1923 # '*'s should not have spaces between.
Andy Whitcroftf9a0b3d2009-01-15 13:51:05 -08001924 while ($to =~ s/\*\s+\*/\*\*/) {
Andy Whitcroft65863862009-01-06 14:41:21 -08001925 }
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001926
Andy Whitcroft65863862009-01-06 14:41:21 -08001927 #print "from<$from> to<$to>\n";
1928 if ($from ne $to) {
1929 ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
1930 }
Andy Whitcroft00ef4ec2009-02-27 14:03:07 -08001931 } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) {
Andy Whitcroft65863862009-01-06 14:41:21 -08001932 my ($from, $to, $ident) = ($1, $1, $2);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001933
Andy Whitcroft65863862009-01-06 14:41:21 -08001934 # Should start with a space.
1935 $to =~ s/^(\S)/ $1/;
1936 # Should not end with a space.
1937 $to =~ s/\s+$//;
1938 # '*'s should not have spaces between.
Andy Whitcroftf9a0b3d2009-01-15 13:51:05 -08001939 while ($to =~ s/\*\s+\*/\*\*/) {
Andy Whitcroft65863862009-01-06 14:41:21 -08001940 }
1941 # Modifiers should have spaces.
1942 $to =~ s/(\b$Modifier$)/$1 /;
1943
Andy Whitcroft667026e2009-02-27 14:03:08 -08001944 #print "from<$from> to<$to> ident<$ident>\n";
1945 if ($from ne $to && $ident !~ /^$Modifier$/) {
Andy Whitcroft65863862009-01-06 14:41:21 -08001946 ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr);
1947 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001948 }
1949
1950# # no BUG() or BUG_ON()
1951# if ($line =~ /\b(BUG|BUG_ON)\b/) {
1952# print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
1953# print "$herecurr";
1954# $clean = 0;
1955# }
1956
Andy Whitcroft8905a672007-11-28 16:21:06 -08001957 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08001958 WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
Andy Whitcroft8905a672007-11-28 16:21:06 -08001959 }
1960
Joe Perches17441222011-06-15 15:08:17 -07001961# check for uses of printk_ratelimit
1962 if ($line =~ /\bprintk_ratelimit\s*\(/) {
1963 WARN("Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
1964 }
1965
Andy Whitcroft00df3442007-06-08 13:47:06 -07001966# printk should use KERN_* levels. Note that follow on printk's on the
1967# same line do not need a level, so we use the current block context
1968# to try and find and validate the current printk. In summary the current
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001969# printk includes all preceding printk's which have no newline on the end.
Andy Whitcroft00df3442007-06-08 13:47:06 -07001970# we assume the first bad printk is the one to report.
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001971 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
Andy Whitcroft00df3442007-06-08 13:47:06 -07001972 my $ok = 0;
1973 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
1974 #print "CHECK<$lines[$ln - 1]\n";
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001975 # we have a preceding printk if it ends
Andy Whitcroft00df3442007-06-08 13:47:06 -07001976 # with "\n" ignore it, else it is to blame
1977 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
1978 if ($rawlines[$ln - 1] !~ m{\\n"}) {
1979 $ok = 1;
1980 }
1981 last;
1982 }
1983 }
1984 if ($ok == 0) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001985 WARN("printk() should include KERN_ facility level\n" . $herecurr);
Andy Whitcroft00df3442007-06-08 13:47:06 -07001986 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001987 }
1988
Andy Whitcroft653d4872007-06-23 17:16:34 -07001989# function brace can't be on same line, except for #defines of do while,
1990# or if closed on same line
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07001991 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
1992 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001993 ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001994 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001995
Andy Whitcroft8905a672007-11-28 16:21:06 -08001996# open braces for enum, union and struct go on the same line.
1997 if ($line =~ /^.\s*{/ &&
1998 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
1999 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
2000 }
2001
Andy Whitcroft0c73b4e2010-10-26 14:23:15 -07002002# missing space after union, struct or enum definition
2003 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
2004 WARN("missing space after $1 definition\n" . $herecurr);
2005 }
2006
Andy Whitcroft8d31cfc2008-07-23 21:29:02 -07002007# check for spacing round square brackets; allowed:
2008# 1. with a type on the left -- int [] a;
Andy Whitcroftfe2a7db2008-10-15 22:02:15 -07002009# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
2010# 3. inside a curly brace -- = { [0...10] = 5 }
Andy Whitcroft8d31cfc2008-07-23 21:29:02 -07002011 while ($line =~ /(.*?\s)\[/g) {
2012 my ($where, $prefix) = ($-[1], $1);
2013 if ($prefix !~ /$Type\s+$/ &&
Andy Whitcroftfe2a7db2008-10-15 22:02:15 -07002014 ($where != 0 || $prefix !~ /^.\s+$/) &&
2015 $prefix !~ /{\s+$/) {
Andy Whitcroft8d31cfc2008-07-23 21:29:02 -07002016 ERROR("space prohibited before open square bracket '['\n" . $herecurr);
2017 }
2018 }
2019
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002020# check for spaces between functions and their parentheses.
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002021 while ($line =~ /($Ident)\s+\(/g) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002022 my $name = $1;
Andy Whitcroft773647a2008-03-28 14:15:58 -07002023 my $ctx_before = substr($line, 0, $-[1]);
2024 my $ctx = "$ctx_before$name";
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002025
2026 # Ignore those directives where spaces _are_ permitted.
Andy Whitcroft773647a2008-03-28 14:15:58 -07002027 if ($name =~ /^(?:
2028 if|for|while|switch|return|case|
2029 volatile|__volatile__|
2030 __attribute__|format|__extension__|
2031 asm|__asm__)$/x)
2032 {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002033
2034 # cpp #define statements have non-optional spaces, ie
2035 # if there is a space between the name and the open
2036 # parenthesis it is simply not a parameter group.
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002037 } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002038
2039 # cpp #elif statement condition may start with a (
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002040 } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002041
2042 # If this whole things ends with a type its most
2043 # likely a typedef for a function.
Andy Whitcroft773647a2008-03-28 14:15:58 -07002044 } elsif ($ctx =~ /$Type$/) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002045
2046 } else {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002047 WARN("space prohibited between function name and open parenthesis '('\n" . $herecurr);
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002048 }
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002049 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07002050# Check operator spacing.
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002051 if (!($line=~/\#\s*include/)) {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002052 my $ops = qr{
2053 <<=|>>=|<=|>=|==|!=|
2054 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
2055 =>|->|<<|>>|<|>|=|!|~|
Andy Whitcroft1f65f942008-07-23 21:29:10 -07002056 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
2057 \?|:
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002058 }x;
Andy Whitcroftcf655042008-03-04 14:28:20 -08002059 my @elements = split(/($ops|;)/, $opline);
Andy Whitcroft00df3442007-06-08 13:47:06 -07002060 my $off = 0;
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002061
2062 my $blank = copy_spacing($opline);
2063
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002064 for (my $n = 0; $n < $#elements; $n += 2) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002065 $off += length($elements[$n]);
2066
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002067 # Pick up the preceding and succeeding characters.
Andy Whitcroft773647a2008-03-28 14:15:58 -07002068 my $ca = substr($opline, 0, $off);
2069 my $cc = '';
2070 if (length($opline) >= ($off + length($elements[$n + 1]))) {
2071 $cc = substr($opline, $off + length($elements[$n + 1]));
2072 }
2073 my $cb = "$ca$;$cc";
2074
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002075 my $a = '';
2076 $a = 'V' if ($elements[$n] ne '');
2077 $a = 'W' if ($elements[$n] =~ /\s$/);
Andy Whitcroftcf655042008-03-04 14:28:20 -08002078 $a = 'C' if ($elements[$n] =~ /$;$/);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002079 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
2080 $a = 'O' if ($elements[$n] eq '');
Andy Whitcroft773647a2008-03-28 14:15:58 -07002081 $a = 'E' if ($ca =~ /^\s*$/);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002082
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002083 my $op = $elements[$n + 1];
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002084
2085 my $c = '';
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002086 if (defined $elements[$n + 2]) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002087 $c = 'V' if ($elements[$n + 2] ne '');
2088 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
Andy Whitcroftcf655042008-03-04 14:28:20 -08002089 $c = 'C' if ($elements[$n + 2] =~ /^$;/);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002090 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
2091 $c = 'O' if ($elements[$n + 2] eq '');
Andy Whitcroft8b1b3372009-01-06 14:41:27 -08002092 $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002093 } else {
2094 $c = 'E';
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002095 }
2096
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002097 my $ctx = "${a}x${c}";
2098
2099 my $at = "(ctx:$ctx)";
2100
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002101 my $ptr = substr($blank, 0, $off) . "^";
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002102 my $hereptr = "$hereline$ptr\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002103
Andy Whitcroft74048ed2008-07-23 21:29:10 -07002104 # Pull out the value of this operator.
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002105 my $op_type = substr($curr_values, $off + 1, 1);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002106
Andy Whitcroft1f65f942008-07-23 21:29:10 -07002107 # Get the full operator variant.
2108 my $opv = $op . substr($curr_vars, $off, 1);
2109
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002110 # Ignore operators passed as parameters.
2111 if ($op_type ne 'V' &&
2112 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
2113
Andy Whitcroftcf655042008-03-04 14:28:20 -08002114# # Ignore comments
2115# } elsif ($op =~ /^$;+$/) {
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002116
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07002117 # ; should have either the end of line or a space or \ after it
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002118 } elsif ($op eq ';') {
Andy Whitcroftcf655042008-03-04 14:28:20 -08002119 if ($ctx !~ /.x[WEBC]/ &&
2120 $cc !~ /^\\/ && $cc !~ /^;/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002121 ERROR("space required after that '$op' $at\n" . $hereptr);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07002122 }
2123
2124 # // is a comment
2125 } elsif ($op eq '//') {
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002126
Andy Whitcroft1f65f942008-07-23 21:29:10 -07002127 # No spaces for:
2128 # ->
2129 # : when part of a bitfield
2130 } elsif ($op eq '->' || $opv eq ':B') {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002131 if ($ctx =~ /Wx.|.xW/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002132 ERROR("spaces prohibited around that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002133 }
2134
2135 # , must have a space on the right.
2136 } elsif ($op eq ',') {
Andy Whitcroftcf655042008-03-04 14:28:20 -08002137 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002138 ERROR("space required after that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002139 }
2140
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002141 # '*' as part of a type definition -- reported already.
Andy Whitcroft74048ed2008-07-23 21:29:10 -07002142 } elsif ($opv eq '*_') {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002143 #warn "'*' is part of type\n";
2144
2145 # unary operators should have a space before and
2146 # none after. May be left adjacent to another
2147 # unary operator, or a cast
2148 } elsif ($op eq '!' || $op eq '~' ||
Andy Whitcroft74048ed2008-07-23 21:29:10 -07002149 $opv eq '*U' || $opv eq '-U' ||
Andy Whitcroft0d413862008-10-15 22:02:16 -07002150 $opv eq '&U' || $opv eq '&&U') {
Andy Whitcroftcf655042008-03-04 14:28:20 -08002151 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002152 ERROR("space required before that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002153 }
Andy Whitcrofta3340b32009-02-27 14:03:07 -08002154 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002155 # A unary '*' may be const
2156
2157 } elsif ($ctx =~ /.xW/) {
Andy Whitcroftfb9e9092009-09-21 17:04:38 -07002158 ERROR("space prohibited after that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002159 }
2160
2161 # unary ++ and unary -- are allowed no space on one side.
2162 } elsif ($op eq '++' or $op eq '--') {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002163 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
2164 ERROR("space required one side of that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002165 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07002166 if ($ctx =~ /Wx[BE]/ ||
2167 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
2168 ERROR("space prohibited before that '$op' $at\n" . $hereptr);
Andy Whitcroft653d4872007-06-23 17:16:34 -07002169 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07002170 if ($ctx =~ /ExW/) {
2171 ERROR("space prohibited after that '$op' $at\n" . $hereptr);
2172 }
2173
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002174
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002175 # << and >> may either have or not have spaces both sides
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002176 } elsif ($op eq '<<' or $op eq '>>' or
2177 $op eq '&' or $op eq '^' or $op eq '|' or
2178 $op eq '+' or $op eq '-' or
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002179 $op eq '*' or $op eq '/' or
2180 $op eq '%')
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002181 {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002182 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002183 ERROR("need consistent spacing around '$op' $at\n" .
2184 $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002185 }
2186
Andy Whitcroft1f65f942008-07-23 21:29:10 -07002187 # A colon needs no spaces before when it is
2188 # terminating a case value or a label.
2189 } elsif ($opv eq ':C' || $opv eq ':L') {
2190 if ($ctx =~ /Wx./) {
2191 ERROR("space prohibited before that '$op' $at\n" . $hereptr);
2192 }
2193
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002194 # All the others need spaces both sides.
Andy Whitcroftcf655042008-03-04 14:28:20 -08002195 } elsif ($ctx !~ /[EWC]x[CWE]/) {
Andy Whitcroft1f65f942008-07-23 21:29:10 -07002196 my $ok = 0;
2197
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002198 # Ignore email addresses <foo@bar>
Andy Whitcroft1f65f942008-07-23 21:29:10 -07002199 if (($op eq '<' &&
2200 $cc =~ /^\S+\@\S+>/) ||
2201 ($op eq '>' &&
2202 $ca =~ /<\S+\@\S+$/))
2203 {
2204 $ok = 1;
2205 }
2206
2207 # Ignore ?:
2208 if (($opv eq ':O' && $ca =~ /\?$/) ||
2209 ($op eq '?' && $cc =~ /^:/)) {
2210 $ok = 1;
2211 }
2212
2213 if ($ok == 0) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002214 ERROR("spaces required around that '$op' $at\n" . $hereptr);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002215 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002216 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002217 $off += length($elements[$n + 1]);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002218 }
2219 }
2220
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002221# check for multiple assignments
2222 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002223 CHK("multiple assignments should be avoided\n" . $herecurr);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002224 }
2225
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002226## # check for multiple declarations, allowing for a function declaration
2227## # continuation.
2228## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
2229## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
2230##
2231## # Remove any bracketed sections to ensure we do not
2232## # falsly report the parameters of functions.
2233## my $ln = $line;
2234## while ($ln =~ s/\([^\(\)]*\)//g) {
2235## }
2236## if ($ln =~ /,/) {
2237## WARN("declaring multiple variables together should be avoided\n" . $herecurr);
2238## }
2239## }
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002240
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002241#need space before brace following if, while, etc
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002242 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
2243 $line =~ /do{/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002244 ERROR("space required before the open brace '{'\n" . $herecurr);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002245 }
2246
2247# closing brace should have a space following it when it has anything
2248# on the line
2249 if ($line =~ /}(?!(?:,|;|\)))\S/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002250 ERROR("space required after that close brace '}'\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002251 }
2252
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002253# check spacing on square brackets
2254 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002255 ERROR("space prohibited after that open square bracket '['\n" . $herecurr);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002256 }
2257 if ($line =~ /\s\]/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002258 ERROR("space prohibited before that close square bracket ']'\n" . $herecurr);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002259 }
2260
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002261# check spacing on parentheses
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002262 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
2263 $line !~ /for\s*\(\s+;/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002264 ERROR("space prohibited after that open parenthesis '('\n" . $herecurr);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002265 }
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002266 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002267 $line !~ /for\s*\(.*;\s+\)/ &&
2268 $line !~ /:\s+\)/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002269 ERROR("space prohibited before that close parenthesis ')'\n" . $herecurr);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002270 }
2271
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002272#goto labels aren't indented, allow a single space however
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002273 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002274 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002275 WARN("labels should not be indented\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002276 }
2277
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002278# Return is not a function.
2279 if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) {
2280 my $spacing = $1;
2281 my $value = $2;
2282
Andy Whitcroft86f9d052009-01-06 14:41:24 -08002283 # Flatten any parentheses
Andy Whitcroftfb2d2c12010-10-26 14:23:12 -07002284 $value =~ s/\(/ \(/g;
2285 $value =~ s/\)/\) /g;
Andy Whitcroft63f17f82009-01-15 13:51:06 -08002286 while ($value =~ s/\[[^\{\}]*\]/1/ ||
2287 $value !~ /(?:$Ident|-?$Constant)\s*
2288 $Compare\s*
2289 (?:$Ident|-?$Constant)/x &&
2290 $value =~ s/\([^\(\)]*\)/1/) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002291 }
Andy Whitcroftfb2d2c12010-10-26 14:23:12 -07002292#print "value<$value>\n";
2293 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002294 ERROR("return is not a function, parentheses are not required\n" . $herecurr);
2295
2296 } elsif ($spacing !~ /\s+/) {
2297 ERROR("space required before the open parenthesis '('\n" . $herecurr);
2298 }
2299 }
Andy Whitcroft53a3c442010-10-26 14:23:14 -07002300# Return of what appears to be an errno should normally be -'ve
2301 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
2302 my $name = $1;
2303 if ($name ne 'EOF' && $name ne 'ERROR') {
2304 WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
2305 }
2306 }
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002307
Joe Perches7d2367a2011-07-25 17:13:22 -07002308# typecasts on min/max could be min_t/max_t
2309 if ($line =~ /^\+(?:.*?)\b(min|max)\s*\($Typecast{0,1}($LvalOrFunc)\s*,\s*$Typecast{0,1}($LvalOrFunc)\s*\)/) {
2310 if (defined $2 || defined $8) {
2311 my $call = $1;
2312 my $cast1 = deparenthesize($2);
2313 my $arg1 = $3;
2314 my $cast2 = deparenthesize($8);
2315 my $arg2 = $9;
2316 my $cast;
2317
2318 if ($cast1 ne "" && $cast2 ne "") {
2319 $cast = "$cast1 or $cast2";
2320 } elsif ($cast1 ne "") {
2321 $cast = $cast1;
2322 } else {
2323 $cast = $cast2;
2324 }
2325 WARN("$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . $herecurr);
2326 }
2327 }
2328
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002329# Need a space before open parenthesis after if, while etc
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002330 if ($line=~/\b(if|while|for|switch)\(/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002331 ERROR("space required before the open parenthesis '('\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002332 }
2333
Andy Whitcroftf5fe35d2008-07-23 21:29:03 -07002334# Check for illegal assignment in if conditional -- and check for trailing
2335# statements after the conditional.
Andy Whitcroft170d3a22008-10-15 22:02:30 -07002336 if ($line =~ /do\s*(?!{)/) {
2337 my ($stat_next) = ctx_statement_block($line_nr_next,
2338 $remain_next, $off_next);
2339 $stat_next =~ s/\n./\n /g;
2340 ##print "stat<$stat> stat_next<$stat_next>\n";
2341
2342 if ($stat_next =~ /^\s*while\b/) {
2343 # If the statement carries leading newlines,
2344 # then count those as offsets.
2345 my ($whitespace) =
2346 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
2347 my $offset =
2348 statement_rawlines($whitespace) - 1;
2349
2350 $suppress_whiletrailers{$line_nr_next +
2351 $offset} = 1;
2352 }
2353 }
2354 if (!defined $suppress_whiletrailers{$linenr} &&
2355 $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002356 my ($s, $c) = ($stat, $cond);
Andy Whitcroft8905a672007-11-28 16:21:06 -08002357
Andy Whitcroftb53c8e12009-01-06 14:41:29 -08002358 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002359 ERROR("do not use assignment in if condition\n" . $herecurr);
Andy Whitcroft8905a672007-11-28 16:21:06 -08002360 }
2361
2362 # Find out what is on the end of the line after the
2363 # conditional.
Andy Whitcroft773647a2008-03-28 14:15:58 -07002364 substr($s, 0, length($c), '');
Andy Whitcroft8905a672007-11-28 16:21:06 -08002365 $s =~ s/\n.*//g;
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002366 $s =~ s/$;//g; # Remove any comments
Andy Whitcroft53210162008-07-23 21:29:03 -07002367 if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
2368 $c !~ /}\s*while\s*/)
Andy Whitcroft773647a2008-03-28 14:15:58 -07002369 {
Andy Whitcroftbb44ad32008-10-15 22:02:34 -07002370 # Find out how long the conditional actually is.
2371 my @newlines = ($c =~ /\n/gs);
2372 my $cond_lines = 1 + $#newlines;
Hidetoshi Seto42bdf742010-03-05 13:43:50 -08002373 my $stat_real = '';
Andy Whitcroftbb44ad32008-10-15 22:02:34 -07002374
Hidetoshi Seto42bdf742010-03-05 13:43:50 -08002375 $stat_real = raw_line($linenr, $cond_lines)
2376 . "\n" if ($cond_lines);
Andy Whitcroftbb44ad32008-10-15 22:02:34 -07002377 if (defined($stat_real) && $cond_lines > 1) {
2378 $stat_real = "[...]\n$stat_real";
2379 }
2380
2381 ERROR("trailing statements should be on next line\n" . $herecurr . $stat_real);
Andy Whitcroft8905a672007-11-28 16:21:06 -08002382 }
2383 }
2384
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002385# Check for bitwise tests written as boolean
2386 if ($line =~ /
2387 (?:
2388 (?:\[|\(|\&\&|\|\|)
2389 \s*0[xX][0-9]+\s*
2390 (?:\&\&|\|\|)
2391 |
2392 (?:\&\&|\|\|)
2393 \s*0[xX][0-9]+\s*
2394 (?:\&\&|\|\||\)|\])
2395 )/x)
2396 {
2397 WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
2398 }
2399
Andy Whitcroft8905a672007-11-28 16:21:06 -08002400# if and else should not have general statements after it
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002401 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
2402 my $s = $1;
2403 $s =~ s/$;//g; # Remove any comments
2404 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
2405 ERROR("trailing statements should be on next line\n" . $herecurr);
2406 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002407 }
Andy Whitcroft39667782009-01-15 13:51:06 -08002408# if should not continue a brace
2409 if ($line =~ /}\s*if\b/) {
2410 ERROR("trailing statements should be on next line\n" .
2411 $herecurr);
2412 }
Andy Whitcrofta1080bf2008-10-15 22:02:25 -07002413# case and default should not have general statements after them
2414 if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
2415 $line !~ /\G(?:
Andy Whitcroft3fef12d2008-10-15 22:02:36 -07002416 (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
Andy Whitcrofta1080bf2008-10-15 22:02:25 -07002417 \s*return\s+
2418 )/xg)
2419 {
2420 ERROR("trailing statements should be on next line\n" . $herecurr);
2421 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002422
2423 # Check for }<nl>else {, these must be at the same
2424 # indent level to be relevant to each other.
2425 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
2426 $previndent == $indent) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002427 ERROR("else should follow close brace '}'\n" . $hereprev);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002428 }
2429
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002430 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
2431 $previndent == $indent) {
2432 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
2433
2434 # Find out what is on the end of the line after the
2435 # conditional.
Andy Whitcroft773647a2008-03-28 14:15:58 -07002436 substr($s, 0, length($c), '');
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08002437 $s =~ s/\n.*//g;
2438
2439 if ($s =~ /^\s*;/) {
2440 ERROR("while should follow close brace '}'\n" . $hereprev);
2441 }
2442 }
2443
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002444#studly caps, commented out until figure out how to distinguish between use of existing and adding new
2445# if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
2446# print "No studly caps, use _\n";
2447# print "$herecurr";
2448# $clean = 0;
2449# }
2450
2451#no spaces allowed after \ in define
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002452 if ($line=~/\#\s*define.*\\\s$/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002453 WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002454 }
2455
Andy Whitcroft653d4872007-06-23 17:16:34 -07002456#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002457 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
Andy Whitcrofte09dec42008-10-15 22:02:20 -07002458 my $file = "$1.h";
2459 my $checkfile = "include/linux/$file";
2460 if (-f "$root/$checkfile" &&
2461 $realfile ne $checkfile &&
Wolfram Sang7840a942010-08-09 17:20:57 -07002462 $1 !~ /$allowed_asm_includes/)
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002463 {
Andy Whitcrofte09dec42008-10-15 22:02:20 -07002464 if ($realfile =~ m{^arch/}) {
2465 CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2466 } else {
2467 WARN("Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2468 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002469 }
2470 }
2471
Andy Whitcroft653d4872007-06-23 17:16:34 -07002472# multi-statement macros should be enclosed in a do while loop, grab the
2473# first statement and ensure its the whole macro if its not enclosed
Andy Whitcroftcf655042008-03-04 14:28:20 -08002474# in a known good container
Andy Whitcroftb8f96a32008-07-23 21:29:07 -07002475 if ($realfile !~ m@/vmlinux.lds.h$@ &&
2476 $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07002477 my $ln = $linenr;
2478 my $cnt = $realcnt;
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002479 my ($off, $dstat, $dcond, $rest);
2480 my $ctx = '';
Andy Whitcroft653d4872007-06-23 17:16:34 -07002481
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002482 my $args = defined($1);
2483
2484 # Find the end of the macro and limit our statement
2485 # search to that.
2486 while ($cnt > 0 && defined $lines[$ln - 1] &&
2487 $lines[$ln - 1] =~ /^(?:-|..*\\$)/)
2488 {
2489 $ctx .= $rawlines[$ln - 1] . "\n";
Andy Whitcrofta3bb97a2008-07-23 21:29:00 -07002490 $cnt-- if ($lines[$ln - 1] !~ /^-/);
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002491 $ln++;
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07002492 }
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002493 $ctx .= $rawlines[$ln - 1];
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002494
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002495 ($dstat, $dcond, $ln, $cnt, $off) =
2496 ctx_statement_block($linenr, $ln - $linenr + 1, 0);
2497 #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
Andy Whitcrofta3bb97a2008-07-23 21:29:00 -07002498 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002499
2500 # Extract the remainder of the define (if any) and
2501 # rip off surrounding spaces, and trailing \'s.
2502 $rest = '';
Andy Whitcroft636d1402008-10-15 22:02:18 -07002503 while ($off != 0 || ($cnt > 0 && $rest =~ /\\\s*$/)) {
2504 #print "ADDING cnt<$cnt> $off <" . substr($lines[$ln - 1], $off) . "> rest<$rest>\n";
Andy Whitcrofta3bb97a2008-07-23 21:29:00 -07002505 if ($off != 0 || $lines[$ln - 1] !~ /^-/) {
2506 $rest .= substr($lines[$ln - 1], $off) . "\n";
2507 $cnt--;
2508 }
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002509 $ln++;
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002510 $off = 0;
2511 }
2512 $rest =~ s/\\\n.//g;
2513 $rest =~ s/^\s*//s;
2514 $rest =~ s/\s*$//s;
2515
2516 # Clean up the original statement.
2517 if ($args) {
2518 substr($dstat, 0, length($dcond), '');
2519 } else {
2520 $dstat =~ s/^.\s*\#\s*define\s+$Ident\s*//;
2521 }
Andy Whitcroft292f1a92008-07-23 21:29:11 -07002522 $dstat =~ s/$;//g;
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002523 $dstat =~ s/\\\n.//g;
2524 $dstat =~ s/^\s*//s;
2525 $dstat =~ s/\s*$//s;
2526
2527 # Flatten any parentheses and braces
Andy Whitcroftbf30d6e2008-10-15 22:02:33 -07002528 while ($dstat =~ s/\([^\(\)]*\)/1/ ||
2529 $dstat =~ s/\{[^\{\}]*\}/1/ ||
2530 $dstat =~ s/\[[^\{\}]*\]/1/)
2531 {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002532 }
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07002533
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002534 my $exceptions = qr{
2535 $Declare|
2536 module_param_named|
2537 MODULE_PARAM_DESC|
2538 DECLARE_PER_CPU|
2539 DEFINE_PER_CPU|
Andy Whitcroft383099f2009-01-06 14:41:18 -08002540 __typeof__\(|
Stefani Seibold22fd2d32010-03-05 13:43:52 -08002541 union|
2542 struct|
Andy Whitcroftea71a0a2009-09-21 17:04:38 -07002543 \.$Ident\s*=\s*|
2544 ^\"|\"$
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002545 }x;
Andy Whitcroft5eaa20b2010-10-26 14:23:18 -07002546 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
2547 if ($rest ne '' && $rest ne ',') {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002548 if ($rest !~ /while\s*\(/ &&
2549 $dstat !~ /$exceptions/)
2550 {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002551 ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002552 }
2553
2554 } elsif ($ctx !~ /;/) {
2555 if ($dstat ne '' &&
2556 $dstat !~ /^(?:$Ident|-?$Constant)$/ &&
2557 $dstat !~ /$exceptions/ &&
Andy Whitcroftb132e5d2008-10-15 22:02:31 -07002558 $dstat !~ /^\.$Ident\s*=/ &&
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002559 $dstat =~ /$Operators/)
2560 {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002561 ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07002562 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07002563 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002564 }
2565
Mike Frysinger080ba922009-01-06 14:41:25 -08002566# make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
2567# all assignments may have only one of the following with an assignment:
2568# .
2569# ALIGN(...)
2570# VMLINUX_SYMBOL(...)
2571 if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
2572 WARN("vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
2573 }
2574
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002575# check for redundant bracing round if etc
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002576 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
2577 my ($level, $endln, @chunks) =
Andy Whitcroftcf655042008-03-04 14:28:20 -08002578 ctx_statement_full($linenr, $realcnt, 1);
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002579 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
Andy Whitcroftcf655042008-03-04 14:28:20 -08002580 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
2581 if ($#chunks > 0 && $level == 0) {
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002582 my $allowed = 0;
2583 my $seen = 0;
Andy Whitcroft773647a2008-03-28 14:15:58 -07002584 my $herectx = $here . "\n";
Andy Whitcroftcf655042008-03-04 14:28:20 -08002585 my $ln = $linenr - 1;
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002586 for my $chunk (@chunks) {
2587 my ($cond, $block) = @{$chunk};
2588
Andy Whitcroft773647a2008-03-28 14:15:58 -07002589 # If the condition carries leading newlines, then count those as offsets.
2590 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
2591 my $offset = statement_rawlines($whitespace) - 1;
2592
2593 #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
2594
2595 # We have looked at and allowed this specific line.
2596 $suppress_ifbraces{$ln + $offset} = 1;
2597
2598 $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
Andy Whitcroftcf655042008-03-04 14:28:20 -08002599 $ln += statement_rawlines($block) - 1;
2600
Andy Whitcroft773647a2008-03-28 14:15:58 -07002601 substr($block, 0, length($cond), '');
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002602
2603 $seen++ if ($block =~ /^\s*{/);
2604
Andy Whitcroftcf655042008-03-04 14:28:20 -08002605 #print "cond<$cond> block<$block> allowed<$allowed>\n";
2606 if (statement_lines($cond) > 1) {
2607 #print "APW: ALLOWED: cond<$cond>\n";
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002608 $allowed = 1;
2609 }
2610 if ($block =~/\b(?:if|for|while)\b/) {
Andy Whitcroftcf655042008-03-04 14:28:20 -08002611 #print "APW: ALLOWED: block<$block>\n";
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002612 $allowed = 1;
2613 }
Andy Whitcroftcf655042008-03-04 14:28:20 -08002614 if (statement_block_size($block) > 1) {
2615 #print "APW: ALLOWED: lines block<$block>\n";
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002616 $allowed = 1;
2617 }
2618 }
2619 if ($seen && !$allowed) {
Andy Whitcroftcf655042008-03-04 14:28:20 -08002620 WARN("braces {} are not necessary for any arm of this statement\n" . $herectx);
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002621 }
2622 }
2623 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07002624 if (!defined $suppress_ifbraces{$linenr - 1} &&
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002625 $line =~ /\b(if|while|for|else)\b/) {
Andy Whitcroftcf655042008-03-04 14:28:20 -08002626 my $allowed = 0;
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002627
Andy Whitcroftcf655042008-03-04 14:28:20 -08002628 # Check the pre-context.
2629 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
2630 #print "APW: ALLOWED: pre<$1>\n";
2631 $allowed = 1;
2632 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07002633
2634 my ($level, $endln, @chunks) =
2635 ctx_statement_full($linenr, $realcnt, $-[0]);
2636
Andy Whitcroftcf655042008-03-04 14:28:20 -08002637 # Check the condition.
2638 my ($cond, $block) = @{$chunks[0]};
Andy Whitcroft773647a2008-03-28 14:15:58 -07002639 #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
Andy Whitcroftcf655042008-03-04 14:28:20 -08002640 if (defined $cond) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002641 substr($block, 0, length($cond), '');
Andy Whitcroftcf655042008-03-04 14:28:20 -08002642 }
2643 if (statement_lines($cond) > 1) {
2644 #print "APW: ALLOWED: cond<$cond>\n";
2645 $allowed = 1;
2646 }
2647 if ($block =~/\b(?:if|for|while)\b/) {
2648 #print "APW: ALLOWED: block<$block>\n";
2649 $allowed = 1;
2650 }
2651 if (statement_block_size($block) > 1) {
2652 #print "APW: ALLOWED: lines block<$block>\n";
2653 $allowed = 1;
2654 }
2655 # Check the post-context.
2656 if (defined $chunks[1]) {
2657 my ($cond, $block) = @{$chunks[1]};
2658 if (defined $cond) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002659 substr($block, 0, length($cond), '');
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002660 }
Andy Whitcroftcf655042008-03-04 14:28:20 -08002661 if ($block =~ /^\s*\{/) {
2662 #print "APW: ALLOWED: chunk-1 block<$block>\n";
2663 $allowed = 1;
2664 }
2665 }
2666 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
2667 my $herectx = $here . "\n";;
Andy Whitcroftf0556632008-10-15 22:02:23 -07002668 my $cnt = statement_rawlines($block);
Andy Whitcroftcf655042008-03-04 14:28:20 -08002669
Andy Whitcroftf0556632008-10-15 22:02:23 -07002670 for (my $n = 0; $n < $cnt; $n++) {
2671 $herectx .= raw_line($linenr, $n) . "\n";;
Andy Whitcroftcf655042008-03-04 14:28:20 -08002672 }
2673
2674 WARN("braces {} are not necessary for single statement blocks\n" . $herectx);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002675 }
2676 }
2677
Andy Whitcroft653d4872007-06-23 17:16:34 -07002678# don't include deprecated include files (uses RAW line)
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002679 for my $inc (@dep_includes) {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002680 if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002681 ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002682 }
2683 }
2684
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002685# don't use deprecated functions
2686 for my $func (@dep_functions) {
Andy Whitcroft00df3442007-06-08 13:47:06 -07002687 if ($line =~ /\b$func\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002688 ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002689 }
2690 }
2691
2692# no volatiles please
Andy Whitcroft6c72ffa2007-10-18 03:05:08 -07002693 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
2694 if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002695 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002696 }
2697
Andy Whitcroft00df3442007-06-08 13:47:06 -07002698# warn about #if 0
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002699 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002700 CHK("if this code is redundant consider removing it\n" .
2701 $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002702 }
2703
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002704# check for needless kfree() checks
2705 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2706 my $expr = $1;
2707 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
Wolfram Sang3c232142008-07-23 21:29:05 -07002708 WARN("kfree(NULL) is safe this check is probably not required\n" . $hereprev);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002709 }
2710 }
Greg Kroah-Hartman4c432a82008-07-23 21:29:04 -07002711# check for needless usb_free_urb() checks
2712 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2713 my $expr = $1;
2714 if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) {
2715 WARN("usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev);
2716 }
2717 }
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002718
Patrick Pannuto1a15a252010-08-09 17:21:01 -07002719# prefer usleep_range over udelay
2720 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
2721 # ignore udelay's < 10, however
2722 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
2723 CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
2724 }
2725 }
2726
Patrick Pannuto09ef8722010-08-09 17:21:02 -07002727# warn about unexpectedly long msleep's
2728 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
2729 if ($1 < 20) {
2730 WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
2731 }
2732 }
2733
Andy Whitcroft00df3442007-06-08 13:47:06 -07002734# warn about #ifdefs in C files
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002735# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
Andy Whitcroft00df3442007-06-08 13:47:06 -07002736# print "#ifdef in C files should be avoided\n";
2737# print "$herecurr";
2738# $clean = 0;
2739# }
2740
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002741# warn about spacing in #ifdefs
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002742 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07002743 ERROR("exactly one space required after that #$1\n" . $herecurr);
2744 }
2745
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002746# check for spinlock_t definitions without a comment.
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002747 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
2748 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002749 my $which = $1;
2750 if (!ctx_has_comment($first_line, $linenr)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002751 CHK("$1 definition without comment\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002752 }
2753 }
2754# check for memory barriers without a comment.
2755 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
2756 if (!ctx_has_comment($first_line, $linenr)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002757 CHK("memory barrier without comment\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07002758 }
2759 }
2760# check of hardware specific defines
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002761 if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002762 CHK("architecture specific defines should be avoided\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002763 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07002764
Tobias Klauserd4977c72010-05-24 14:33:30 -07002765# Check that the storage class is at the beginning of a declaration
2766 if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
2767 WARN("storage class should be at the beginning of the declaration\n" . $herecurr)
2768 }
2769
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002770# check the location of the inline attribute, that it is between
2771# storage class and type.
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002772 if ($line =~ /\b$Type\s+$Inline\b/ ||
2773 $line =~ /\b$Inline\s+$Storage\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002774 ERROR("inline keyword should sit between storage class and type\n" . $herecurr);
2775 }
2776
Andy Whitcroft8905a672007-11-28 16:21:06 -08002777# Check for __inline__ and __inline, prefer inline
2778 if ($line =~ /\b(__inline__|__inline)\b/) {
2779 WARN("plain inline is preferred over $1\n" . $herecurr);
2780 }
2781
Joe Perches3d130fd2011-01-12 17:00:00 -08002782# Check for __attribute__ packed, prefer __packed
2783 if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
2784 WARN("__packed is preferred over __attribute__((packed))\n" . $herecurr);
2785 }
2786
Joe Perches8f53a9b2010-03-05 13:43:48 -08002787# check for sizeof(&)
2788 if ($line =~ /\bsizeof\s*\(\s*\&/) {
2789 WARN("sizeof(& should be avoided\n" . $herecurr);
2790 }
2791
Joe Perches428e2fd2011-05-24 17:13:39 -07002792# check for line continuations in quoted strings with odd counts of "
2793 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
2794 WARN("Avoid line continuations in quoted strings\n" . $herecurr);
2795 }
2796
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002797# check for new externs in .c files.
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002798 if ($realfile =~ /\.c$/ && defined $stat &&
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002799 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002800 {
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002801 my $function_name = $1;
2802 my $paren_space = $2;
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002803
2804 my $s = $stat;
2805 if (defined $cond) {
2806 substr($s, 0, length($cond), '');
2807 }
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002808 if ($s =~ /^\s*;/ &&
2809 $function_name ne 'uninitialized_var')
2810 {
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002811 WARN("externs should be avoided in .c files\n" . $herecurr);
2812 }
2813
2814 if ($paren_space =~ /\n/) {
2815 WARN("arguments for function declarations should follow identifier\n" . $herecurr);
2816 }
Andy Whitcroft9c9ba342008-04-29 00:59:33 -07002817
2818 } elsif ($realfile =~ /\.c$/ && defined $stat &&
2819 $stat =~ /^.\s*extern\s+/)
2820 {
2821 WARN("externs should be avoided in .c files\n" . $herecurr);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002822 }
2823
2824# checks for new __setup's
2825 if ($rawline =~ /\b__setup\("([^"]*)"/) {
2826 my $name = $1;
2827
2828 if (!grep(/$name/, @setup_docs)) {
2829 CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
2830 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07002831 }
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002832
2833# check for pointless casting of kmalloc return
Joe Perchescaf2a542011-01-12 16:59:56 -08002834 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07002835 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
2836 }
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002837
Joe Perchescaf2a542011-01-12 16:59:56 -08002838# check for multiple semicolons
2839 if ($line =~ /;\s*;\s*$/) {
2840 WARN("Statements terminations use 1 semicolon\n" . $herecurr);
2841 }
2842
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002843# check for gcc specific __FUNCTION__
2844 if ($line =~ /__FUNCTION__/) {
2845 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
2846 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07002847
Thomas Gleixner4882720b2010-09-07 14:34:01 +00002848# check for semaphores initialized locked
2849 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
Andy Whitcroft773647a2008-03-28 14:15:58 -07002850 WARN("consider using a completion\n" . $herecurr);
Peter Zijlstra1704f472010-03-19 01:37:42 +01002851
Andy Whitcroft773647a2008-03-28 14:15:58 -07002852 }
Alexey Dobriyan33ee3b22011-03-22 16:34:40 -07002853# recommend kstrto* over simple_strto*
Andy Whitcroft773647a2008-03-28 14:15:58 -07002854 if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
Alexey Dobriyan33ee3b22011-03-22 16:34:40 -07002855 WARN("consider using kstrto* in preference to simple_$1\n" . $herecurr);
Andy Whitcroft773647a2008-03-28 14:15:58 -07002856 }
Michael Ellermanf3db6632008-07-23 21:28:57 -07002857# check for __initcall(), use device_initcall() explicitly please
2858 if ($line =~ /^.\s*__initcall\s*\(/) {
2859 WARN("please use device_initcall() instead of __initcall()\n" . $herecurr);
2860 }
Emese Revfy79404842010-03-05 13:43:53 -08002861# check for various ops structs, ensure they are const.
2862 my $struct_ops = qr{acpi_dock_ops|
2863 address_space_operations|
2864 backlight_ops|
2865 block_device_operations|
2866 dentry_operations|
2867 dev_pm_ops|
2868 dma_map_ops|
2869 extent_io_ops|
2870 file_lock_operations|
2871 file_operations|
2872 hv_ops|
2873 ide_dma_ops|
2874 intel_dvo_dev_ops|
2875 item_operations|
2876 iwl_ops|
2877 kgdb_arch|
2878 kgdb_io|
2879 kset_uevent_ops|
2880 lock_manager_operations|
2881 microcode_ops|
2882 mtrr_ops|
2883 neigh_ops|
2884 nlmsvc_binding|
2885 pci_raw_ops|
2886 pipe_buf_operations|
2887 platform_hibernation_ops|
2888 platform_suspend_ops|
2889 proto_ops|
2890 rpc_pipe_ops|
2891 seq_operations|
2892 snd_ac97_build_ops|
2893 soc_pcmcia_socket_ops|
2894 stacktrace_ops|
2895 sysfs_ops|
2896 tty_operations|
2897 usb_mon_operations|
2898 wd_ops}x;
Andy Whitcroft6903ffb2009-01-15 13:51:07 -08002899 if ($line !~ /\bconst\b/ &&
Emese Revfy79404842010-03-05 13:43:53 -08002900 $line =~ /\bstruct\s+($struct_ops)\b/) {
Andy Whitcroft6903ffb2009-01-15 13:51:07 -08002901 WARN("struct $1 should normally be const\n" .
2902 $herecurr);
Andy Whitcroft2b6db5c2009-01-06 14:41:29 -08002903 }
Andy Whitcroft773647a2008-03-28 14:15:58 -07002904
2905# use of NR_CPUS is usually wrong
2906# ignore definitions of NR_CPUS and usage to define arrays as likely right
2907 if ($line =~ /\bNR_CPUS\b/ &&
Andy Whitcroftc45dcab2008-06-05 22:46:01 -07002908 $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
2909 $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
Andy Whitcroft171ae1a2008-04-29 00:59:32 -07002910 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
2911 $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
2912 $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
Andy Whitcroft773647a2008-03-28 14:15:58 -07002913 {
2914 WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
2915 }
Andy Whitcroft9c9ba342008-04-29 00:59:33 -07002916
2917# check for %L{u,d,i} in strings
2918 my $string;
2919 while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
2920 $string = substr($rawline, $-[1], $+[1] - $-[1]);
Andy Whitcroft2a1bc5d2008-10-15 22:02:23 -07002921 $string =~ s/%%/__/g;
Andy Whitcroft9c9ba342008-04-29 00:59:33 -07002922 if ($string =~ /(?<!%)%L[udi]/) {
2923 WARN("\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
2924 last;
2925 }
2926 }
Andy Whitcroft691d77b2009-01-06 14:41:16 -08002927
2928# whine mightly about in_atomic
2929 if ($line =~ /\bin_atomic\s*\(/) {
2930 if ($realfile =~ m@^drivers/@) {
2931 ERROR("do not use in_atomic in drivers\n" . $herecurr);
Andy Whitcroftf4a87732009-02-27 14:03:05 -08002932 } elsif ($realfile !~ m@^kernel/@) {
Andy Whitcroft691d77b2009-01-06 14:41:16 -08002933 WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
2934 }
2935 }
Peter Zijlstra1704f472010-03-19 01:37:42 +01002936
2937# check for lockdep_set_novalidate_class
2938 if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
2939 $line =~ /__lockdep_no_validate__\s*\)/ ) {
2940 if ($realfile !~ m@^kernel/lockdep@ &&
2941 $realfile !~ m@^include/linux/lockdep@ &&
2942 $realfile !~ m@^drivers/base/core@) {
2943 ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
2944 }
2945 }
Dave Jones88f88312011-01-12 16:59:59 -08002946
2947 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
2948 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
2949 WARN("Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
2950 }
Dave Jones309c00c2011-03-22 16:34:44 -07002951
2952 # Check for memset with swapped arguments
2953 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
2954 ERROR("memset size is 3rd argument, not the second.\n" . $herecurr);
2955 }
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002956 }
2957
2958 # If we have no input at all, then there is nothing to report on
2959 # so just keep quiet.
2960 if ($#rawlines == -1) {
2961 exit(0);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002962 }
2963
Andy Whitcroft8905a672007-11-28 16:21:06 -08002964 # In mailback mode only produce a report in the negative, for
2965 # things that appear to be patches.
2966 if ($mailback && ($clean == 1 || !$is_patch)) {
2967 exit(0);
2968 }
2969
2970 # This is not a patch, and we are are in 'no-patch' mode so
2971 # just keep quiet.
2972 if (!$chk_patch && !$is_patch) {
2973 exit(0);
2974 }
2975
2976 if (!$is_patch) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002977 ERROR("Does not appear to be a unified-diff format patch\n");
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002978 }
2979 if ($is_patch && $chk_signoff && $signoff == 0) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07002980 ERROR("Missing Signed-off-by: line(s)\n");
Andy Whitcroft0a920b52007-06-01 00:46:48 -07002981 }
2982
Andy Whitcroft8905a672007-11-28 16:21:06 -08002983 print report_dump();
Andy Whitcroft13214ad2008-02-08 04:22:03 -08002984 if ($summary && !($clean == 1 && $quiet == 1)) {
2985 print "$filename " if ($summary_file);
Andy Whitcroft8905a672007-11-28 16:21:06 -08002986 print "total: $cnt_error errors, $cnt_warn warnings, " .
2987 (($check)? "$cnt_chk checks, " : "") .
2988 "$cnt_lines lines checked\n";
2989 print "\n" if ($quiet == 0);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07002990 }
Andy Whitcroft8905a672007-11-28 16:21:06 -08002991
Andy Whitcroftd2c0a232010-10-26 14:23:12 -07002992 if ($quiet == 0) {
2993 # If there were whitespace errors which cleanpatch can fix
2994 # then suggest that.
2995 if ($rpt_cleaners) {
2996 print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
2997 print " scripts/cleanfile\n\n";
Mike Frysingerb0781212011-03-22 16:34:43 -07002998 $rpt_cleaners = 0;
Andy Whitcroftd2c0a232010-10-26 14:23:12 -07002999 }
3000 }
3001
Andy Whitcroft0a920b52007-06-01 00:46:48 -07003002 if ($clean == 1 && $quiet == 0) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08003003 print "$vname has no obvious style problems and is ready for submission.\n"
Andy Whitcroft0a920b52007-06-01 00:46:48 -07003004 }
3005 if ($clean == 0 && $quiet == 0) {
Andy Whitcroftc2fdda02008-02-08 04:20:54 -08003006 print "$vname has style problems, please review. If any of these errors\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -07003007 print "are false positives report them to the maintainer, see\n";
3008 print "CHECKPATCH in MAINTAINERS.\n";
3009 }
Andy Whitcroft13214ad2008-02-08 04:22:03 -08003010
Andy Whitcroft0a920b52007-06-01 00:46:48 -07003011 return $clean;
3012}