| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 |
|
| 7 | use strict;
|
| 8 |
|
| 9 | my $P = $0;
|
| 10 | $P =~ s@.*/@@g;
|
| 11 |
|
| 12 | my $V = '0.04';
|
| 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;
|
| 20 | GetOptions(
|
| 21 | 'q|quiet' => \$quiet,
|
| 22 | 'tree!' => \$tree,
|
| 23 | 'signoff!' => \$chk_signoff,
|
| 24 | 'patch!' => \$chk_patch,
|
| 25 | ) or exit;
|
| 26 |
|
| 27 | my $exit = 0;
|
| 28 |
|
| 29 | if ($#ARGV < 0) {
|
| 30 | print "usage: $P [options] patchfile\n";
|
| 31 | print "version: $V\n";
|
| 32 | print "options: -q => quiet\n";
|
| 33 | print " --no-tree => run without a kernel tree\n";
|
| 34 | exit(1);
|
| 35 | }
|
| 36 |
|
| 37 | if ($tree && !top_of_kernel_tree()) {
|
| 38 | print "Must be run from the top-level dir. of a kernel tree\n";
|
| 39 | exit(2);
|
| 40 | }
|
| 41 |
|
| 42 | my @dep_includes = ();
|
| 43 | my @dep_functions = ();
|
| 44 | my $removal = 'Documentation/feature-removal-schedule.txt';
|
| 45 | if ($tree && -f $removal) {
|
| 46 | open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n";
|
| 47 | while (<REMOVE>) {
|
| 48 | if (/^Files:\s+(.*\S)/) {
|
| 49 | for my $file (split(/[, ]+/, $1)) {
|
| 50 | if ($file =~ m@include/(.*)@) {
|
| 51 | push(@dep_includes, $1);
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | } elsif (/^Funcs:\s+(.*\S)/) {
|
| 56 | for my $func (split(/[, ]+/, $1)) {
|
| 57 | push(@dep_functions, $func);
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | my @rawlines = ();
|
| 64 | while (<>) {
|
| 65 | chomp;
|
| 66 | push(@rawlines, $_);
|
| 67 | if (eof(ARGV)) {
|
| 68 | if (!process($ARGV, @rawlines)) {
|
| 69 | $exit = 1;
|
| 70 | }
|
| 71 | @rawlines = ();
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | exit($exit);
|
| 76 |
|
| 77 | sub 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 |
|
| 88 | sub 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 |
|
| 109 | sub line_stats {
|
| 110 | my ($line) = @_;
|
| 111 |
|
| 112 | |
| 113 | $line =~ s/^.//;
|
| 114 | $line = expand_tabs($line);
|
| 115 |
|
| 116 | |
| 117 | my ($white) = ($line =~ /^(\s*)/);
|
| 118 |
|
| 119 | return (length($line), length($white));
|
| 120 | }
|
| 121 |
|
| 122 | sub 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 |
|
| 153 | sub ctx_block_get {
|
| 154 | my ($linenr, $remain, $outer) = @_;
|
| 155 | my $line;
|
| 156 | my $start = $linenr - 1;
|
| 157 | my $blk = '';
|
| 158 | my @o;
|
| 159 | my @c;
|
| 160 | my @res = ();
|
| 161 |
|
| 162 | for ($line = $start; $remain > 0; $line++) {
|
| 163 | next if ($rawlines[$line] =~ /^-/);
|
| 164 | $remain--;
|
| 165 |
|
| 166 | $blk .= $rawlines[$line];
|
| 167 |
|
| 168 | @o = ($blk =~ /\{/g);
|
| 169 | @c = ($blk =~ /\}/g);
|
| 170 |
|
| 171 | if (!$outer || (scalar(@o) - scalar(@c)) == 1) {
|
| 172 | push(@res, $rawlines[$line]);
|
| 173 | }
|
| 174 |
|
| 175 | last if (scalar(@o) == scalar(@c));
|
| 176 | }
|
| 177 |
|
| 178 | return @res;
|
| 179 | }
|
| 180 | sub ctx_block_outer {
|
| 181 | my ($linenr, $remain) = @_;
|
| 182 |
|
| 183 | return ctx_block_get($linenr, $remain, 1);
|
| 184 | }
|
| 185 | sub ctx_block {
|
| 186 | my ($linenr, $remain) = @_;
|
| 187 |
|
| 188 | return ctx_block_get($linenr, $remain, 0);
|
| 189 | }
|
| 190 |
|
| 191 | sub ctx_locate_comment {
|
| 192 | my ($first_line, $end_line) = @_;
|
| 193 |
|
| 194 | |
| 195 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@);
|
| 196 | return $current_comment if (defined $current_comment);
|
| 197 |
|
| 198 | |
| 199 | |
| 200 | my $in_comment = 0;
|
| 201 | $current_comment = '';
|
| 202 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
|
| 203 | my $line = $rawlines[$linenr - 1];
|
| 204 | |
| 205 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
|
| 206 | $in_comment = 1;
|
| 207 | }
|
| 208 | if ($line =~ m@/\*@) {
|
| 209 | $in_comment = 1;
|
| 210 | }
|
| 211 | if (!$in_comment && $current_comment ne '') {
|
| 212 | $current_comment = '';
|
| 213 | }
|
| 214 | $current_comment .= $line . "\n" if ($in_comment);
|
| 215 | if ($line =~ m@\*/@) {
|
| 216 | $in_comment = 0;
|
| 217 | }
|
| 218 | }
|
| 219 |
|
| 220 | chomp($current_comment);
|
| 221 | return($current_comment);
|
| 222 | }
|
| 223 | sub ctx_has_comment {
|
| 224 | my ($first_line, $end_line) = @_;
|
| 225 | my $cmt = ctx_locate_comment($first_line, $end_line);
|
| 226 |
|
| 227 | |
| 228 | |
| 229 |
|
| 230 | return ($cmt ne '');
|
| 231 | }
|
| 232 |
|
| 233 | sub cat_vet {
|
| 234 | my ($vet) = @_;
|
| 235 |
|
| 236 | $vet =~ s/\t/^I/;
|
| 237 | $vet =~ s/$/\$/;
|
| 238 |
|
| 239 | return $vet;
|
| 240 | }
|
| 241 |
|
| 242 | sub process {
|
| 243 | my $filename = shift;
|
| 244 | my @lines = @_;
|
| 245 |
|
| 246 | my $linenr=0;
|
| 247 | my $prevline="";
|
| 248 | my $stashline="";
|
| 249 |
|
| 250 | my $length;
|
| 251 | my $indent;
|
| 252 | my $previndent=0;
|
| 253 | my $stashindent=0;
|
| 254 |
|
| 255 | my $clean = 1;
|
| 256 | my $signoff = 0;
|
| 257 | my $is_patch = 0;
|
| 258 |
|
| 259 | |
| 260 | my $realfile = '';
|
| 261 | my $realline = 0;
|
| 262 | my $realcnt = 0;
|
| 263 | my $here = '';
|
| 264 | my $in_comment = 0;
|
| 265 | my $first_line = 0;
|
| 266 |
|
| 267 | foreach my $line (@lines) {
|
| 268 | $linenr++;
|
| 269 |
|
| 270 | |
| 271 | if ($line=~/^\+\+\+\s+(\S+)/) {
|
| 272 | $realfile=$1;
|
| 273 | $realfile =~ s@^[^/]*/@@;
|
| 274 | $in_comment = 0;
|
| 275 | next;
|
| 276 | }
|
| 277 | |
| 278 | if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) {
|
| 279 | $is_patch = 1;
|
| 280 | $first_line = $linenr + 1;
|
| 281 | $in_comment = 0;
|
| 282 | $realline=$1-1;
|
| 283 | if (defined $2) {
|
| 284 | $realcnt=$3+1;
|
| 285 | } else {
|
| 286 | $realcnt=1+1;
|
| 287 | }
|
| 288 | next;
|
| 289 | }
|
| 290 |
|
| 291 | |
| 292 | |
| 293 | |
| 294 | if ($line =~ /^( |\+|$)/) {
|
| 295 | $realline++;
|
| 296 |
|
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
|
| 305 | $in_comment = 1;
|
| 306 | }
|
| 307 | if ($line =~ m@/\*@) {
|
| 308 | $in_comment = 1;
|
| 309 | }
|
| 310 | if ($line =~ m@\*/@) {
|
| 311 | $in_comment = 0;
|
| 312 | }
|
| 313 |
|
| 314 | |
| 315 | ($length, $indent) = line_stats($line);
|
| 316 |
|
| 317 | |
| 318 | ($prevline, $stashline) = ($stashline, $line);
|
| 319 | ($previndent, $stashindent) = ($stashindent, $indent);
|
| 320 | }
|
| 321 | $realcnt-- if ($realcnt != 0);
|
| 322 |
|
| 323 | |
| 324 | $here = "#$linenr: ";
|
| 325 | $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
|
| 326 |
|
| 327 | my $hereline = "$here\n$line\n";
|
| 328 | my $herecurr = "$here\n$line\n\n";
|
| 329 | my $hereprev = "$here\n$prevline\n$line\n\n";
|
| 330 |
|
| 331 | |
| 332 | if ($line =~ /^\s*Signed-off-by:\s/) {
|
| 333 | $signoff++;
|
| 334 |
|
| 335 | } elsif ($line =~ /^\s*signed-off-by:/i) {
|
| 336 | |
| 337 | $signoff++;
|
| 338 | if (!($line =~ /^\s*Signed-off-by:/)) {
|
| 339 | print "use Signed-off-by:\n";
|
| 340 | print "$herecurr";
|
| 341 | $clean = 0;
|
| 342 | }
|
| 343 | if ($line =~ /^\s*signed-off-by:\S/i) {
|
| 344 | print "need space after Signed-off-by:\n";
|
| 345 | print "$herecurr";
|
| 346 | $clean = 0;
|
| 347 | }
|
| 348 | }
|
| 349 |
|
| 350 | |
| 351 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) {
|
| 352 | print "patch seems to be corrupt (line wrapped?) [$realcnt]\n";
|
| 353 | print "$herecurr";
|
| 354 | $clean = 0;
|
| 355 | }
|
| 356 |
|
| 357 | |
| 358 | if ($line=~/^-/) {next;}
|
| 359 |
|
| 360 | |
| 361 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
|
| 362 |
|
| 363 | |
| 364 | if ($line=~/\+.*\S\s+$/) {
|
| 365 | my $herevet = "$here\n" . cat_vet($line) . "\n\n";
|
| 366 | print "trailing whitespace\n";
|
| 367 | print "$herevet";
|
| 368 | $clean = 0;
|
| 369 | }
|
| 370 | |
| 371 | if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
|
| 372 | print "line over 80 characters\n";
|
| 373 | print "$herecurr";
|
| 374 | $clean = 0;
|
| 375 | }
|
| 376 |
|
| 377 | |
| 378 | next if ($realfile !~ /\.[hc]$/);
|
| 379 |
|
| 380 | |
| 381 | |
| 382 | if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) {
|
| 383 | my $herevet = "$here\n" . cat_vet($line) . "\n\n";
|
| 384 | print "use tabs not spaces\n";
|
| 385 | print "$herevet";
|
| 386 | $clean = 0;
|
| 387 | }
|
| 388 |
|
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | next if ($in_comment);
|
| 394 |
|
| 395 | |
| 396 | $line =~ s@/\*.*\*/@@g;
|
| 397 | $line =~ s@/\*.*@@;
|
| 398 | $line =~ s@.*\*/@@;
|
| 399 |
|
| 400 | |
| 401 | |
| 402 | |
| 403 |
|
| 404 | |
| 405 | |
| 406 | if ($line=~/\bswitch\s*\(.*\)/) {
|
| 407 | my $err = '';
|
| 408 | my $sep = '';
|
| 409 | my @ctx = ctx_block_outer($linenr, $realcnt);
|
| 410 | shift(@ctx);
|
| 411 | for my $ctx (@ctx) {
|
| 412 | my ($clen, $cindent) = line_stats($ctx);
|
| 413 | if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
|
| 414 | $indent != $cindent) {
|
| 415 | $err .= "$sep$ctx\n";
|
| 416 | $sep = '';
|
| 417 | } else {
|
| 418 | $sep = "[...]\n";
|
| 419 | }
|
| 420 | }
|
| 421 | if ($err ne '') {
|
| 422 | print "switch and case should be at the same indent\n";
|
| 423 | print "$here\n$line\n$err\n";
|
| 424 | $clean = 0;
|
| 425 | }
|
| 426 | }
|
| 427 |
|
| 428 | |
| 429 | if ($line=~/^[^\+]/) {next;}
|
| 430 |
|
| 431 | |
| 432 | |
| 433 | |
| 434 |
|
| 435 | |
| 436 | if ($line =~ m{//}) {
|
| 437 | print "do not use C99 // comments\n";
|
| 438 | print "$herecurr";
|
| 439 | $clean = 0;
|
| 440 | }
|
| 441 | |
| 442 | $line =~ s@//.*@@;
|
| 443 |
|
| 444 | |
| 445 | |
| 446 | $line = sanitise_line($line);
|
| 447 |
|
| 448 | |
| 449 | if (($line =~ /EXPORT_SYMBOL.*\(.*\)/) ||
|
| 450 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\(.*\)/)) {
|
| 451 | if (($prevline !~ /^}/) &&
|
| 452 | ($prevline !~ /^\+}/) &&
|
| 453 | ($prevline !~ /^ }/)) {
|
| 454 | print "EXPORT_SYMBOL(func); should immediately follow its function\n";
|
| 455 | print "$herecurr";
|
| 456 | $clean = 0;
|
| 457 | }
|
| 458 | }
|
| 459 |
|
| 460 | |
| 461 | if ($line=~/\s*static\s.*=\s+(0|NULL);/) {
|
| 462 | print "do not initialise statics to 0 or NULL\n";
|
| 463 | print "$herecurr";
|
| 464 | $clean = 0;
|
| 465 | }
|
| 466 |
|
| 467 | |
| 468 | if ($line=~/\s*typedef\s/) {
|
| 469 | print "do not add new typedefs\n";
|
| 470 | print "$herecurr";
|
| 471 | $clean = 0;
|
| 472 | }
|
| 473 |
|
| 474 | |
| 475 | my $type = '(?:char|short|int|long|unsigned|float|double|' .
|
| 476 | 'struct\s+[A-Za-z\d_]+|' .
|
| 477 | 'union\s+[A-Za-z\d_]+)';
|
| 478 |
|
| 479 | if ($line =~ m{[A-Za-z\d_]+(\*+) [A-Za-z\d_]+}) {
|
| 480 | print "\"foo$1 bar\" should be \"foo $1bar\"\n";
|
| 481 | print "$herecurr";
|
| 482 | $clean = 0;
|
| 483 | }
|
| 484 | if ($line =~ m{$type (\*) [A-Za-z\d_]+} ||
|
| 485 | $line =~ m{[A-Za-z\d_]+ (\*\*+) [A-Za-z\d_]+}) {
|
| 486 | print "\"foo $1 bar\" should be \"foo $1bar\"\n";
|
| 487 | print "$herecurr";
|
| 488 | $clean = 0;
|
| 489 | }
|
| 490 | if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_](\*+)\)}) {
|
| 491 | print "\"(foo$1)\" should be \"(foo $1)\"\n";
|
| 492 | print "$herecurr";
|
| 493 | $clean = 0;
|
| 494 | }
|
| 495 | if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_]\s+(\*+)\s+\)}) {
|
| 496 | print "\"(foo $1 )\" should be \"(foo $1)\"\n";
|
| 497 | print "$herecurr";
|
| 498 | $clean = 0;
|
| 499 | }
|
| 500 |
|
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 |
|
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | if ($line =~ /\bprintk\((?!KERN_)/) {
|
| 514 | my $ok = 0;
|
| 515 | for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
|
| 516 | |
| 517 | |
| 518 | |
| 519 | if ($lines[$ln - 1] =~ m{\bprintk\(}) {
|
| 520 | if ($rawlines[$ln - 1] !~ m{\\n"}) {
|
| 521 | $ok = 1;
|
| 522 | }
|
| 523 | last;
|
| 524 | }
|
| 525 | }
|
| 526 | if ($ok == 0) {
|
| 527 | print "printk() should include KERN_ facility level\n";
|
| 528 | print "$herecurr";
|
| 529 | $clean = 0;
|
| 530 | }
|
| 531 | }
|
| 532 |
|
| 533 | |
| 534 | if (($line=~/[A-Za-z\d_]+\**\s+\**[A-Za-z\d_]+\(.*\).* {/) and
|
| 535 | !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
|
| 536 | print "braces following function declarations go on the next line\n";
|
| 537 | print "$herecurr";
|
| 538 | $clean = 0;
|
| 539 | }
|
| 540 | |
| 541 | |
| 542 | |
| 543 | my $opline = $line;
|
| 544 | $opline = expand_tabs($opline);
|
| 545 | $opline =~ s/^./ /;
|
| 546 | if (!($line=~/\#\s*include/)) {
|
| 547 | |
| 548 | my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline);
|
| 549 | my $off = 0;
|
| 550 | for (my $n = 0; $n < $#elements; $n += 2) {
|
| 551 | $off += length($elements[$n]);
|
| 552 |
|
| 553 | my $a = '';
|
| 554 | $a = 'V' if ($elements[$n] ne '');
|
| 555 | $a = 'W' if ($elements[$n] =~ /\s$/);
|
| 556 | $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
|
| 557 | $a = 'O' if ($elements[$n] eq '');
|
| 558 | $a = 'E' if ($elements[$n] eq '' && $n == 0);
|
| 559 |
|
| 560 | my $op = $elements[$n + 1];
|
| 561 |
|
| 562 | my $c = '';
|
| 563 | if (defined $elements[$n + 2]) {
|
| 564 | $c = 'V' if ($elements[$n + 2] ne '');
|
| 565 | $c = 'W' if ($elements[$n + 2] =~ /^\s/);
|
| 566 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
|
| 567 | $c = 'O' if ($elements[$n + 2] eq '');
|
| 568 | } else {
|
| 569 | $c = 'E';
|
| 570 | }
|
| 571 |
|
| 572 | |
| 573 | my $ca = substr($opline, $off - 1, 1);
|
| 574 | my $cc = '';
|
| 575 | if (length($opline) > ($off + length($elements[$n]))) {
|
| 576 | $cc = substr($opline, $off + 1 + length($elements[$n]), 1);
|
| 577 | }
|
| 578 |
|
| 579 | my $ctx = "${a}x${c}";
|
| 580 |
|
| 581 | my $at = "(ctx:$ctx)";
|
| 582 |
|
| 583 | my $ptr = (" " x $off) . "^";
|
| 584 | my $hereptr = "$hereline$ptr\n\n";
|
| 585 |
|
| 586 | |
| 587 |
|
| 588 | |
| 589 | if ($op eq ';' or $op eq '//') {
|
| 590 |
|
| 591 | |
| 592 | } elsif ($op eq '->') {
|
| 593 | if ($ctx =~ /Wx.|.xW/) {
|
| 594 | print "no spaces around that '$op' $at\n";
|
| 595 | print "$hereptr";
|
| 596 | $clean = 0;
|
| 597 | }
|
| 598 |
|
| 599 | |
| 600 | } elsif ($op eq ',') {
|
| 601 | if ($ctx !~ /.xW|.xE/) {
|
| 602 | print "need space after that '$op' $at\n";
|
| 603 | print "$hereptr";
|
| 604 | $clean = 0;
|
| 605 | }
|
| 606 |
|
| 607 | |
| 608 | } elsif ($op eq '!' or $op eq '~') {
|
| 609 | if ($ctx !~ /[WOEB]x./) {
|
| 610 | print "need space before that '$op' $at\n";
|
| 611 | print "$hereptr";
|
| 612 | $clean = 0;
|
| 613 | }
|
| 614 | if ($ctx =~ /.xW/) {
|
| 615 | print "no space after that '$op' $at\n";
|
| 616 | print "$hereptr";
|
| 617 | $clean = 0;
|
| 618 | }
|
| 619 |
|
| 620 | |
| 621 | } elsif ($op eq '++' or $op eq '--') {
|
| 622 | if ($ctx !~ /[WOB]x[^W]|[^W]x[WOB]/) {
|
| 623 | print "need space one side of that '$op' $at\n";
|
| 624 | print "$hereptr";
|
| 625 | $clean = 0;
|
| 626 | }
|
| 627 |
|
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | } elsif ($op eq '&' or $op eq '-') {
|
| 641 | if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) {
|
| 642 | print "need space before that '$op' $at\n";
|
| 643 | print "$hereptr";
|
| 644 | $clean = 0;
|
| 645 | }
|
| 646 |
|
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | } elsif ($op eq '*') {
|
| 653 | if ($ca eq '*') {
|
| 654 | if ($cc =~ /\s/) {
|
| 655 | print "no space after that '$op' $at\n";
|
| 656 | print "$hereptr";
|
| 657 | $clean = 0;
|
| 658 | }
|
| 659 | } elsif ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB/) {
|
| 660 | print "need space before that '$op' $at\n";
|
| 661 | print "$hereptr";
|
| 662 | $clean = 0;
|
| 663 | }
|
| 664 |
|
| 665 | |
| 666 | } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or
|
| 667 | $op eq '^' or $op eq '|')
|
| 668 | {
|
| 669 | if ($ctx !~ /VxV|WxW|VxE|WxE/) {
|
| 670 | print "need consistent spacing around '$op' $at\n";
|
| 671 | print "$hereptr";
|
| 672 | $clean = 0;
|
| 673 | }
|
| 674 |
|
| 675 | |
| 676 | } elsif ($ctx !~ /[EW]x[WE]/) {
|
| 677 | print "need spaces around that '$op' $at\n";
|
| 678 | print "$hereptr";
|
| 679 | $clean = 0;
|
| 680 | }
|
| 681 | $off += length($elements[$n + 1]);
|
| 682 | }
|
| 683 | }
|
| 684 |
|
| 685 | |
| 686 | if ($line=~/\(.*\){/) {
|
| 687 | print "need a space before the brace\n";
|
| 688 | print "$herecurr";
|
| 689 | $clean = 0;
|
| 690 | }
|
| 691 |
|
| 692 | |
| 693 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
|
| 694 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
|
| 695 | print "labels should not be indented\n";
|
| 696 | print "$herecurr";
|
| 697 | $clean = 0;
|
| 698 | }
|
| 699 |
|
| 700 | |
| 701 | if ($line=~/\b(if|while|for|switch)\(/) {
|
| 702 | print "need a space before the open parenthesis\n";
|
| 703 | print "$herecurr";
|
| 704 | $clean = 0;
|
| 705 | }
|
| 706 |
|
| 707 | |
| 708 | if ($line=~/\b(if|while)\s*\(.*[^<>!=]=[^=].*\)/) {
|
| 709 | |
| 710 | print "do not use assignment in condition\n";
|
| 711 | print "$herecurr";
|
| 712 | $clean = 0;
|
| 713 | }
|
| 714 |
|
| 715 | |
| 716 | |
| 717 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
|
| 718 | $previndent == $indent) {
|
| 719 | print "else should follow close brace\n";
|
| 720 | print "$hereprev";
|
| 721 | $clean = 0;
|
| 722 | }
|
| 723 |
|
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 |
|
| 731 | |
| 732 | if ($line=~/\#define.*\\\s$/) {
|
| 733 | print("Whitepspace after \\ makes next lines useless\n");
|
| 734 | print "$herecurr";
|
| 735 | $clean = 0;
|
| 736 | }
|
| 737 |
|
| 738 | |
| 739 | if ($tree && $line =~ qr|\s*\#\s*include\s*\<asm\/(.*)\.h\>|) {
|
| 740 | my $checkfile = "include/linux/$1.h";
|
| 741 | if (-f $checkfile) {
|
| 742 | print "Use #include <linux/$1.h> instead of <asm/$1.h>\n";
|
| 743 | print $herecurr;
|
| 744 | $clean = 0;
|
| 745 | }
|
| 746 | }
|
| 747 |
|
| 748 | |
| 749 | if ($prevline=~/\b(if|while|for|switch)\s*\(/) {
|
| 750 | my @opened = $prevline=~/\(/g;
|
| 751 | my @closed = $prevline=~/\)/g;
|
| 752 | my $nr_line = $linenr;
|
| 753 | my $remaining = $realcnt - 1;
|
| 754 | my $next_line = $line;
|
| 755 | my $extra_lines = 0;
|
| 756 | my $display_segment = $prevline;
|
| 757 |
|
| 758 | while ($remaining > 0 && scalar @opened > scalar @closed) {
|
| 759 | $prevline .= $next_line;
|
| 760 | $display_segment .= "\n" . $next_line;
|
| 761 | $next_line = $lines[$nr_line];
|
| 762 | $nr_line++;
|
| 763 | $remaining--;
|
| 764 |
|
| 765 | @opened = $prevline=~/\(/g;
|
| 766 | @closed = $prevline=~/\)/g;
|
| 767 | }
|
| 768 |
|
| 769 | if (($prevline=~/\b(if|while|for|switch)\s*\(.*\)\s*$/) and ($next_line=~/{/) and
|
| 770 | !($next_line=~/\b(if|while|for)/) and !($next_line=~/\#define.*do.*while/)) {
|
| 771 | print "That { should be on the previous line\n";
|
| 772 | print "$here\n$display_segment\n$next_line\n\n";
|
| 773 | $clean = 0;
|
| 774 | }
|
| 775 | }
|
| 776 |
|
| 777 | |
| 778 | if (($prevline=~/\#define.*\\/) and !($prevline=~/do\s+{/) and
|
| 779 | !($prevline=~/\(\{/) and ($line=~/;\s*\\/) and
|
| 780 | !($line=~/do.*{/) and !($line=~/\(\{/)) {
|
| 781 | print "Macros with multiple statements should be enclosed in a do - while loop\n";
|
| 782 | print "$hereprev";
|
| 783 | $clean = 0;
|
| 784 | }
|
| 785 |
|
| 786 | |
| 787 | for my $inc (@dep_includes) {
|
| 788 | if ($line =~ m@\#\s*include\s*\<$inc>@) {
|
| 789 | print "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n";
|
| 790 | print "$herecurr";
|
| 791 | $clean = 0;
|
| 792 | }
|
| 793 | }
|
| 794 |
|
| 795 | |
| 796 | for my $func (@dep_functions) {
|
| 797 | if ($line =~ /\b$func\b/) {
|
| 798 | print "Don't use $func(): see Documentation/feature-removal-schedule.txt\n";
|
| 799 | print "$herecurr";
|
| 800 | $clean = 0;
|
| 801 | }
|
| 802 | }
|
| 803 |
|
| 804 | |
| 805 | if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) {
|
| 806 | print "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n";
|
| 807 | print "$herecurr";
|
| 808 | $clean = 0;
|
| 809 | }
|
| 810 |
|
| 811 | |
| 812 | if ($line =~ /^.#\s*if\s+0\b/) {
|
| 813 | print "#if 0 -- if this code redundant remove it\n";
|
| 814 | print "$herecurr";
|
| 815 | $clean = 0;
|
| 816 | }
|
| 817 |
|
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 |
|
| 825 | |
| 826 | if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
|
| 827 | my $which = $1;
|
| 828 | if (!ctx_has_comment($first_line, $linenr)) {
|
| 829 | print "$1 definition without comment\n";
|
| 830 | print "$herecurr";
|
| 831 | $clean = 0;
|
| 832 | }
|
| 833 | }
|
| 834 | |
| 835 | if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
|
| 836 | if (!ctx_has_comment($first_line, $linenr)) {
|
| 837 | print "memory barrier without comment\n";
|
| 838 | print "$herecurr";
|
| 839 | $clean = 0;
|
| 840 | }
|
| 841 | }
|
| 842 | |
| 843 | if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) {
|
| 844 | print "architecture specific defines should be avoided\n";
|
| 845 | print "$herecurr";
|
| 846 | $clean = 0;
|
| 847 | }
|
| 848 | }
|
| 849 |
|
| 850 | if ($chk_patch && !$is_patch) {
|
| 851 | $clean = 0;
|
| 852 | print "Does not appear to be a unified-diff format patch\n";
|
| 853 | }
|
| 854 | if ($is_patch && $chk_signoff && $signoff == 0) {
|
| 855 | $clean = 0;
|
| 856 | print "Missing Signed-off-by: line(s)\n";
|
| 857 | }
|
| 858 |
|
| 859 | if ($clean == 1 && $quiet == 0) {
|
| 860 | print "Your patch has no obvious style problems and is ready for submission.\n"
|
| 861 | }
|
| 862 | if ($clean == 0 && $quiet == 0) {
|
| 863 | print "Your patch has style problems, please review. If any of these errors\n";
|
| 864 | print "are false positives report them to the maintainer, see\n";
|
| 865 | print "CHECKPATCH in MAINTAINERS.\n";
|
| 866 | }
|
| 867 | return $clean;
|
| 868 | }
|