blob: 59ad83caa210dd5d31af0bb76aa234e3dad0fca6 [file] [log] [blame]
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001#!/usr/bin/perl -w
2# (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit)
Andy Whitcroft00df3442007-06-08 13:47:06 -07003# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
Andy Whitcroft0a920b52007-06-01 00:46:48 -07004# (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc)
5# Licensed under the terms of the GNU GPL License version 2
6
7use strict;
8
9my $P = $0;
Andy Whitcroft00df3442007-06-08 13:47:06 -070010$P =~ s@.*/@@g;
Andy Whitcroft0a920b52007-06-01 00:46:48 -070011
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -070012my $V = '0.10';
Andy Whitcroft0a920b52007-06-01 00:46:48 -070013
14use Getopt::Long qw(:config no_auto_abbrev);
15
16my $quiet = 0;
17my $tree = 1;
18my $chk_signoff = 1;
19my $chk_patch = 1;
Andy Whitcroft653d4872007-06-23 17:16:34 -070020my $tst_type = 0;
Andy Whitcroft0a920b52007-06-01 00:46:48 -070021GetOptions(
22 'q|quiet' => \$quiet,
23 'tree!' => \$tree,
24 'signoff!' => \$chk_signoff,
25 'patch!' => \$chk_patch,
Andy Whitcroft653d4872007-06-23 17:16:34 -070026 'test-type!' => \$tst_type,
Andy Whitcroft0a920b52007-06-01 00:46:48 -070027) or exit;
28
29my $exit = 0;
30
31if ($#ARGV < 0) {
Andy Whitcroft00df3442007-06-08 13:47:06 -070032 print "usage: $P [options] patchfile\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -070033 print "version: $V\n";
34 print "options: -q => quiet\n";
35 print " --no-tree => run without a kernel tree\n";
36 exit(1);
37}
38
39if ($tree && !top_of_kernel_tree()) {
40 print "Must be run from the top-level dir. of a kernel tree\n";
41 exit(2);
42}
43
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -070044my @dep_includes = ();
45my @dep_functions = ();
Andy Whitcroft0a920b52007-06-01 00:46:48 -070046my $removal = 'Documentation/feature-removal-schedule.txt';
47if ($tree && -f $removal) {
48 open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n";
49 while (<REMOVE>) {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -070050 if (/^Check:\s+(.*\S)/) {
51 for my $entry (split(/[, ]+/, $1)) {
52 if ($entry =~ m@include/(.*)@) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -070053 push(@dep_includes, $1);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -070054
Andy Whitcroftf0a594c2007-07-19 01:48:34 -070055 } elsif ($entry !~ m@/@) {
56 push(@dep_functions, $entry);
57 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -070058 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -070059 }
60 }
61}
62
Andy Whitcroft00df3442007-06-08 13:47:06 -070063my @rawlines = ();
Andy Whitcroft0a920b52007-06-01 00:46:48 -070064while (<>) {
65 chomp;
Andy Whitcroft00df3442007-06-08 13:47:06 -070066 push(@rawlines, $_);
Andy Whitcroft0a920b52007-06-01 00:46:48 -070067 if (eof(ARGV)) {
Andy Whitcroft00df3442007-06-08 13:47:06 -070068 if (!process($ARGV, @rawlines)) {
Andy Whitcroft0a920b52007-06-01 00:46:48 -070069 $exit = 1;
70 }
Andy Whitcroft00df3442007-06-08 13:47:06 -070071 @rawlines = ();
Andy Whitcroft0a920b52007-06-01 00:46:48 -070072 }
73}
74
75exit($exit);
76
77sub top_of_kernel_tree {
78 if ((-f "COPYING") && (-f "CREDITS") && (-f "Kbuild") &&
79 (-f "MAINTAINERS") && (-f "Makefile") && (-f "README") &&
80 (-d "Documentation") && (-d "arch") && (-d "include") &&
81 (-d "drivers") && (-d "fs") && (-d "init") && (-d "ipc") &&
82 (-d "kernel") && (-d "lib") && (-d "scripts")) {
83 return 1;
84 }
85 return 0;
86}
87
88sub expand_tabs {
89 my ($str) = @_;
90
91 my $res = '';
92 my $n = 0;
93 for my $c (split(//, $str)) {
94 if ($c eq "\t") {
95 $res .= ' ';
96 $n++;
97 for (; ($n % 8) != 0; $n++) {
98 $res .= ' ';
99 }
100 next;
101 }
102 $res .= $c;
103 $n++;
104 }
105
106 return $res;
107}
108
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700109sub line_stats {
110 my ($line) = @_;
111
112 # Drop the diff line leader and expand tabs
113 $line =~ s/^.//;
114 $line = expand_tabs($line);
115
116 # Pick the indent from the front of the line.
117 my ($white) = ($line =~ /^(\s*)/);
118
119 return (length($line), length($white));
120}
121
Andy Whitcroft00df3442007-06-08 13:47:06 -0700122sub sanitise_line {
123 my ($line) = @_;
124
125 my $res = '';
126 my $l = '';
127
128 my $quote = '';
129
130 foreach my $c (split(//, $line)) {
131 if ($l ne "\\" && ($c eq "'" || $c eq '"')) {
132 if ($quote eq '') {
133 $quote = $c;
134 $res .= $c;
135 $l = $c;
136 next;
137 } elsif ($quote eq $c) {
138 $quote = '';
139 }
140 }
141 if ($quote && $c ne "\t") {
142 $res .= "X";
143 } else {
144 $res .= $c;
145 }
146
147 $l = $c;
148 }
149
150 return $res;
151}
152
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700153sub ctx_block_get {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700154 my ($linenr, $remain, $outer, $open, $close, $off) = @_;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700155 my $line;
156 my $start = $linenr - 1;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700157 my $blk = '';
158 my @o;
159 my @c;
160 my @res = ();
161
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700162 my $level = 0;
Andy Whitcroft00df3442007-06-08 13:47:06 -0700163 for ($line = $start; $remain > 0; $line++) {
164 next if ($rawlines[$line] =~ /^-/);
165 $remain--;
166
167 $blk .= $rawlines[$line];
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700168 foreach my $c (split(//, $rawlines[$line])) {
169 ##print "C<$c>L<$level><$open$close>O<$off>\n";
170 if ($off > 0) {
171 $off--;
172 next;
173 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700174
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700175 if ($c eq $close && $level > 0) {
176 $level--;
177 last if ($level == 0);
178 } elsif ($c eq $open) {
179 $level++;
180 }
181 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700182
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700183 if (!$outer || $level <= 1) {
Andy Whitcroft00df3442007-06-08 13:47:06 -0700184 push(@res, $rawlines[$line]);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700185 }
186
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700187 last if ($level == 0);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700188 }
189
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700190 return ($level, @res);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700191}
192sub ctx_block_outer {
193 my ($linenr, $remain) = @_;
194
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700195 my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
196 return @r;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700197}
198sub ctx_block {
199 my ($linenr, $remain) = @_;
200
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700201 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
202 return @r;
Andy Whitcroft653d4872007-06-23 17:16:34 -0700203}
204sub ctx_statement {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700205 my ($linenr, $remain, $off) = @_;
206
207 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
208 return @r;
209}
210sub ctx_block_level {
Andy Whitcroft653d4872007-06-23 17:16:34 -0700211 my ($linenr, $remain) = @_;
212
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700213 return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700214}
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700215sub ctx_statement_level {
216 my ($linenr, $remain, $off) = @_;
217
218 return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
219}
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700220
221sub ctx_locate_comment {
222 my ($first_line, $end_line) = @_;
223
224 # Catch a comment on the end of the line itself.
Andy Whitcroft00df3442007-06-08 13:47:06 -0700225 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700226 return $current_comment if (defined $current_comment);
227
228 # Look through the context and try and figure out if there is a
229 # comment.
230 my $in_comment = 0;
231 $current_comment = '';
232 for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
Andy Whitcroft00df3442007-06-08 13:47:06 -0700233 my $line = $rawlines[$linenr - 1];
234 #warn " $line\n";
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700235 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
236 $in_comment = 1;
237 }
238 if ($line =~ m@/\*@) {
239 $in_comment = 1;
240 }
241 if (!$in_comment && $current_comment ne '') {
242 $current_comment = '';
243 }
244 $current_comment .= $line . "\n" if ($in_comment);
245 if ($line =~ m@\*/@) {
246 $in_comment = 0;
247 }
248 }
249
250 chomp($current_comment);
251 return($current_comment);
252}
253sub ctx_has_comment {
254 my ($first_line, $end_line) = @_;
255 my $cmt = ctx_locate_comment($first_line, $end_line);
256
Andy Whitcroft00df3442007-06-08 13:47:06 -0700257 ##print "LINE: $rawlines[$end_line - 1 ]\n";
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700258 ##print "CMMT: $cmt\n";
259
260 return ($cmt ne '');
261}
262
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700263sub ctx_expr_before {
264 my ($line) = @_;
265
266 ##print "CHECK<$line>\n";
267
268 my $pos = length($line) - 1;
269 my $count = 0;
270 my $c;
271
272 for (; $pos >= 0; $pos--) {
273 $c = substr($line, $pos, 1);
274 ##print "CHECK: c<$c> count<$count>\n";
275 if ($c eq ')') {
276 $count++;
277 } elsif ($c eq '(') {
278 last if (--$count == 0);
279 }
280 }
281
282 ##print "CHECK: result<" . substr($line, 0, $pos) . ">\n";
283
284 return substr($line, 0, $pos);
285}
286
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700287sub cat_vet {
288 my ($vet) = @_;
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700289 my ($res, $coded);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700290
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700291 $res = '';
292 while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]])/g) {
293 $coded = sprintf("^%c", unpack('C', $2) + 64);
294 $res .= $1 . $coded;
295 }
296 $res =~ s/$/\$/;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700297
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700298 return $res;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700299}
300
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700301my @report = ();
302sub report {
303 push(@report, $_[0]);
304}
305sub report_dump {
306 @report;
307}
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700308sub ERROR {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700309 report("ERROR: $_[0]\n");
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700310 our $clean = 0;
311}
312sub WARN {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700313 report("WARNING: $_[0]\n");
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700314 our $clean = 0;
315}
316sub CHK {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700317 report("CHECK: $_[0]\n");
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700318 our $clean = 0;
319}
320
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700321sub process {
322 my $filename = shift;
323 my @lines = @_;
324
325 my $linenr=0;
326 my $prevline="";
327 my $stashline="";
328
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700329 my $length;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700330 my $indent;
331 my $previndent=0;
332 my $stashindent=0;
333
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700334 our $clean = 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700335 my $signoff = 0;
336 my $is_patch = 0;
337
338 # Trace the real file/line as we go.
339 my $realfile = '';
340 my $realline = 0;
341 my $realcnt = 0;
342 my $here = '';
343 my $in_comment = 0;
344 my $first_line = 0;
345
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700346 my $Ident = qr{[A-Za-z\d_]+};
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700347 my $Storage = qr{extern|static|asmlinkage};
348 my $Sparse = qr{
349 __user|
350 __kernel|
351 __force|
352 __iomem|
353 __must_check|
354 __init_refok|
355 fastcall
356 }x;
357 my $Inline = qr{inline|__always_inline|noinline};
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700358 my $NonptrType = qr{
359 \b
360 (?:const\s+)?
361 (?:unsigned\s+)?
362 (?:
363 void|
364 char|
365 short|
366 int|
367 long|
368 unsigned|
369 float|
370 double|
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700371 bool|
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700372 long\s+int|
373 long\s+long|
374 long\s+long\s+int|
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700375 u8|u16|u32|u64|
376 s8|s16|s32|s64|
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700377 struct\s+$Ident|
378 union\s+$Ident|
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700379 enum\s+$Ident|
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700380 ${Ident}_t
381 )
382 (?:\s+$Sparse)*
383 \b
384 }x;
385 my $Type = qr{
386 \b$NonptrType\b
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700387 (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)?
388 (?:\s+$Sparse)*
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700389 }x;
390 my $Declare = qr{(?:$Storage\s+)?$Type};
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700391 my $Attribute = qr{
392 const|
393 __read_mostly|
394 __(?:mem|cpu|dev|)(?:initdata|init)
395 }x;
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700396 my $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
397 my $Lval = qr{$Ident(?:$Member)*};
Andy Whitcroft653d4872007-06-23 17:16:34 -0700398
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700399 # Possible bare types.
400 my @bare = ();
401 my $Bare = $NonptrType;
402
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700403 # Pre-scan the patch looking for any __setup documentation.
404 my @setup_docs = ();
405 my $setup_docs = 0;
406 foreach my $line (@lines) {
407 if ($line=~/^\+\+\+\s+(\S+)/) {
408 $setup_docs = 0;
409 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
410 $setup_docs = 1;
411 }
412 next;
413 }
414
415 if ($setup_docs && $line =~ /^\+/) {
416 push(@setup_docs, $line);
417 }
418 }
419
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700420 foreach my $line (@lines) {
421 $linenr++;
422
Andy Whitcroft653d4872007-06-23 17:16:34 -0700423 my $rawline = $line;
424
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700425#extract the filename as it passes
426 if ($line=~/^\+\+\+\s+(\S+)/) {
427 $realfile=$1;
Andy Whitcroft00df3442007-06-08 13:47:06 -0700428 $realfile =~ s@^[^/]*/@@;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700429 $in_comment = 0;
430 next;
431 }
432#extract the line range in the file after the patch is applied
433 if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) {
434 $is_patch = 1;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700435 $first_line = $linenr + 1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700436 $in_comment = 0;
437 $realline=$1-1;
438 if (defined $2) {
439 $realcnt=$3+1;
440 } else {
441 $realcnt=1+1;
442 }
443 next;
444 }
445
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700446# track the line number as we move through the hunk, note that
447# new versions of GNU diff omit the leading space on completely
448# blank context lines so we need to count that too.
449 if ($line =~ /^( |\+|$)/) {
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700450 $realline++;
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700451 $realcnt-- if ($realcnt != 0);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700452
453 # track any sort of multi-line comment. Obviously if
454 # the added text or context do not include the whole
455 # comment we will not see it. Such is life.
456 #
457 # Guestimate if this is a continuing comment. If this
458 # is the start of a diff block and this line starts
459 # ' *' then it is very likely a comment.
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700460 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700461 $in_comment = 1;
462 }
463 if ($line =~ m@/\*@) {
464 $in_comment = 1;
465 }
466 if ($line =~ m@\*/@) {
467 $in_comment = 0;
468 }
469
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700470 # Measure the line length and indent.
471 ($length, $indent) = line_stats($line);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700472
473 # Track the previous line.
474 ($prevline, $stashline) = ($stashline, $line);
475 ($previndent, $stashindent) = ($stashindent, $indent);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700476 } elsif ($realcnt == 1) {
477 $realcnt--;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700478 }
479
480#make up the handle for any error we report on this line
Randy Dunlap389834b2007-06-08 13:47:03 -0700481 $here = "#$linenr: ";
482 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700483
Andy Whitcroft00df3442007-06-08 13:47:06 -0700484 my $hereline = "$here\n$line\n";
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700485 my $herecurr = "$here\n$line\n";
486 my $hereprev = "$here\n$prevline\n$line\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700487
488#check the patch for a signoff:
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700489 if ($line =~ /^\s*signed-off-by:/i) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700490 # This is a signoff, if ugly, so do not double report.
491 $signoff++;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700492 if (!($line =~ /^\s*Signed-off-by:/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700493 WARN("Signed-off-by: is the preferred form\n" .
494 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700495 }
496 if ($line =~ /^\s*signed-off-by:\S/i) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700497 WARN("need space after Signed-off-by:\n" .
498 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700499 }
500 }
501
Andy Whitcroft00df3442007-06-08 13:47:06 -0700502# Check for wrappage within a valid hunk of the file
503 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700504 ERROR("patch seems to be corrupt (line wrapped?)\n" .
505 $herecurr);
506 }
507
508# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
509 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
510 !($line =~ m/^(
511 [\x09\x0A\x0D\x20-\x7E] # ASCII
512 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
513 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
514 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
515 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
516 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
517 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
518 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
519 )*$/x )) {
520 ERROR("Invalid UTF-8\n" . $herecurr);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700521 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700522
Andy Whitcroft00df3442007-06-08 13:47:06 -0700523#ignore lines being removed
524 if ($line=~/^-/) {next;}
525
526# check we are in a valid source file if not then ignore this hunk
527 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700528
529#trailing whitespace
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700530 if ($line =~ /^\+.*\015/) {
531 my $herevet = "$here\n" . cat_vet($line) . "\n";
532 ERROR("DOS line endings\n" . $herevet);
533
534 } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700535 my $herevet = "$here\n" . cat_vet($line) . "\n";
536 ERROR("trailing whitespace\n" . $herevet);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700537 }
538#80 column limit
Andy Whitcroft00df3442007-06-08 13:47:06 -0700539 if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700540 WARN("line over 80 characters\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700541 }
542
543# check we are in a valid source file *.[hc] if not then ignore this hunk
544 next if ($realfile !~ /\.[hc]$/);
545
546# at the beginning of a line any tabs must come first and anything
547# more than 8 must use tabs.
548 if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700549 my $herevet = "$here\n" . cat_vet($line) . "\n";
550 ERROR("use tabs not spaces\n" . $herevet);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700551 }
552
Andy Whitcroft653d4872007-06-23 17:16:34 -0700553# Remove comments from the line before processing.
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700554 my $comment_edge = ($line =~ s@/\*.*\*/@@g) +
555 ($line =~ s@/\*.*@@) +
556 ($line =~ s@^(.).*\*/@$1@);
557
558# The rest of our checks refer specifically to C style
559# only apply those _outside_ comments. Only skip
560# lines in the middle of comments.
561 next if (!$comment_edge && $in_comment);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700562
Andy Whitcroft653d4872007-06-23 17:16:34 -0700563# Standardise the strings and chars within the input to simplify matching.
564 $line = sanitise_line($line);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700565
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700566# Check for potential 'bare' types
567 if ($realcnt &&
568 $line !~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?$Type\b/ &&
569 $line !~ /$Ident:\s*$/ &&
570 $line !~ /^.\s*$Ident\s*\(/ &&
571 ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?($Ident)\b/ ||
572 $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/)) {
573 my $possible = $1;
574 if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ &&
575 $possible ne 'goto' && $possible ne 'return' &&
576 $possible ne 'struct' && $possible ne 'enum' &&
577 $possible ne 'case' && $possible ne 'else' &&
578 $possible ne 'typedef') {
579 #print "POSSIBLE<$possible>\n";
580 push(@bare, $possible);
581 my $bare = join("|", @bare);
582 $Bare = qr{
583 \b(?:$bare)\b
584 (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)?
585 (?:\s+$Sparse)*
586 }x;
587 }
588 }
589
Andy Whitcroft653d4872007-06-23 17:16:34 -0700590#
591# Checks which may be anchored in the context.
592#
593
594# Check for switch () and associated case and default
595# statements should be at the same indent.
Andy Whitcroft00df3442007-06-08 13:47:06 -0700596 if ($line=~/\bswitch\s*\(.*\)/) {
597 my $err = '';
598 my $sep = '';
599 my @ctx = ctx_block_outer($linenr, $realcnt);
600 shift(@ctx);
601 for my $ctx (@ctx) {
602 my ($clen, $cindent) = line_stats($ctx);
603 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
604 $indent != $cindent) {
605 $err .= "$sep$ctx\n";
606 $sep = '';
607 } else {
608 $sep = "[...]\n";
609 }
610 }
611 if ($err ne '') {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700612 ERROR("switch and case should be at the same indent\n$hereline$err");
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700613 }
614 }
615
616# if/while/etc brace do not go on next line, unless defining a do while loop,
617# or if that brace on the next line is for something else
618 if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700619 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700620 my $ctx_ln = $linenr + $#ctx + 1;
621 my $ctx_cnt = $realcnt - $#ctx - 1;
622 my $ctx = join("\n", @ctx);
623
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700624 # Skip over any removed lines in the context following statement.
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700625 while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) {
626 $ctx_ln++;
627 $ctx_cnt--;
628 }
629 ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>";
630
631 if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700632 ERROR("That open brace { should be on the previous line\n" .
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700633 "$here\n$ctx\n$lines[$ctx_ln - 1]");
Andy Whitcroft00df3442007-06-08 13:47:06 -0700634 }
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700635 if ($level == 0 && $ctx =~ /\)\s*\;\s*$/ && defined $lines[$ctx_ln - 1]) {
636 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
637 if ($nindent > $indent) {
638 WARN("Trailing semicolon indicates no statements, indent implies otherwise\n" .
639 "$here\n$ctx\n$lines[$ctx_ln - 1]");
640 }
641 }
Andy Whitcroft00df3442007-06-08 13:47:06 -0700642 }
643
644#ignore lines not being added
645 if ($line=~/^[^\+]/) {next;}
646
Andy Whitcroft653d4872007-06-23 17:16:34 -0700647# TEST: allow direct testing of the type matcher.
648 if ($tst_type && $line =~ /^.$Declare$/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700649 ERROR("TEST: is type $Declare\n" . $herecurr);
Andy Whitcroft653d4872007-06-23 17:16:34 -0700650 next;
651 }
652
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700653# check for initialisation to aggregates open brace on the next line
654 if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ &&
655 $line =~ /^.\s*{/) {
656 ERROR("That open brace { should be on the previous line\n" . $hereprev);
657 }
658
Andy Whitcroft653d4872007-06-23 17:16:34 -0700659#
660# Checks which are anchored on the added line.
661#
662
663# check for malformed paths in #include statements (uses RAW line)
664 if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) {
665 my $path = $1;
666 if ($path =~ m{//}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700667 ERROR("malformed #include filename\n" .
668 $herecurr);
Andy Whitcroft653d4872007-06-23 17:16:34 -0700669 }
670 # Sanitise this special form of string.
671 $path = 'X' x length($path);
672 $line =~ s{\<.*\>}{<$path>};
673 }
Andy Whitcroft00df3442007-06-08 13:47:06 -0700674
675# no C99 // comments
676 if ($line =~ m{//}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700677 ERROR("do not use C99 // comments\n" . $herecurr);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700678 }
679 # Remove C99 comments.
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700680 $line =~ s@//.*@@;
681
682#EXPORT_SYMBOL should immediately follow its function closing }.
Andy Whitcroft653d4872007-06-23 17:16:34 -0700683 if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) ||
684 ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
685 my $name = $1;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700686 if (($prevline !~ /^}/) &&
687 ($prevline !~ /^\+}/) &&
Andy Whitcroft653d4872007-06-23 17:16:34 -0700688 ($prevline !~ /^ }/) &&
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700689 ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700690 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700691 }
692 }
693
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700694# check for external initialisers.
695 if ($line =~ /^.$Type\s*$Ident\s*=\s*(0|NULL);/) {
696 ERROR("do not initialise externals to 0 or NULL\n" .
697 $herecurr);
698 }
Andy Whitcroft653d4872007-06-23 17:16:34 -0700699# check for static initialisers.
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700700 if ($line =~ /\s*static\s.*=\s*(0|NULL);/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700701 ERROR("do not initialise statics to 0 or NULL\n" .
702 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700703 }
704
Andy Whitcroft653d4872007-06-23 17:16:34 -0700705# check for new typedefs, only function parameters and sparse annotations
706# make sense.
707 if ($line =~ /\btypedef\s/ &&
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700708 $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ &&
Andy Whitcroft653d4872007-06-23 17:16:34 -0700709 $line !~ /\b__bitwise(?:__|)\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700710 WARN("do not add new typedefs\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700711 }
712
713# * goes on variable not on type
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700714 if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700715 ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" .
716 $herecurr);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700717
718 } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700719 ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" .
720 $herecurr);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700721
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700722 } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700723 ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" .
724 $herecurr);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700725
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700726 } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700727 ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" .
728 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700729 }
730
731# # no BUG() or BUG_ON()
732# if ($line =~ /\b(BUG|BUG_ON)\b/) {
733# print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
734# print "$herecurr";
735# $clean = 0;
736# }
737
Andy Whitcroft00df3442007-06-08 13:47:06 -0700738# printk should use KERN_* levels. Note that follow on printk's on the
739# same line do not need a level, so we use the current block context
740# to try and find and validate the current printk. In summary the current
741# printk includes all preceeding printk's which have no newline on the end.
742# we assume the first bad printk is the one to report.
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700743 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
Andy Whitcroft00df3442007-06-08 13:47:06 -0700744 my $ok = 0;
745 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
746 #print "CHECK<$lines[$ln - 1]\n";
747 # we have a preceeding printk if it ends
748 # with "\n" ignore it, else it is to blame
749 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
750 if ($rawlines[$ln - 1] !~ m{\\n"}) {
751 $ok = 1;
752 }
753 last;
754 }
755 }
756 if ($ok == 0) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700757 WARN("printk() should include KERN_ facility level\n" . $herecurr);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700758 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700759 }
760
Andy Whitcroft653d4872007-06-23 17:16:34 -0700761# function brace can't be on same line, except for #defines of do while,
762# or if closed on same line
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700763 if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700764 !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700765 ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700766 }
Andy Whitcroft653d4872007-06-23 17:16:34 -0700767
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700768# check for spaces between functions and their parentheses.
769 if ($line =~ /($Ident)\s+\(/ &&
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700770 $1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright)$/ &&
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700771 $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) {
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700772 WARN("no space between function name and open parenthesis '('\n" . $herecurr);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700773 }
Andy Whitcroft653d4872007-06-23 17:16:34 -0700774# Check operator spacing.
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700775 # Note we expand the line with the leading + as the real
776 # line will be displayed with the leading + and the tabs
777 # will therefore also expand that way.
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700778 my $opline = $line;
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700779 $opline = expand_tabs($opline);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700780 $opline =~ s/^./ /;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700781 if (!($line=~/\#\s*include/)) {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700782 my $ops = qr{
783 <<=|>>=|<=|>=|==|!=|
784 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
785 =>|->|<<|>>|<|>|=|!|~|
786 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/
787 }x;
788 my @elements = split(/($ops|;)/, $opline);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700789 my $off = 0;
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700790 for (my $n = 0; $n < $#elements; $n += 2) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700791 $off += length($elements[$n]);
792
793 my $a = '';
794 $a = 'V' if ($elements[$n] ne '');
795 $a = 'W' if ($elements[$n] =~ /\s$/);
796 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
797 $a = 'O' if ($elements[$n] eq '');
798 $a = 'E' if ($elements[$n] eq '' && $n == 0);
799
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700800 my $op = $elements[$n + 1];
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700801
802 my $c = '';
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700803 if (defined $elements[$n + 2]) {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700804 $c = 'V' if ($elements[$n + 2] ne '');
805 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
806 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
807 $c = 'O' if ($elements[$n + 2] eq '');
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700808 $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700809 } else {
810 $c = 'E';
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700811 }
812
Andy Whitcroft00df3442007-06-08 13:47:06 -0700813 # Pick up the preceeding and succeeding characters.
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700814 my $ca = substr($opline, 0, $off);
Andy Whitcroft00df3442007-06-08 13:47:06 -0700815 my $cc = '';
Andy Whitcroft653d4872007-06-23 17:16:34 -0700816 if (length($opline) >= ($off + length($elements[$n + 1]))) {
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700817 $cc = substr($opline, $off + length($elements[$n + 1]));
Andy Whitcroft00df3442007-06-08 13:47:06 -0700818 }
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700819 my $cb = "$ca$;$cc";
Andy Whitcroft00df3442007-06-08 13:47:06 -0700820
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700821 my $ctx = "${a}x${c}";
822
823 my $at = "(ctx:$ctx)";
824
825 my $ptr = (" " x $off) . "^";
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700826 my $hereptr = "$hereline$ptr\n";
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700827
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700828 # Classify operators into binary, unary, or
829 # definitions (* only) where they have more
830 # than one mode.
831 my $unary_ctx = $prevline . $ca;
832 $unary_ctx =~ s/^./ /;
833 my $is_unary = 0;
834 my $Unary = qr{
835 (?:
836 ^|;|,|$ops|\(|\?|:|
837 \(\s*$Type\s*\)|
838 $Type|
839 return|case|else|
840 \{|\}|
841 \[|
842 ^.\#\s*define\s+$Ident\s*(?:\([^\)]*\))?|
843 ^.\#\s*else|
844 ^.\#\s*endif|
845 ^.\#\s*(?:if|ifndef|ifdef)\b.*
846 )\s*(?:|\\)\s*$
847 }x;
848 my $UnaryFalse = qr{
849 sizeof\s*\(\s*$Type\s*\)\s*$
850 }x;
851 my $UnaryDefine = qr{
852 (?:$Type|$Bare)\s*|
853 (?:$Type|$Bare).*,\s*\**
854 }x;
855 if ($op eq '-' || $op eq '&' || $op eq '*') {
856 # An operator is binary if the left hand
857 # side is a value. Pick out the known
858 # non-values.
859 if ($unary_ctx =~ /$Unary$/s &&
860 $unary_ctx !~ /$UnaryFalse$/s) {
861 $is_unary = 1;
862
863 # Special handling for ')' check if this
864 # brace represents a conditional, if so
865 # we are unary.
866 } elsif ($unary_ctx =~ /\)\s*$/) {
867 my $before = ctx_expr_before($unary_ctx);
868 if ($before =~ /(?:for|if|while)\s*$/) {
869 $is_unary = 1;
870 }
871 }
872
873 # Check for type definition for of '*'.
874 if ($op eq '*' && $unary_ctx =~ /$UnaryDefine$/) {
875 $is_unary = 2;
876 }
877 }
878
879 #if ($op eq '-' || $op eq '&' || $op eq '*') {
880 # print "UNARY: <$is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n";
881 #}
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700882
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700883 # ; should have either the end of line or a space or \ after it
884 if ($op eq ';') {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700885 if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ &&
886 $cc !~ /^;/) {
887 ERROR("need space after that '$op' $at\n" . $hereptr);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700888 }
889
890 # // is a comment
891 } elsif ($op eq '//') {
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700892
893 # -> should have no spaces
894 } elsif ($op eq '->') {
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700895 if ($ctx =~ /Wx.|.xW/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700896 ERROR("no spaces around that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700897 }
898
899 # , must have a space on the right.
900 } elsif ($op eq ',') {
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700901 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700902 ERROR("need space after that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700903 }
904
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700905 # '*' as part of a type definition -- reported already.
906 } elsif ($op eq '*' && $is_unary == 2) {
907 #warn "'*' is part of type\n";
908
909 # unary operators should have a space before and
910 # none after. May be left adjacent to another
911 # unary operator, or a cast
912 } elsif ($op eq '!' || $op eq '~' ||
913 ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) {
914 if ($ctx !~ /[WEB]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700915 ERROR("need space before that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700916 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700917 if ($ctx =~ /.xW/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700918 ERROR("no space after that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700919 }
920
921 # unary ++ and unary -- are allowed no space on one side.
922 } elsif ($op eq '++' or $op eq '--') {
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700923 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700924 ERROR("need space one side of that '$op' $at\n" . $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700925 }
Andy Whitcroftd8aaf122007-06-23 17:16:44 -0700926 if ($ctx =~ /Wx./ && $cc =~ /^;/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700927 ERROR("no space before that '$op' $at\n" . $hereptr);
Andy Whitcroft653d4872007-06-23 17:16:34 -0700928 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700929
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700930 # << and >> may either have or not have spaces both sides
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700931 } elsif ($op eq '<<' or $op eq '>>' or
932 $op eq '&' or $op eq '^' or $op eq '|' or
933 $op eq '+' or $op eq '-' or
934 $op eq '*' or $op eq '/')
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700935 {
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700936 if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700937 ERROR("need consistent spacing around '$op' $at\n" .
938 $hereptr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700939 }
940
941 # All the others need spaces both sides.
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700942 } elsif ($ctx !~ /[EW]x[WE]/) {
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700943 # Ignore email addresses <foo@bar>
944 if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) &&
945 !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) {
946 ERROR("need spaces around that '$op' $at\n" . $hereptr);
947 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700948 }
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -0700949 $off += length($elements[$n + 1]);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700950 }
951 }
952
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700953# check for multiple assignments
954 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
955 WARN("multiple assignments should be avoided\n" . $herecurr);
956 }
957
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700958## # check for multiple declarations, allowing for a function declaration
959## # continuation.
960## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
961## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
962##
963## # Remove any bracketed sections to ensure we do not
964## # falsly report the parameters of functions.
965## my $ln = $line;
966## while ($ln =~ s/\([^\(\)]*\)//g) {
967## }
968## if ($ln =~ /,/) {
969## WARN("declaring multiple variables together should be avoided\n" . $herecurr);
970## }
971## }
Andy Whitcroftf0a594c2007-07-19 01:48:34 -0700972
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700973#need space before brace following if, while, etc
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700974 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
975 $line =~ /do{/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -0700976 ERROR("need a space before the open brace '{'\n" . $herecurr);
977 }
978
979# closing brace should have a space following it when it has anything
980# on the line
981 if ($line =~ /}(?!(?:,|;|\)))\S/) {
982 ERROR("need a space after that close brace '}'\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -0700983 }
984
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700985# check spacing on square brackets
986 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
987 ERROR("no space after that open square bracket '['\n" . $herecurr);
988 }
989 if ($line =~ /\s\]/) {
990 ERROR("no space before that close square bracket ']'\n" . $herecurr);
991 }
992
993# check spacing on paretheses
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700994 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
995 $line !~ /for\s*\(\s+;/) {
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -0700996 ERROR("no space after that open parenthesis '('\n" . $herecurr);
997 }
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -0700998 if ($line =~ /\s\)/ && $line !~ /^.\s*\)/ &&
999 $line !~ /for\s*\(.*;\s+\)/) {
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001000 ERROR("no space before that close parenthesis ')'\n" . $herecurr);
1001 }
1002
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001003#goto labels aren't indented, allow a single space however
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001004 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001005 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001006 WARN("labels should not be indented\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001007 }
1008
1009# Need a space before open parenthesis after if, while etc
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001010 if ($line=~/\b(if|while|for|switch)\(/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001011 ERROR("need a space before the open parenthesis '('\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001012 }
1013
1014# Check for illegal assignment in if conditional.
Andy Whitcroft653d4872007-06-23 17:16:34 -07001015 if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) {
Andy Whitcroft00df3442007-06-08 13:47:06 -07001016 #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001017 ERROR("do not use assignment in if condition\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001018 }
1019
1020 # Check for }<nl>else {, these must be at the same
1021 # indent level to be relevant to each other.
1022 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
1023 $previndent == $indent) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001024 ERROR("else should follow close brace '}'\n" . $hereprev);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001025 }
1026
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001027#studly caps, commented out until figure out how to distinguish between use of existing and adding new
1028# if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
1029# print "No studly caps, use _\n";
1030# print "$herecurr";
1031# $clean = 0;
1032# }
1033
1034#no spaces allowed after \ in define
1035 if ($line=~/\#define.*\\\s$/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001036 WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001037 }
1038
Andy Whitcroft653d4872007-06-23 17:16:34 -07001039#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
1040 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) {
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001041 my $checkfile = "include/linux/$1.h";
1042 if (-f $checkfile) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001043 CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" .
1044 $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001045 }
1046 }
1047
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001048# if and else should not have general statements after it
1049 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ &&
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001050 $1 !~ /^\s*(?:\sif|{|\\|$)/) {
1051 ERROR("trailing statements should be on next line\n" . $herecurr);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001052 }
1053
Andy Whitcroft653d4872007-06-23 17:16:34 -07001054# multi-statement macros should be enclosed in a do while loop, grab the
1055# first statement and ensure its the whole macro if its not enclosed
1056# in a known goot container
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001057 if ($prevline =~ /\#define.*\\/ &&
1058 $prevline !~/(?:do\s+{|\(\{|\{)/ &&
1059 $line !~ /(?:do\s+{|\(\{|\{)/ &&
1060 $line !~ /^.\s*$Declare\s/) {
Andy Whitcroft653d4872007-06-23 17:16:34 -07001061 # Grab the first statement, if that is the entire macro
1062 # its ok. This may start either on the #define line
1063 # or the one below.
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001064 my $ln = $linenr;
1065 my $cnt = $realcnt;
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001066 my $off = 0;
Andy Whitcroft653d4872007-06-23 17:16:34 -07001067
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001068 # If the macro starts on the define line start
1069 # grabbing the statement after the identifier
1070 $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$};
1071 ##print "1<$1> 2<$2>\n";
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001072 if (defined $2 && $2 ne '') {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001073 $off = length($1);
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001074 $ln--;
1075 $cnt++;
1076 }
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001077 my @ctx = ctx_statement($ln, $cnt, $off);
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001078 my $ctx_ln = $ln + $#ctx + 1;
1079 my $ctx = join("\n", @ctx);
1080
1081 # Pull in any empty extension lines.
1082 while ($ctx =~ /\\$/ &&
1083 $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) {
1084 $ctx .= $lines[$ctx_ln - 1];
1085 $ctx_ln++;
1086 }
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001087
1088 if ($ctx =~ /\\$/) {
1089 if ($ctx =~ /;/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001090 ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001091 } else {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001092 ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
Andy Whitcroftd8aaf122007-06-23 17:16:44 -07001093 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001094 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001095 }
1096
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001097# check for redundant bracing round if etc
1098 if ($line =~ /\b(if|while|for|else)\b/) {
1099 # Locate the end of the opening statement.
1100 my @control = ctx_statement($linenr, $realcnt, 0);
1101 my $nr = $linenr + (scalar(@control) - 1);
1102 my $cnt = $realcnt - (scalar(@control) - 1);
1103
1104 my $off = $realcnt - $cnt;
1105 #print "$off: line<$line>end<" . $lines[$nr - 1] . ">\n";
1106
1107 # If this is is a braced statement group check it
1108 if ($lines[$nr - 1] =~ /{\s*$/) {
1109 my ($lvl, @block) = ctx_block_level($nr, $cnt);
1110
1111 my $stmt = join(' ', @block);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001112 $stmt =~ s/(^[^{]*){//;
1113 my $before = $1;
1114 $stmt =~ s/}([^}]*$)//;
1115 my $after = $1;
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001116
1117 #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n";
1118 #print "stmt<$stmt>\n\n";
1119
1120 # Count the ;'s if there is fewer than two
1121 # then there can only be one statement,
1122 # if there is a brace inside we cannot
1123 # trivially detect if its one statement.
1124 # Also nested if's often require braces to
1125 # disambiguate the else binding so shhh there.
1126 my @semi = ($stmt =~ /;/g);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001127 push(@semi, "/**/") if ($stmt =~ m@/\*@);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001128 ##print "semi<" . scalar(@semi) . ">\n";
1129 if ($lvl == 0 && scalar(@semi) < 2 &&
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001130 $stmt !~ /{/ && $stmt !~ /\bif\b/ &&
1131 $before !~ /}/ && $after !~ /{/) {
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001132 my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
1133 shift(@block);
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001134 WARN("braces {} are not necessary for single statement blocks\n" . $herectx);
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001135 }
1136 }
1137 }
1138
Andy Whitcroft653d4872007-06-23 17:16:34 -07001139# don't include deprecated include files (uses RAW line)
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001140 for my $inc (@dep_includes) {
Andy Whitcroft653d4872007-06-23 17:16:34 -07001141 if ($rawline =~ m@\#\s*include\s*\<$inc>@) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001142 ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001143 }
1144 }
1145
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001146# don't use deprecated functions
1147 for my $func (@dep_functions) {
Andy Whitcroft00df3442007-06-08 13:47:06 -07001148 if ($line =~ /\b$func\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001149 ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001150 }
1151 }
1152
1153# no volatiles please
Andy Whitcroft00df3442007-06-08 13:47:06 -07001154 if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001155 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001156 }
1157
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001158# SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated
1159 if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) {
1160 ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr);
1161 }
1162
Andy Whitcroft00df3442007-06-08 13:47:06 -07001163# warn about #if 0
1164 if ($line =~ /^.#\s*if\s+0\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001165 CHK("if this code is redundant consider removing it\n" .
1166 $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001167 }
1168
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001169# check for needless kfree() checks
1170 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
1171 my $expr = $1;
1172 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
1173 WARN("kfree(NULL) is safe this check is probabally not required\n" . $hereprev);
1174 }
1175 }
1176
Andy Whitcroft00df3442007-06-08 13:47:06 -07001177# warn about #ifdefs in C files
1178# if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
1179# print "#ifdef in C files should be avoided\n";
1180# print "$herecurr";
1181# $clean = 0;
1182# }
1183
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001184# warn about spacing in #ifdefs
1185 if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) {
1186 ERROR("exactly one space required after that #$1\n" . $herecurr);
1187 }
1188
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001189# check for spinlock_t definitions without a comment.
1190 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
1191 my $which = $1;
1192 if (!ctx_has_comment($first_line, $linenr)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001193 CHK("$1 definition without comment\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001194 }
1195 }
1196# check for memory barriers without a comment.
1197 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
1198 if (!ctx_has_comment($first_line, $linenr)) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001199 CHK("memory barrier without comment\n" . $herecurr);
Andy Whitcroft4a0df2e2007-06-08 13:46:39 -07001200 }
1201 }
1202# check of hardware specific defines
Andy Whitcroft22f2a2e2007-08-10 13:01:03 -07001203 if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001204 CHK("architecture specific defines should be avoided\n" . $herecurr);
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001205 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001206
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001207# check the location of the inline attribute, that it is between
1208# storage class and type.
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001209 if ($line =~ /\b$Type\s+$Inline\b/ ||
1210 $line =~ /\b$Inline\s+$Storage\b/) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001211 ERROR("inline keyword should sit between storage class and type\n" . $herecurr);
1212 }
1213
1214# check for new externs in .c files.
1215 if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) {
1216 WARN("externs should be avoided in .c files\n" . $herecurr);
1217 }
1218
1219# checks for new __setup's
1220 if ($rawline =~ /\b__setup\("([^"]*)"/) {
1221 my $name = $1;
1222
1223 if (!grep(/$name/, @setup_docs)) {
1224 CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
1225 }
Andy Whitcroft653d4872007-06-23 17:16:34 -07001226 }
Andy Whitcroft9c0ca6f2007-10-16 23:29:38 -07001227
1228# check for pointless casting of kmalloc return
1229 if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) {
1230 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
1231 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001232 }
1233
1234 if ($chk_patch && !$is_patch) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001235 ERROR("Does not appear to be a unified-diff format patch\n");
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001236 }
1237 if ($is_patch && $chk_signoff && $signoff == 0) {
Andy Whitcroftde7d4f02007-07-15 23:37:22 -07001238 ERROR("Missing Signed-off-by: line(s)\n");
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001239 }
1240
Andy Whitcroftf0a594c2007-07-19 01:48:34 -07001241 if ($clean == 0 && ($chk_patch || $is_patch)) {
1242 print report_dump();
1243 }
Andy Whitcroft0a920b52007-06-01 00:46:48 -07001244 if ($clean == 1 && $quiet == 0) {
1245 print "Your patch has no obvious style problems and is ready for submission.\n"
1246 }
1247 if ($clean == 0 && $quiet == 0) {
1248 print "Your patch has style problems, please review. If any of these errors\n";
1249 print "are false positives report them to the maintainer, see\n";
1250 print "CHECKPATCH in MAINTAINERS.\n";
1251 }
1252 return $clean;
1253}