Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 4 | # (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 | |
| 7 | use strict; |
| 8 | |
| 9 | my $P = $0; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 10 | $P =~ s@.*/@@g; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 11 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 12 | my $V = '0.12'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 13 | |
| 14 | use Getopt::Long qw(:config no_auto_abbrev); |
| 15 | |
| 16 | my $quiet = 0; |
| 17 | my $tree = 1; |
| 18 | my $chk_signoff = 1; |
| 19 | my $chk_patch = 1; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 20 | my $tst_type = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 21 | my $emacs = 0; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 22 | my $terse = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 23 | my $file = 0; |
| 24 | my $check = 0; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 25 | my $summary = 1; |
| 26 | my $mailback = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 27 | my $root; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 28 | GetOptions( |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 29 | 'q|quiet+' => \$quiet, |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 30 | 'tree!' => \$tree, |
| 31 | 'signoff!' => \$chk_signoff, |
| 32 | 'patch!' => \$chk_patch, |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 33 | 'test-type!' => \$tst_type, |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 34 | 'emacs!' => \$emacs, |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 35 | 'terse!' => \$terse, |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 36 | 'file!' => \$file, |
| 37 | 'subjective!' => \$check, |
| 38 | 'strict!' => \$check, |
| 39 | 'root=s' => \$root, |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 40 | 'summary!' => \$summary, |
| 41 | 'mailback!' => \$mailback, |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 42 | ) or exit; |
| 43 | |
| 44 | my $exit = 0; |
| 45 | |
| 46 | if ($#ARGV < 0) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 47 | print "usage: $P [options] patchfile\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 48 | print "version: $V\n"; |
| 49 | print "options: -q => quiet\n"; |
| 50 | print " --no-tree => run without a kernel tree\n"; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 51 | print " --terse => one line per report\n"; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 52 | print " --emacs => emacs compile window format\n"; |
| 53 | print " --file => check a source file\n"; |
| 54 | print " --strict => enable more subjective tests\n"; |
| 55 | print " --root => path to the kernel tree root\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 56 | exit(1); |
| 57 | } |
| 58 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 59 | if ($terse) { |
| 60 | $emacs = 1; |
| 61 | $quiet++; |
| 62 | } |
| 63 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 64 | if ($tree) { |
| 65 | if (defined $root) { |
| 66 | if (!top_of_kernel_tree($root)) { |
| 67 | die "$P: $root: --root does not point at a valid tree\n"; |
| 68 | } |
| 69 | } else { |
| 70 | if (top_of_kernel_tree('.')) { |
| 71 | $root = '.'; |
| 72 | } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ && |
| 73 | top_of_kernel_tree($1)) { |
| 74 | $root = $1; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (!defined $root) { |
| 79 | print "Must be run from the top-level dir. of a kernel tree\n"; |
| 80 | exit(2); |
| 81 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 84 | my $emitted_corrupt = 0; |
| 85 | |
| 86 | our $Ident = qr{[A-Za-z_][A-Za-z\d_]*}; |
| 87 | our $Storage = qr{extern|static|asmlinkage}; |
| 88 | our $Sparse = qr{ |
| 89 | __user| |
| 90 | __kernel| |
| 91 | __force| |
| 92 | __iomem| |
| 93 | __must_check| |
| 94 | __init_refok| |
| 95 | __kprobes| |
| 96 | fastcall |
| 97 | }x; |
| 98 | our $Attribute = qr{ |
| 99 | const| |
| 100 | __read_mostly| |
| 101 | __kprobes| |
| 102 | __(?:mem|cpu|dev|)(?:initdata|init) |
| 103 | }x; |
| 104 | our $Inline = qr{inline|__always_inline|noinline}; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 105 | our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; |
| 106 | our $Lval = qr{$Ident(?:$Member)*}; |
| 107 | |
| 108 | our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*}; |
| 109 | our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; |
| 110 | our $Operators = qr{ |
| 111 | <=|>=|==|!=| |
| 112 | =>|->|<<|>>|<|>|!|~| |
| 113 | &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/ |
| 114 | }x; |
| 115 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 116 | our $NonptrType; |
| 117 | our $Type; |
| 118 | our $Declare; |
| 119 | |
| 120 | our @typeList = ( |
| 121 | qr{void}, |
| 122 | qr{char}, |
| 123 | qr{short}, |
| 124 | qr{int}, |
| 125 | qr{long}, |
| 126 | qr{unsigned}, |
| 127 | qr{float}, |
| 128 | qr{double}, |
| 129 | qr{bool}, |
| 130 | qr{long\s+int}, |
| 131 | qr{long\s+long}, |
| 132 | qr{long\s+long\s+int}, |
| 133 | qr{(?:__)?(?:u|s|be|le)(?:8|16|32|64)}, |
| 134 | qr{struct\s+$Ident}, |
| 135 | qr{union\s+$Ident}, |
| 136 | qr{enum\s+$Ident}, |
| 137 | qr{${Ident}_t}, |
| 138 | qr{${Ident}_handler}, |
| 139 | qr{${Ident}_handler_fn}, |
| 140 | ); |
| 141 | |
| 142 | sub build_types { |
| 143 | my $all = "(?: \n" . join("|\n ", @typeList) . "\n)"; |
| 144 | $NonptrType = qr{ |
| 145 | \b |
| 146 | (?:const\s+)? |
| 147 | (?:unsigned\s+)? |
| 148 | $all |
| 149 | (?:\s+$Sparse|\s+const)* |
| 150 | \b |
| 151 | }x; |
| 152 | $Type = qr{ |
| 153 | \b$NonptrType\b |
| 154 | (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? |
| 155 | (?:\s+$Sparse|\s+$Attribute)* |
| 156 | }x; |
| 157 | $Declare = qr{(?:$Storage\s+)?$Type}; |
| 158 | } |
| 159 | build_types(); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 160 | |
| 161 | $chk_signoff = 0 if ($file); |
| 162 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 163 | my @dep_includes = (); |
| 164 | my @dep_functions = (); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 165 | my $removal = "Documentation/feature-removal-schedule.txt"; |
| 166 | if ($tree && -f "$root/$removal") { |
| 167 | open(REMOVE, "<$root/$removal") || |
| 168 | die "$P: $removal: open failed - $!\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 169 | while (<REMOVE>) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 170 | if (/^Check:\s+(.*\S)/) { |
| 171 | for my $entry (split(/[, ]+/, $1)) { |
| 172 | if ($entry =~ m@include/(.*)@) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 173 | push(@dep_includes, $1); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 174 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 175 | } elsif ($entry !~ m@/@) { |
| 176 | push(@dep_functions, $entry); |
| 177 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 178 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 183 | my @rawlines = (); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 184 | for my $filename (@ARGV) { |
| 185 | if ($file) { |
| 186 | open(FILE, "diff -u /dev/null $filename|") || |
| 187 | die "$P: $filename: diff failed - $!\n"; |
| 188 | } else { |
| 189 | open(FILE, "<$filename") || |
| 190 | die "$P: $filename: open failed - $!\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 191 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 192 | while (<FILE>) { |
| 193 | chomp; |
| 194 | push(@rawlines, $_); |
| 195 | } |
| 196 | close(FILE); |
| 197 | if (!process($filename, @rawlines)) { |
| 198 | $exit = 1; |
| 199 | } |
| 200 | @rawlines = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | exit($exit); |
| 204 | |
| 205 | sub top_of_kernel_tree { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 206 | my ($root) = @_; |
| 207 | |
| 208 | my @tree_check = ( |
| 209 | "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", |
| 210 | "README", "Documentation", "arch", "include", "drivers", |
| 211 | "fs", "init", "ipc", "kernel", "lib", "scripts", |
| 212 | ); |
| 213 | |
| 214 | foreach my $check (@tree_check) { |
| 215 | if (! -e $root . '/' . $check) { |
| 216 | return 0; |
| 217 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 218 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 219 | return 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | sub expand_tabs { |
| 223 | my ($str) = @_; |
| 224 | |
| 225 | my $res = ''; |
| 226 | my $n = 0; |
| 227 | for my $c (split(//, $str)) { |
| 228 | if ($c eq "\t") { |
| 229 | $res .= ' '; |
| 230 | $n++; |
| 231 | for (; ($n % 8) != 0; $n++) { |
| 232 | $res .= ' '; |
| 233 | } |
| 234 | next; |
| 235 | } |
| 236 | $res .= $c; |
| 237 | $n++; |
| 238 | } |
| 239 | |
| 240 | return $res; |
| 241 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 242 | sub copy_spacing { |
| 243 | my ($str) = @_; |
| 244 | |
| 245 | my $res = ''; |
| 246 | for my $c (split(//, $str)) { |
| 247 | if ($c eq "\t") { |
| 248 | $res .= $c; |
| 249 | } else { |
| 250 | $res .= ' '; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | return $res; |
| 255 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 256 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 257 | sub line_stats { |
| 258 | my ($line) = @_; |
| 259 | |
| 260 | # Drop the diff line leader and expand tabs |
| 261 | $line =~ s/^.//; |
| 262 | $line = expand_tabs($line); |
| 263 | |
| 264 | # Pick the indent from the front of the line. |
| 265 | my ($white) = ($line =~ /^(\s*)/); |
| 266 | |
| 267 | return (length($line), length($white)); |
| 268 | } |
| 269 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 270 | sub sanitise_line { |
| 271 | my ($line) = @_; |
| 272 | |
| 273 | my $res = ''; |
| 274 | my $l = ''; |
| 275 | |
| 276 | my $quote = ''; |
| 277 | |
| 278 | foreach my $c (split(//, $line)) { |
| 279 | if ($l ne "\\" && ($c eq "'" || $c eq '"')) { |
| 280 | if ($quote eq '') { |
| 281 | $quote = $c; |
| 282 | $res .= $c; |
| 283 | $l = $c; |
| 284 | next; |
| 285 | } elsif ($quote eq $c) { |
| 286 | $quote = ''; |
| 287 | } |
| 288 | } |
| 289 | if ($quote && $c ne "\t") { |
| 290 | $res .= "X"; |
| 291 | } else { |
| 292 | $res .= $c; |
| 293 | } |
| 294 | |
| 295 | $l = $c; |
| 296 | } |
| 297 | |
| 298 | return $res; |
| 299 | } |
| 300 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 301 | sub ctx_statement_block { |
| 302 | my ($linenr, $remain, $off) = @_; |
| 303 | my $line = $linenr - 1; |
| 304 | my $blk = ''; |
| 305 | my $soff = $off; |
| 306 | my $coff = $off - 1; |
| 307 | |
| 308 | my $type = ''; |
| 309 | my $level = 0; |
| 310 | my $c; |
| 311 | my $len = 0; |
| 312 | while (1) { |
| 313 | #warn "CSB: blk<$blk>\n"; |
| 314 | # If we are about to drop off the end, pull in more |
| 315 | # context. |
| 316 | if ($off >= $len) { |
| 317 | for (; $remain > 0; $line++) { |
| 318 | next if ($rawlines[$line] =~ /^-/); |
| 319 | $remain--; |
| 320 | $blk .= sanitise_line($rawlines[$line]) . "\n"; |
| 321 | $len = length($blk); |
| 322 | $line++; |
| 323 | last; |
| 324 | } |
| 325 | # Bail if there is no further context. |
| 326 | #warn "CSB: blk<$blk> off<$off> len<$len>\n"; |
| 327 | if ($off == $len) { |
| 328 | last; |
| 329 | } |
| 330 | } |
| 331 | $c = substr($blk, $off, 1); |
| 332 | |
| 333 | #warn "CSB: c<$c> type<$type> level<$level>\n"; |
| 334 | # Statement ends at the ';' or a close '}' at the |
| 335 | # outermost level. |
| 336 | if ($level == 0 && $c eq ';') { |
| 337 | last; |
| 338 | } |
| 339 | |
| 340 | if (($type eq '' || $type eq '(') && $c eq '(') { |
| 341 | $level++; |
| 342 | $type = '('; |
| 343 | } |
| 344 | if ($type eq '(' && $c eq ')') { |
| 345 | $level--; |
| 346 | $type = ($level != 0)? '(' : ''; |
| 347 | |
| 348 | if ($level == 0 && $coff < $soff) { |
| 349 | $coff = $off; |
| 350 | } |
| 351 | } |
| 352 | if (($type eq '' || $type eq '{') && $c eq '{') { |
| 353 | $level++; |
| 354 | $type = '{'; |
| 355 | } |
| 356 | if ($type eq '{' && $c eq '}') { |
| 357 | $level--; |
| 358 | $type = ($level != 0)? '{' : ''; |
| 359 | |
| 360 | if ($level == 0) { |
| 361 | last; |
| 362 | } |
| 363 | } |
| 364 | $off++; |
| 365 | } |
| 366 | |
| 367 | my $statement = substr($blk, $soff, $off - $soff + 1); |
| 368 | my $condition = substr($blk, $soff, $coff - $soff + 1); |
| 369 | |
| 370 | #warn "STATEMENT<$statement>\n"; |
| 371 | #warn "CONDITION<$condition>\n"; |
| 372 | |
| 373 | return ($statement, $condition); |
| 374 | } |
| 375 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 376 | sub ctx_block_get { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 377 | my ($linenr, $remain, $outer, $open, $close, $off) = @_; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 378 | my $line; |
| 379 | my $start = $linenr - 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 380 | my $blk = ''; |
| 381 | my @o; |
| 382 | my @c; |
| 383 | my @res = (); |
| 384 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 385 | my $level = 0; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 386 | for ($line = $start; $remain > 0; $line++) { |
| 387 | next if ($rawlines[$line] =~ /^-/); |
| 388 | $remain--; |
| 389 | |
| 390 | $blk .= $rawlines[$line]; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 391 | foreach my $c (split(//, $rawlines[$line])) { |
| 392 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; |
| 393 | if ($off > 0) { |
| 394 | $off--; |
| 395 | next; |
| 396 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 397 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 398 | if ($c eq $close && $level > 0) { |
| 399 | $level--; |
| 400 | last if ($level == 0); |
| 401 | } elsif ($c eq $open) { |
| 402 | $level++; |
| 403 | } |
| 404 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 405 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 406 | if (!$outer || $level <= 1) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 407 | push(@res, $rawlines[$line]); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 410 | last if ($level == 0); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 413 | return ($level, @res); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 414 | } |
| 415 | sub ctx_block_outer { |
| 416 | my ($linenr, $remain) = @_; |
| 417 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 418 | my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0); |
| 419 | return @r; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 420 | } |
| 421 | sub ctx_block { |
| 422 | my ($linenr, $remain) = @_; |
| 423 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 424 | my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
| 425 | return @r; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 426 | } |
| 427 | sub ctx_statement { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 428 | my ($linenr, $remain, $off) = @_; |
| 429 | |
| 430 | my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off); |
| 431 | return @r; |
| 432 | } |
| 433 | sub ctx_block_level { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 434 | my ($linenr, $remain) = @_; |
| 435 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 436 | return ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 437 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 438 | sub ctx_statement_level { |
| 439 | my ($linenr, $remain, $off) = @_; |
| 440 | |
| 441 | return ctx_block_get($linenr, $remain, 0, '(', ')', $off); |
| 442 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 443 | |
| 444 | sub ctx_locate_comment { |
| 445 | my ($first_line, $end_line) = @_; |
| 446 | |
| 447 | # Catch a comment on the end of the line itself. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 448 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 449 | return $current_comment if (defined $current_comment); |
| 450 | |
| 451 | # Look through the context and try and figure out if there is a |
| 452 | # comment. |
| 453 | my $in_comment = 0; |
| 454 | $current_comment = ''; |
| 455 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 456 | my $line = $rawlines[$linenr - 1]; |
| 457 | #warn " $line\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 458 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
| 459 | $in_comment = 1; |
| 460 | } |
| 461 | if ($line =~ m@/\*@) { |
| 462 | $in_comment = 1; |
| 463 | } |
| 464 | if (!$in_comment && $current_comment ne '') { |
| 465 | $current_comment = ''; |
| 466 | } |
| 467 | $current_comment .= $line . "\n" if ($in_comment); |
| 468 | if ($line =~ m@\*/@) { |
| 469 | $in_comment = 0; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | chomp($current_comment); |
| 474 | return($current_comment); |
| 475 | } |
| 476 | sub ctx_has_comment { |
| 477 | my ($first_line, $end_line) = @_; |
| 478 | my $cmt = ctx_locate_comment($first_line, $end_line); |
| 479 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 480 | ##print "LINE: $rawlines[$end_line - 1 ]\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 481 | ##print "CMMT: $cmt\n"; |
| 482 | |
| 483 | return ($cmt ne ''); |
| 484 | } |
| 485 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 486 | sub cat_vet { |
| 487 | my ($vet) = @_; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 488 | my ($res, $coded); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 489 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 490 | $res = ''; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 491 | while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) { |
| 492 | $res .= $1; |
| 493 | if ($2 ne '') { |
| 494 | $coded = sprintf("^%c", unpack('C', $2) + 64); |
| 495 | $res .= $coded; |
| 496 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 497 | } |
| 498 | $res =~ s/$/\$/; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 499 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 500 | return $res; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 503 | sub annotate_values { |
| 504 | my ($stream, $type) = @_; |
| 505 | |
| 506 | my $res; |
| 507 | my $cur = $stream; |
| 508 | |
| 509 | my $debug = 0; |
| 510 | |
| 511 | print "$stream\n" if ($debug); |
| 512 | |
| 513 | ##my $type = 'N'; |
| 514 | my $pos = 0; |
| 515 | my $preprocessor = 0; |
| 516 | my $paren = 0; |
| 517 | my @paren_type; |
| 518 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 519 | while (length($cur)) { |
| 520 | print " <$type> " if ($debug); |
| 521 | if ($cur =~ /^(\s+)/o) { |
| 522 | print "WS($1)\n" if ($debug); |
| 523 | if ($1 =~ /\n/ && $preprocessor) { |
| 524 | $preprocessor = 0; |
| 525 | $type = 'N'; |
| 526 | } |
| 527 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 528 | } elsif ($cur =~ /^($Type)/) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 529 | print "DECLARE($1)\n" if ($debug); |
| 530 | $type = 'T'; |
| 531 | |
| 532 | } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) { |
| 533 | print "DEFINE($1)\n" if ($debug); |
| 534 | $preprocessor = 1; |
| 535 | $paren_type[$paren] = 'N'; |
| 536 | |
| 537 | } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|endif))/o) { |
| 538 | print "PRE($1)\n" if ($debug); |
| 539 | $preprocessor = 1; |
| 540 | $type = 'N'; |
| 541 | |
| 542 | } elsif ($cur =~ /^(\\\n)/o) { |
| 543 | print "PRECONT($1)\n" if ($debug); |
| 544 | |
| 545 | } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { |
| 546 | print "SIZEOF($1)\n" if ($debug); |
| 547 | if (defined $2) { |
| 548 | $paren_type[$paren] = 'V'; |
| 549 | } |
| 550 | $type = 'N'; |
| 551 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 552 | } elsif ($cur =~ /^(if|while|typeof|for)\b/o) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 553 | print "COND($1)\n" if ($debug); |
| 554 | $paren_type[$paren] = 'N'; |
| 555 | $type = 'N'; |
| 556 | |
| 557 | } elsif ($cur =~/^(return|case|else)/o) { |
| 558 | print "KEYWORD($1)\n" if ($debug); |
| 559 | $type = 'N'; |
| 560 | |
| 561 | } elsif ($cur =~ /^(\()/o) { |
| 562 | print "PAREN('$1')\n" if ($debug); |
| 563 | $paren++; |
| 564 | $type = 'N'; |
| 565 | |
| 566 | } elsif ($cur =~ /^(\))/o) { |
| 567 | $paren-- if ($paren > 0); |
| 568 | if (defined $paren_type[$paren]) { |
| 569 | $type = $paren_type[$paren]; |
| 570 | undef $paren_type[$paren]; |
| 571 | print "PAREN('$1') -> $type\n" if ($debug); |
| 572 | } else { |
| 573 | print "PAREN('$1')\n" if ($debug); |
| 574 | } |
| 575 | |
| 576 | } elsif ($cur =~ /^($Ident)\(/o) { |
| 577 | print "FUNC($1)\n" if ($debug); |
| 578 | $paren_type[$paren] = 'V'; |
| 579 | |
| 580 | } elsif ($cur =~ /^($Ident|$Constant)/o) { |
| 581 | print "IDENT($1)\n" if ($debug); |
| 582 | $type = 'V'; |
| 583 | |
| 584 | } elsif ($cur =~ /^($Assignment)/o) { |
| 585 | print "ASSIGN($1)\n" if ($debug); |
| 586 | $type = 'N'; |
| 587 | |
| 588 | } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) { |
| 589 | print "END($1)\n" if ($debug); |
| 590 | $type = 'N'; |
| 591 | |
| 592 | } elsif ($cur =~ /^($Operators)/o) { |
| 593 | print "OP($1)\n" if ($debug); |
| 594 | if ($1 ne '++' && $1 ne '--') { |
| 595 | $type = 'N'; |
| 596 | } |
| 597 | |
| 598 | } elsif ($cur =~ /(^.)/o) { |
| 599 | print "C($1)\n" if ($debug); |
| 600 | } |
| 601 | if (defined $1) { |
| 602 | $cur = substr($cur, length($1)); |
| 603 | $res .= $type x length($1); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | return $res; |
| 608 | } |
| 609 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 610 | sub possible { |
| 611 | my ($possible) = @_; |
| 612 | |
| 613 | #print "CHECK<$possible>\n"; |
| 614 | if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ && |
| 615 | $possible ne 'goto' && $possible ne 'return' && |
| 616 | $possible ne 'struct' && $possible ne 'enum' && |
| 617 | $possible ne 'case' && $possible ne 'else' && |
| 618 | $possible ne 'typedef') { |
| 619 | #print "POSSIBLE<$possible>\n"; |
| 620 | push(@typeList, $possible); |
| 621 | build_types(); |
| 622 | } |
| 623 | } |
| 624 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 625 | my $prefix = ''; |
| 626 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 627 | my @report = (); |
| 628 | sub report { |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 629 | my $line = $prefix . $_[0]; |
| 630 | |
| 631 | $line = (split('\n', $line))[0] . "\n" if ($terse); |
| 632 | |
| 633 | push(@report, $line); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 634 | } |
| 635 | sub report_dump { |
| 636 | @report; |
| 637 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 638 | sub ERROR { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 639 | report("ERROR: $_[0]\n"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 640 | our $clean = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 641 | our $cnt_error++; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 642 | } |
| 643 | sub WARN { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 644 | report("WARNING: $_[0]\n"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 645 | our $clean = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 646 | our $cnt_warn++; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 647 | } |
| 648 | sub CHK { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 649 | if ($check) { |
| 650 | report("CHECK: $_[0]\n"); |
| 651 | our $clean = 0; |
| 652 | our $cnt_chk++; |
| 653 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 656 | sub process { |
| 657 | my $filename = shift; |
| 658 | my @lines = @_; |
| 659 | |
| 660 | my $linenr=0; |
| 661 | my $prevline=""; |
| 662 | my $stashline=""; |
| 663 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 664 | my $length; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 665 | my $indent; |
| 666 | my $previndent=0; |
| 667 | my $stashindent=0; |
| 668 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 669 | our $clean = 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 670 | my $signoff = 0; |
| 671 | my $is_patch = 0; |
| 672 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 673 | our $cnt_lines = 0; |
| 674 | our $cnt_error = 0; |
| 675 | our $cnt_warn = 0; |
| 676 | our $cnt_chk = 0; |
| 677 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 678 | # Trace the real file/line as we go. |
| 679 | my $realfile = ''; |
| 680 | my $realline = 0; |
| 681 | my $realcnt = 0; |
| 682 | my $here = ''; |
| 683 | my $in_comment = 0; |
| 684 | my $first_line = 0; |
| 685 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 686 | my $prev_values = 'N'; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 687 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 688 | # Pre-scan the patch looking for any __setup documentation. |
| 689 | my @setup_docs = (); |
| 690 | my $setup_docs = 0; |
| 691 | foreach my $line (@lines) { |
| 692 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 693 | $setup_docs = 0; |
| 694 | if ($1 =~ m@Documentation/kernel-parameters.txt$@) { |
| 695 | $setup_docs = 1; |
| 696 | } |
| 697 | next; |
| 698 | } |
| 699 | |
| 700 | if ($setup_docs && $line =~ /^\+/) { |
| 701 | push(@setup_docs, $line); |
| 702 | } |
| 703 | } |
| 704 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 705 | $prefix = ''; |
| 706 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 707 | foreach my $line (@lines) { |
| 708 | $linenr++; |
| 709 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 710 | my $rawline = $line; |
| 711 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 712 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 713 | #extract the filename as it passes |
| 714 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 715 | $realfile=$1; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 716 | $realfile =~ s@^[^/]*/@@; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 717 | $in_comment = 0; |
| 718 | next; |
| 719 | } |
| 720 | #extract the line range in the file after the patch is applied |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 721 | if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 722 | $is_patch = 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 723 | $first_line = $linenr + 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 724 | $in_comment = 0; |
| 725 | $realline=$1-1; |
| 726 | if (defined $2) { |
| 727 | $realcnt=$3+1; |
| 728 | } else { |
| 729 | $realcnt=1+1; |
| 730 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 731 | $prev_values = 'N'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 732 | next; |
| 733 | } |
| 734 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 735 | # track the line number as we move through the hunk, note that |
| 736 | # new versions of GNU diff omit the leading space on completely |
| 737 | # blank context lines so we need to count that too. |
| 738 | if ($line =~ /^( |\+|$)/) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 739 | $realline++; |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 740 | $realcnt-- if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 741 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 742 | # Guestimate if this is a continuing comment. Run |
| 743 | # the context looking for a comment "edge". If this |
| 744 | # edge is a close comment then we must be in a comment |
| 745 | # at context start. |
| 746 | if ($linenr == $first_line) { |
| 747 | my $edge; |
| 748 | for (my $ln = $first_line; $ln < ($linenr + $realcnt); $ln++) { |
| 749 | ($edge) = ($lines[$ln - 1] =~ m@(/\*|\*/)@); |
| 750 | last if (defined $edge); |
| 751 | } |
| 752 | if (defined $edge && $edge eq '*/') { |
| 753 | $in_comment = 1; |
| 754 | } |
| 755 | } |
| 756 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 757 | # Guestimate if this is a continuing comment. If this |
| 758 | # is the start of a diff block and this line starts |
| 759 | # ' *' then it is very likely a comment. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 760 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 761 | $in_comment = 1; |
| 762 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 763 | |
| 764 | # Find the last comment edge on _this_ line. |
| 765 | while (($line =~ m@(/\*|\*/)@g)) { |
| 766 | if ($1 eq '/*') { |
| 767 | $in_comment = 1; |
| 768 | } else { |
| 769 | $in_comment = 0; |
| 770 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 773 | # Measure the line length and indent. |
| 774 | ($length, $indent) = line_stats($line); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 775 | |
| 776 | # Track the previous line. |
| 777 | ($prevline, $stashline) = ($stashline, $line); |
| 778 | ($previndent, $stashindent) = ($stashindent, $indent); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 779 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 780 | } elsif ($realcnt == 1) { |
| 781 | $realcnt--; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | #make up the handle for any error we report on this line |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 785 | $here = "#$linenr: " if (!$file); |
| 786 | $here = "#$realline: " if ($file); |
Randy Dunlap | 389834b | 2007-06-08 13:47:03 -0700 | [diff] [blame] | 787 | $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 788 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 789 | my $hereline = "$here\n$line\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 790 | my $herecurr = "$here\n$line\n"; |
| 791 | my $hereprev = "$here\n$prevline\n$line\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 792 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 793 | $prefix = "$filename:$realline: " if ($emacs && $file); |
| 794 | $prefix = "$filename:$linenr: " if ($emacs && !$file); |
| 795 | $cnt_lines++ if ($realcnt != 0); |
| 796 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 797 | #check the patch for a signoff: |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 798 | if ($line =~ /^\s*signed-off-by:/i) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 799 | # This is a signoff, if ugly, so do not double report. |
| 800 | $signoff++; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 801 | if (!($line =~ /^\s*Signed-off-by:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 802 | WARN("Signed-off-by: is the preferred form\n" . |
| 803 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 804 | } |
| 805 | if ($line =~ /^\s*signed-off-by:\S/i) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 806 | WARN("need space after Signed-off-by:\n" . |
| 807 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 811 | # Check for wrappage within a valid hunk of the file |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 812 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 813 | ERROR("patch seems to be corrupt (line wrapped?)\n" . |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 814 | $herecurr) if (!$emitted_corrupt++); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php |
| 818 | if (($realfile =~ /^$/ || $line =~ /^\+/) && |
| 819 | !($line =~ m/^( |
| 820 | [\x09\x0A\x0D\x20-\x7E] # ASCII |
| 821 | | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
| 822 | | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs |
| 823 | | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte |
| 824 | | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates |
| 825 | | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 826 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 827 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 828 | )*$/x )) { |
| 829 | ERROR("Invalid UTF-8\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 830 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 831 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 832 | #ignore lines being removed |
| 833 | if ($line=~/^-/) {next;} |
| 834 | |
| 835 | # check we are in a valid source file if not then ignore this hunk |
| 836 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 837 | |
| 838 | #trailing whitespace |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 839 | if ($line =~ /^\+.*\015/) { |
| 840 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 841 | ERROR("DOS line endings\n" . $herevet); |
| 842 | |
| 843 | } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 844 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 845 | ERROR("trailing whitespace\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 846 | } |
| 847 | #80 column limit |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 848 | if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 849 | WARN("line over 80 characters\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 852 | # check for adding lines without a newline. |
| 853 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { |
| 854 | WARN("adding a line without newline at end of file\n" . $herecurr); |
| 855 | } |
| 856 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 857 | # check we are in a valid source file *.[hc] if not then ignore this hunk |
| 858 | next if ($realfile !~ /\.[hc]$/); |
| 859 | |
| 860 | # at the beginning of a line any tabs must come first and anything |
| 861 | # more than 8 must use tabs. |
| 862 | if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 863 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
| 864 | ERROR("use tabs not spaces\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 867 | # Remove comments from the line before processing. |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 868 | my $comment_edge = ($line =~ s@/\*.*\*/@@g) + |
| 869 | ($line =~ s@/\*.*@@) + |
| 870 | ($line =~ s@^(.).*\*/@$1@); |
| 871 | |
| 872 | # The rest of our checks refer specifically to C style |
| 873 | # only apply those _outside_ comments. Only skip |
| 874 | # lines in the middle of comments. |
| 875 | next if (!$comment_edge && $in_comment); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 876 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 877 | # Standardise the strings and chars within the input to simplify matching. |
| 878 | $line = sanitise_line($line); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 879 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 880 | # Check for potential 'bare' types |
| 881 | if ($realcnt && |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 882 | $line !~ /$Ident:\s*$/ && |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 883 | ($line =~ /^.\s*$Ident\s*\(\*+\s*$Ident\)\s*\(/ || |
| 884 | $line !~ /^.\s*$Ident\s*\(/)) { |
| 885 | # definitions in global scope can only start with types |
| 886 | if ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) { |
| 887 | possible($1); |
| 888 | |
| 889 | # declarations always start with types |
| 890 | } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/) { |
| 891 | possible($1); |
| 892 | |
| 893 | # any (foo ... *) is a pointer cast, and foo is a type |
| 894 | } elsif ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/) { |
| 895 | possible($1); |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 896 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 897 | |
| 898 | # Check for any sort of function declaration. |
| 899 | # int foo(something bar, other baz); |
| 900 | # void (*store_gdt)(x86_descr_ptr *); |
| 901 | if ($prev_values eq 'N' && $line =~ /^(.(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { |
| 902 | my ($name_len) = length($1); |
| 903 | my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, $name_len); |
| 904 | my $ctx = join("\n", @ctx); |
| 905 | |
| 906 | $ctx =~ s/\n.//; |
| 907 | substr($ctx, 0, $name_len + 1) = ''; |
| 908 | $ctx =~ s/\)[^\)]*$//; |
| 909 | for my $arg (split(/\s*,\s*/, $ctx)) { |
| 910 | if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) { |
| 911 | |
| 912 | possible($1); |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 919 | # |
| 920 | # Checks which may be anchored in the context. |
| 921 | # |
| 922 | |
| 923 | # Check for switch () and associated case and default |
| 924 | # statements should be at the same indent. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 925 | if ($line=~/\bswitch\s*\(.*\)/) { |
| 926 | my $err = ''; |
| 927 | my $sep = ''; |
| 928 | my @ctx = ctx_block_outer($linenr, $realcnt); |
| 929 | shift(@ctx); |
| 930 | for my $ctx (@ctx) { |
| 931 | my ($clen, $cindent) = line_stats($ctx); |
| 932 | if ($ctx =~ /^\+\s*(case\s+|default:)/ && |
| 933 | $indent != $cindent) { |
| 934 | $err .= "$sep$ctx\n"; |
| 935 | $sep = ''; |
| 936 | } else { |
| 937 | $sep = "[...]\n"; |
| 938 | } |
| 939 | } |
| 940 | if ($err ne '') { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 941 | ERROR("switch and case should be at the same indent\n$hereline$err"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
| 945 | # if/while/etc brace do not go on next line, unless defining a do while loop, |
| 946 | # or if that brace on the next line is for something else |
| 947 | if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 948 | my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 949 | my $ctx_ln = $linenr + $#ctx + 1; |
| 950 | my $ctx_cnt = $realcnt - $#ctx - 1; |
| 951 | my $ctx = join("\n", @ctx); |
| 952 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 953 | # Skip over any removed lines in the context following statement. |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 954 | while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) { |
| 955 | $ctx_ln++; |
| 956 | $ctx_cnt--; |
| 957 | } |
| 958 | ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>"; |
| 959 | |
| 960 | if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 961 | ERROR("That open brace { should be on the previous line\n" . |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 962 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 963 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 964 | if ($level == 0 && $ctx =~ /\)\s*\;\s*$/ && defined $lines[$ctx_ln - 1]) { |
| 965 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); |
| 966 | if ($nindent > $indent) { |
| 967 | WARN("Trailing semicolon indicates no statements, indent implies otherwise\n" . |
| 968 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
| 969 | } |
| 970 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 973 | # Track the 'values' across context and added lines. |
| 974 | my $opline = $line; $opline =~ s/^./ /; |
| 975 | my $curr_values = annotate_values($opline . "\n", $prev_values); |
| 976 | $curr_values = $prev_values . $curr_values; |
| 977 | #warn "--> $opline\n"; |
| 978 | #warn "--> $curr_values ($prev_values)\n"; |
| 979 | $prev_values = substr($curr_values, -1); |
| 980 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 981 | #ignore lines not being added |
| 982 | if ($line=~/^[^\+]/) {next;} |
| 983 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 984 | # TEST: allow direct testing of the type matcher. |
| 985 | if ($tst_type && $line =~ /^.$Declare$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 986 | ERROR("TEST: is type $Declare\n" . $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 987 | next; |
| 988 | } |
| 989 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 990 | # check for initialisation to aggregates open brace on the next line |
| 991 | if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ && |
| 992 | $line =~ /^.\s*{/) { |
| 993 | ERROR("That open brace { should be on the previous line\n" . $hereprev); |
| 994 | } |
| 995 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 996 | # |
| 997 | # Checks which are anchored on the added line. |
| 998 | # |
| 999 | |
| 1000 | # check for malformed paths in #include statements (uses RAW line) |
| 1001 | if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) { |
| 1002 | my $path = $1; |
| 1003 | if ($path =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1004 | ERROR("malformed #include filename\n" . |
| 1005 | $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1006 | } |
| 1007 | # Sanitise this special form of string. |
| 1008 | $path = 'X' x length($path); |
| 1009 | $line =~ s{\<.*\>}{<$path>}; |
| 1010 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1011 | |
| 1012 | # no C99 // comments |
| 1013 | if ($line =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1014 | ERROR("do not use C99 // comments\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1015 | } |
| 1016 | # Remove C99 comments. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1017 | $line =~ s@//.*@@; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1018 | $opline =~ s@//.*@@; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1019 | |
| 1020 | #EXPORT_SYMBOL should immediately follow its function closing }. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1021 | if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) || |
| 1022 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { |
| 1023 | my $name = $1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1024 | if (($prevline !~ /^}/) && |
| 1025 | ($prevline !~ /^\+}/) && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1026 | ($prevline !~ /^ }/) && |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1027 | ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1028 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1032 | # check for external initialisers. |
| 1033 | if ($line =~ /^.$Type\s*$Ident\s*=\s*(0|NULL);/) { |
| 1034 | ERROR("do not initialise externals to 0 or NULL\n" . |
| 1035 | $herecurr); |
| 1036 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1037 | # check for static initialisers. |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1038 | if ($line =~ /\s*static\s.*=\s*(0|NULL);/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1039 | ERROR("do not initialise statics to 0 or NULL\n" . |
| 1040 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1043 | # check for new typedefs, only function parameters and sparse annotations |
| 1044 | # make sense. |
| 1045 | if ($line =~ /\btypedef\s/ && |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1046 | $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1047 | $line !~ /\b__bitwise(?:__|)\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1048 | WARN("do not add new typedefs\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | # * goes on variable not on type |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1052 | if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1053 | ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" . |
| 1054 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1055 | |
| 1056 | } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1057 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . |
| 1058 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1059 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1060 | } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1061 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . |
| 1062 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1063 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1064 | } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1065 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . |
| 1066 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | # # no BUG() or BUG_ON() |
| 1070 | # if ($line =~ /\b(BUG|BUG_ON)\b/) { |
| 1071 | # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n"; |
| 1072 | # print "$herecurr"; |
| 1073 | # $clean = 0; |
| 1074 | # } |
| 1075 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1076 | if ($line =~ /\bLINUX_VERSION_CODE\b/) { |
| 1077 | WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged" . $herecurr); |
| 1078 | } |
| 1079 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1080 | # printk should use KERN_* levels. Note that follow on printk's on the |
| 1081 | # same line do not need a level, so we use the current block context |
| 1082 | # to try and find and validate the current printk. In summary the current |
| 1083 | # printk includes all preceeding printk's which have no newline on the end. |
| 1084 | # we assume the first bad printk is the one to report. |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1085 | if ($line =~ /\bprintk\((?!KERN_)\s*"/) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1086 | my $ok = 0; |
| 1087 | for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { |
| 1088 | #print "CHECK<$lines[$ln - 1]\n"; |
| 1089 | # we have a preceeding printk if it ends |
| 1090 | # with "\n" ignore it, else it is to blame |
| 1091 | if ($lines[$ln - 1] =~ m{\bprintk\(}) { |
| 1092 | if ($rawlines[$ln - 1] !~ m{\\n"}) { |
| 1093 | $ok = 1; |
| 1094 | } |
| 1095 | last; |
| 1096 | } |
| 1097 | } |
| 1098 | if ($ok == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1099 | WARN("printk() should include KERN_ facility level\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1100 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1103 | # function brace can't be on same line, except for #defines of do while, |
| 1104 | # or if closed on same line |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1105 | if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1106 | !($line=~/\#define.*do\s{/) and !($line=~/}/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1107 | ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1108 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1109 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1110 | # open braces for enum, union and struct go on the same line. |
| 1111 | if ($line =~ /^.\s*{/ && |
| 1112 | $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { |
| 1113 | ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); |
| 1114 | } |
| 1115 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1116 | # check for spaces between functions and their parentheses. |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1117 | while ($line =~ /($Ident)\s+\(/g) { |
| 1118 | if ($1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/ && |
| 1119 | $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) { |
| 1120 | WARN("no space between function name and open parenthesis '('\n" . $herecurr); |
| 1121 | } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1122 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1123 | # Check operator spacing. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1124 | if (!($line=~/\#\s*include/)) { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1125 | my $ops = qr{ |
| 1126 | <<=|>>=|<=|>=|==|!=| |
| 1127 | \+=|-=|\*=|\/=|%=|\^=|\|=|&=| |
| 1128 | =>|->|<<|>>|<|>|=|!|~| |
| 1129 | &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/ |
| 1130 | }x; |
| 1131 | my @elements = split(/($ops|;)/, $opline); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1132 | my $off = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1133 | |
| 1134 | my $blank = copy_spacing($opline); |
| 1135 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1136 | for (my $n = 0; $n < $#elements; $n += 2) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1137 | $off += length($elements[$n]); |
| 1138 | |
| 1139 | my $a = ''; |
| 1140 | $a = 'V' if ($elements[$n] ne ''); |
| 1141 | $a = 'W' if ($elements[$n] =~ /\s$/); |
| 1142 | $a = 'B' if ($elements[$n] =~ /(\[|\()$/); |
| 1143 | $a = 'O' if ($elements[$n] eq ''); |
| 1144 | $a = 'E' if ($elements[$n] eq '' && $n == 0); |
| 1145 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1146 | my $op = $elements[$n + 1]; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1147 | |
| 1148 | my $c = ''; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1149 | if (defined $elements[$n + 2]) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1150 | $c = 'V' if ($elements[$n + 2] ne ''); |
| 1151 | $c = 'W' if ($elements[$n + 2] =~ /^\s/); |
| 1152 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); |
| 1153 | $c = 'O' if ($elements[$n + 2] eq ''); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1154 | $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1155 | } else { |
| 1156 | $c = 'E'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1159 | # Pick up the preceeding and succeeding characters. |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1160 | my $ca = substr($opline, 0, $off); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1161 | my $cc = ''; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1162 | if (length($opline) >= ($off + length($elements[$n + 1]))) { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1163 | $cc = substr($opline, $off + length($elements[$n + 1])); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1164 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1165 | my $cb = "$ca$;$cc"; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1166 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1167 | my $ctx = "${a}x${c}"; |
| 1168 | |
| 1169 | my $at = "(ctx:$ctx)"; |
| 1170 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1171 | my $ptr = substr($blank, 0, $off) . "^"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1172 | my $hereptr = "$hereline$ptr\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1173 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1174 | # Classify operators into binary, unary, or |
| 1175 | # definitions (* only) where they have more |
| 1176 | # than one mode. |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1177 | my $op_type = substr($curr_values, $off + 1, 1); |
| 1178 | my $op_left = substr($curr_values, $off, 1); |
| 1179 | my $is_unary; |
| 1180 | if ($op_type eq 'T') { |
| 1181 | $is_unary = 2; |
| 1182 | } elsif ($op_left eq 'V') { |
| 1183 | $is_unary = 0; |
| 1184 | } else { |
| 1185 | $is_unary = 1; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1186 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1187 | #if ($op eq '-' || $op eq '&' || $op eq '*') { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1188 | # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1189 | #} |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1190 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1191 | # ; should have either the end of line or a space or \ after it |
| 1192 | if ($op eq ';') { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1193 | if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ && |
| 1194 | $cc !~ /^;/) { |
| 1195 | ERROR("need space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | # // is a comment |
| 1199 | } elsif ($op eq '//') { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1200 | |
| 1201 | # -> should have no spaces |
| 1202 | } elsif ($op eq '->') { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1203 | if ($ctx =~ /Wx.|.xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1204 | ERROR("no spaces around that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | # , must have a space on the right. |
| 1208 | } elsif ($op eq ',') { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1209 | if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1210 | ERROR("need space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1213 | # '*' as part of a type definition -- reported already. |
| 1214 | } elsif ($op eq '*' && $is_unary == 2) { |
| 1215 | #warn "'*' is part of type\n"; |
| 1216 | |
| 1217 | # unary operators should have a space before and |
| 1218 | # none after. May be left adjacent to another |
| 1219 | # unary operator, or a cast |
| 1220 | } elsif ($op eq '!' || $op eq '~' || |
| 1221 | ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) { |
| 1222 | if ($ctx !~ /[WEB]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1223 | ERROR("need space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1224 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1225 | if ($ctx =~ /.xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1226 | ERROR("no space after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | # unary ++ and unary -- are allowed no space on one side. |
| 1230 | } elsif ($op eq '++' or $op eq '--') { |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1231 | if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1232 | ERROR("need space one side of that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1233 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1234 | if ($ctx =~ /Wx./ && $cc =~ /^;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1235 | ERROR("no space before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1236 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1237 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1238 | # << and >> may either have or not have spaces both sides |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1239 | } elsif ($op eq '<<' or $op eq '>>' or |
| 1240 | $op eq '&' or $op eq '^' or $op eq '|' or |
| 1241 | $op eq '+' or $op eq '-' or |
| 1242 | $op eq '*' or $op eq '/') |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1243 | { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1244 | if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1245 | ERROR("need consistent spacing around '$op' $at\n" . |
| 1246 | $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | # All the others need spaces both sides. |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1250 | } elsif ($ctx !~ /[EW]x[WE]/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1251 | # Ignore email addresses <foo@bar> |
| 1252 | if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && |
| 1253 | !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { |
| 1254 | ERROR("need spaces around that '$op' $at\n" . $hereptr); |
| 1255 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1256 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1257 | $off += length($elements[$n + 1]); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1261 | # check for multiple assignments |
| 1262 | if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1263 | CHK("multiple assignments should be avoided\n" . $herecurr); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1266 | ## # check for multiple declarations, allowing for a function declaration |
| 1267 | ## # continuation. |
| 1268 | ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ && |
| 1269 | ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { |
| 1270 | ## |
| 1271 | ## # Remove any bracketed sections to ensure we do not |
| 1272 | ## # falsly report the parameters of functions. |
| 1273 | ## my $ln = $line; |
| 1274 | ## while ($ln =~ s/\([^\(\)]*\)//g) { |
| 1275 | ## } |
| 1276 | ## if ($ln =~ /,/) { |
| 1277 | ## WARN("declaring multiple variables together should be avoided\n" . $herecurr); |
| 1278 | ## } |
| 1279 | ## } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1280 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1281 | #need space before brace following if, while, etc |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1282 | if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || |
| 1283 | $line =~ /do{/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1284 | ERROR("need a space before the open brace '{'\n" . $herecurr); |
| 1285 | } |
| 1286 | |
| 1287 | # closing brace should have a space following it when it has anything |
| 1288 | # on the line |
| 1289 | if ($line =~ /}(?!(?:,|;|\)))\S/) { |
| 1290 | ERROR("need a space after that close brace '}'\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1293 | # check spacing on square brackets |
| 1294 | if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { |
| 1295 | ERROR("no space after that open square bracket '['\n" . $herecurr); |
| 1296 | } |
| 1297 | if ($line =~ /\s\]/) { |
| 1298 | ERROR("no space before that close square bracket ']'\n" . $herecurr); |
| 1299 | } |
| 1300 | |
| 1301 | # check spacing on paretheses |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1302 | if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && |
| 1303 | $line !~ /for\s*\(\s+;/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1304 | ERROR("no space after that open parenthesis '('\n" . $herecurr); |
| 1305 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1306 | if ($line =~ /\s\)/ && $line !~ /^.\s*\)/ && |
| 1307 | $line !~ /for\s*\(.*;\s+\)/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1308 | ERROR("no space before that close parenthesis ')'\n" . $herecurr); |
| 1309 | } |
| 1310 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1311 | #goto labels aren't indented, allow a single space however |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1312 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1313 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1314 | WARN("labels should not be indented\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | # Need a space before open parenthesis after if, while etc |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1318 | if ($line=~/\b(if|while|for|switch)\(/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1319 | ERROR("need a space before the open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | # Check for illegal assignment in if conditional. |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1323 | if ($line =~ /\bif\s*\(/) { |
| 1324 | my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); |
| 1325 | |
| 1326 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) { |
| 1327 | ERROR("do not use assignment in if condition ($c)\n" . $herecurr); |
| 1328 | } |
| 1329 | |
| 1330 | # Find out what is on the end of the line after the |
| 1331 | # conditional. |
| 1332 | substr($s, 0, length($c)) = ''; |
| 1333 | $s =~ s/\n.*//g; |
| 1334 | |
| 1335 | if (length($c) && $s !~ /^\s*({|;|\/\*.*\*\/)?\s*\\*\s*$/) { |
| 1336 | ERROR("trailing statements should be on next line\n" . $herecurr); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | # if and else should not have general statements after it |
| 1341 | if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ && |
| 1342 | $1 !~ /^\s*(?:\sif|{|\\|$)/) { |
| 1343 | ERROR("trailing statements should be on next line\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | # Check for }<nl>else {, these must be at the same |
| 1347 | # indent level to be relevant to each other. |
| 1348 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and |
| 1349 | $previndent == $indent) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1350 | ERROR("else should follow close brace '}'\n" . $hereprev); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1353 | #studly caps, commented out until figure out how to distinguish between use of existing and adding new |
| 1354 | # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { |
| 1355 | # print "No studly caps, use _\n"; |
| 1356 | # print "$herecurr"; |
| 1357 | # $clean = 0; |
| 1358 | # } |
| 1359 | |
| 1360 | #no spaces allowed after \ in define |
| 1361 | if ($line=~/\#define.*\\\s$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1362 | WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1365 | #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) |
| 1366 | if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1367 | my $checkfile = "$root/include/linux/$1.h"; |
| 1368 | if (-f $checkfile && $1 ne 'irq.h') { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1369 | CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" . |
| 1370 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1374 | # multi-statement macros should be enclosed in a do while loop, grab the |
| 1375 | # first statement and ensure its the whole macro if its not enclosed |
| 1376 | # in a known goot container |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1377 | if ($prevline =~ /\#define.*\\/ && |
| 1378 | $prevline !~/(?:do\s+{|\(\{|\{)/ && |
| 1379 | $line !~ /(?:do\s+{|\(\{|\{)/ && |
| 1380 | $line !~ /^.\s*$Declare\s/) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1381 | # Grab the first statement, if that is the entire macro |
| 1382 | # its ok. This may start either on the #define line |
| 1383 | # or the one below. |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1384 | my $ln = $linenr; |
| 1385 | my $cnt = $realcnt; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1386 | my $off = 0; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1387 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1388 | # If the macro starts on the define line start |
| 1389 | # grabbing the statement after the identifier |
| 1390 | $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$}; |
| 1391 | ##print "1<$1> 2<$2>\n"; |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1392 | if (defined $2 && $2 ne '') { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1393 | $off = length($1); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1394 | $ln--; |
| 1395 | $cnt++; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1396 | while ($lines[$ln - 1] =~ /^-/) { |
| 1397 | $ln--; |
| 1398 | $cnt++; |
| 1399 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1400 | } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1401 | my @ctx = ctx_statement($ln, $cnt, $off); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1402 | my $ctx_ln = $ln + $#ctx + 1; |
| 1403 | my $ctx = join("\n", @ctx); |
| 1404 | |
| 1405 | # Pull in any empty extension lines. |
| 1406 | while ($ctx =~ /\\$/ && |
| 1407 | $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) { |
| 1408 | $ctx .= $lines[$ctx_ln - 1]; |
| 1409 | $ctx_ln++; |
| 1410 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1411 | |
| 1412 | if ($ctx =~ /\\$/) { |
| 1413 | if ($ctx =~ /;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1414 | ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1415 | } else { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1416 | ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1417 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1418 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1421 | # check for redundant bracing round if etc |
| 1422 | if ($line =~ /\b(if|while|for|else)\b/) { |
| 1423 | # Locate the end of the opening statement. |
| 1424 | my @control = ctx_statement($linenr, $realcnt, 0); |
| 1425 | my $nr = $linenr + (scalar(@control) - 1); |
| 1426 | my $cnt = $realcnt - (scalar(@control) - 1); |
| 1427 | |
| 1428 | my $off = $realcnt - $cnt; |
| 1429 | #print "$off: line<$line>end<" . $lines[$nr - 1] . ">\n"; |
| 1430 | |
| 1431 | # If this is is a braced statement group check it |
| 1432 | if ($lines[$nr - 1] =~ /{\s*$/) { |
| 1433 | my ($lvl, @block) = ctx_block_level($nr, $cnt); |
| 1434 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1435 | my $stmt = join("\n", @block); |
| 1436 | # Drop the diff line leader. |
| 1437 | $stmt =~ s/\n./\n/g; |
| 1438 | # Drop the code outside the block. |
| 1439 | $stmt =~ s/(^[^{]*){\s*//; |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1440 | my $before = $1; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1441 | $stmt =~ s/\s*}([^}]*$)//; |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1442 | my $after = $1; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1443 | |
| 1444 | #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n"; |
| 1445 | #print "stmt<$stmt>\n\n"; |
| 1446 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1447 | # Count the newlines, if there is only one |
| 1448 | # then the block should not have {}'s. |
| 1449 | my @lines = ($stmt =~ /\n/g); |
| 1450 | #print "lines<" . scalar(@lines) . ">\n"; |
| 1451 | if ($lvl == 0 && scalar(@lines) == 0 && |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1452 | $stmt !~ /{/ && $stmt !~ /\bif\b/ && |
| 1453 | $before !~ /}/ && $after !~ /{/) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1454 | my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n"; |
| 1455 | shift(@block); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1456 | WARN("braces {} are not necessary for single statement blocks\n" . $herectx); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1461 | # don't include deprecated include files (uses RAW line) |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1462 | for my $inc (@dep_includes) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1463 | if ($rawline =~ m@\#\s*include\s*\<$inc>@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1464 | ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1468 | # don't use deprecated functions |
| 1469 | for my $func (@dep_functions) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1470 | if ($line =~ /\b$func\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1471 | ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | # no volatiles please |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1476 | my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; |
| 1477 | if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1478 | WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1481 | # SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated |
| 1482 | if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) { |
| 1483 | ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr); |
| 1484 | } |
| 1485 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1486 | # warn about #if 0 |
| 1487 | if ($line =~ /^.#\s*if\s+0\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1488 | CHK("if this code is redundant consider removing it\n" . |
| 1489 | $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1492 | # check for needless kfree() checks |
| 1493 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { |
| 1494 | my $expr = $1; |
| 1495 | if ($line =~ /\bkfree\(\Q$expr\E\);/) { |
| 1496 | WARN("kfree(NULL) is safe this check is probabally not required\n" . $hereprev); |
| 1497 | } |
| 1498 | } |
| 1499 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1500 | # warn about #ifdefs in C files |
| 1501 | # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { |
| 1502 | # print "#ifdef in C files should be avoided\n"; |
| 1503 | # print "$herecurr"; |
| 1504 | # $clean = 0; |
| 1505 | # } |
| 1506 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1507 | # warn about spacing in #ifdefs |
| 1508 | if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) { |
| 1509 | ERROR("exactly one space required after that #$1\n" . $herecurr); |
| 1510 | } |
| 1511 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1512 | # check for spinlock_t definitions without a comment. |
| 1513 | if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { |
| 1514 | my $which = $1; |
| 1515 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1516 | CHK("$1 definition without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | # check for memory barriers without a comment. |
| 1520 | if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { |
| 1521 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1522 | CHK("memory barrier without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | # check of hardware specific defines |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1526 | if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1527 | CHK("architecture specific defines should be avoided\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1528 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1529 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1530 | # check the location of the inline attribute, that it is between |
| 1531 | # storage class and type. |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1532 | if ($line =~ /\b$Type\s+$Inline\b/ || |
| 1533 | $line =~ /\b$Inline\s+$Storage\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1534 | ERROR("inline keyword should sit between storage class and type\n" . $herecurr); |
| 1535 | } |
| 1536 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1537 | # Check for __inline__ and __inline, prefer inline |
| 1538 | if ($line =~ /\b(__inline__|__inline)\b/) { |
| 1539 | WARN("plain inline is preferred over $1\n" . $herecurr); |
| 1540 | } |
| 1541 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1542 | # check for new externs in .c files. |
| 1543 | if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) { |
| 1544 | WARN("externs should be avoided in .c files\n" . $herecurr); |
| 1545 | } |
| 1546 | |
| 1547 | # checks for new __setup's |
| 1548 | if ($rawline =~ /\b__setup\("([^"]*)"/) { |
| 1549 | my $name = $1; |
| 1550 | |
| 1551 | if (!grep(/$name/, @setup_docs)) { |
| 1552 | CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); |
| 1553 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1554 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1555 | |
| 1556 | # check for pointless casting of kmalloc return |
| 1557 | if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { |
| 1558 | WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); |
| 1559 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1562 | # In mailback mode only produce a report in the negative, for |
| 1563 | # things that appear to be patches. |
| 1564 | if ($mailback && ($clean == 1 || !$is_patch)) { |
| 1565 | exit(0); |
| 1566 | } |
| 1567 | |
| 1568 | # This is not a patch, and we are are in 'no-patch' mode so |
| 1569 | # just keep quiet. |
| 1570 | if (!$chk_patch && !$is_patch) { |
| 1571 | exit(0); |
| 1572 | } |
| 1573 | |
| 1574 | if (!$is_patch) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1575 | ERROR("Does not appear to be a unified-diff format patch\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1576 | } |
| 1577 | if ($is_patch && $chk_signoff && $signoff == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1578 | ERROR("Missing Signed-off-by: line(s)\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1581 | print report_dump(); |
| 1582 | if ($summary) { |
| 1583 | print "total: $cnt_error errors, $cnt_warn warnings, " . |
| 1584 | (($check)? "$cnt_chk checks, " : "") . |
| 1585 | "$cnt_lines lines checked\n"; |
| 1586 | print "\n" if ($quiet == 0); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1587 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1588 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1589 | if ($clean == 1 && $quiet == 0) { |
| 1590 | print "Your patch has no obvious style problems and is ready for submission.\n" |
| 1591 | } |
| 1592 | if ($clean == 0 && $quiet == 0) { |
| 1593 | print "Your patch has style problems, please review. If any of these errors\n"; |
| 1594 | print "are false positives report them to the maintainer, see\n"; |
| 1595 | print "CHECKPATCH in MAINTAINERS.\n"; |
| 1596 | } |
| 1597 | return $clean; |
| 1598 | } |