diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 687 |
1 files changed, 568 insertions, 119 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 182be0f12407..374abf443636 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -9,7 +9,8 @@ use strict; | |||
| 9 | use POSIX; | 9 | use POSIX; |
| 10 | 10 | ||
| 11 | my $P = $0; | 11 | my $P = $0; |
| 12 | $P =~ s@.*/@@g; | 12 | $P =~ s@(.*)/@@g; |
| 13 | my $D = $1; | ||
| 13 | 14 | ||
| 14 | my $V = '0.32'; | 15 | my $V = '0.32'; |
| 15 | 16 | ||
| @@ -43,6 +44,8 @@ my $configuration_file = ".checkpatch.conf"; | |||
| 43 | my $max_line_length = 80; | 44 | my $max_line_length = 80; |
| 44 | my $ignore_perl_version = 0; | 45 | my $ignore_perl_version = 0; |
| 45 | my $minimum_perl_version = 5.10.0; | 46 | my $minimum_perl_version = 5.10.0; |
| 47 | my $min_conf_desc_length = 4; | ||
| 48 | my $spelling_file = "$D/spelling.txt"; | ||
| 46 | 49 | ||
| 47 | sub help { | 50 | sub help { |
| 48 | my ($exitcode) = @_; | 51 | my ($exitcode) = @_; |
| @@ -63,6 +66,7 @@ Options: | |||
| 63 | --types TYPE(,TYPE2...) show only these comma separated message types | 66 | --types TYPE(,TYPE2...) show only these comma separated message types |
| 64 | --ignore TYPE(,TYPE2...) ignore various comma separated message types | 67 | --ignore TYPE(,TYPE2...) ignore various comma separated message types |
| 65 | --max-line-length=n set the maximum line length, if exceeded, warn | 68 | --max-line-length=n set the maximum line length, if exceeded, warn |
| 69 | --min-conf-desc-length=n set the min description length, if shorter, warn | ||
| 66 | --show-types show the message "types" in the output | 70 | --show-types show the message "types" in the output |
| 67 | --root=PATH PATH to the kernel tree root | 71 | --root=PATH PATH to the kernel tree root |
| 68 | --no-summary suppress the per-file summary | 72 | --no-summary suppress the per-file summary |
| @@ -131,6 +135,7 @@ GetOptions( | |||
| 131 | 'types=s' => \@use, | 135 | 'types=s' => \@use, |
| 132 | 'show-types!' => \$show_types, | 136 | 'show-types!' => \$show_types, |
| 133 | 'max-line-length=i' => \$max_line_length, | 137 | 'max-line-length=i' => \$max_line_length, |
| 138 | 'min-conf-desc-length=i' => \$min_conf_desc_length, | ||
| 134 | 'root=s' => \$root, | 139 | 'root=s' => \$root, |
| 135 | 'summary!' => \$summary, | 140 | 'summary!' => \$summary, |
| 136 | 'mailback!' => \$mailback, | 141 | 'mailback!' => \$mailback, |
| @@ -309,9 +314,12 @@ our $Operators = qr{ | |||
| 309 | our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; | 314 | our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; |
| 310 | 315 | ||
| 311 | our $NonptrType; | 316 | our $NonptrType; |
| 317 | our $NonptrTypeMisordered; | ||
| 312 | our $NonptrTypeWithAttr; | 318 | our $NonptrTypeWithAttr; |
| 313 | our $Type; | 319 | our $Type; |
| 320 | our $TypeMisordered; | ||
| 314 | our $Declare; | 321 | our $Declare; |
| 322 | our $DeclareMisordered; | ||
| 315 | 323 | ||
| 316 | our $NON_ASCII_UTF8 = qr{ | 324 | our $NON_ASCII_UTF8 = qr{ |
| 317 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | 325 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
| @@ -353,16 +361,36 @@ our $signature_tags = qr{(?xi: | |||
| 353 | Cc: | 361 | Cc: |
| 354 | )}; | 362 | )}; |
| 355 | 363 | ||
| 364 | our @typeListMisordered = ( | ||
| 365 | qr{char\s+(?:un)?signed}, | ||
| 366 | qr{int\s+(?:(?:un)?signed\s+)?short\s}, | ||
| 367 | qr{int\s+short(?:\s+(?:un)?signed)}, | ||
| 368 | qr{short\s+int(?:\s+(?:un)?signed)}, | ||
| 369 | qr{(?:un)?signed\s+int\s+short}, | ||
| 370 | qr{short\s+(?:un)?signed}, | ||
| 371 | qr{long\s+int\s+(?:un)?signed}, | ||
| 372 | qr{int\s+long\s+(?:un)?signed}, | ||
| 373 | qr{long\s+(?:un)?signed\s+int}, | ||
| 374 | qr{int\s+(?:un)?signed\s+long}, | ||
| 375 | qr{int\s+(?:un)?signed}, | ||
| 376 | qr{int\s+long\s+long\s+(?:un)?signed}, | ||
| 377 | qr{long\s+long\s+int\s+(?:un)?signed}, | ||
| 378 | qr{long\s+long\s+(?:un)?signed\s+int}, | ||
| 379 | qr{long\s+long\s+(?:un)?signed}, | ||
| 380 | qr{long\s+(?:un)?signed}, | ||
| 381 | ); | ||
| 382 | |||
| 356 | our @typeList = ( | 383 | our @typeList = ( |
| 357 | qr{void}, | 384 | qr{void}, |
| 358 | qr{(?:unsigned\s+)?char}, | 385 | qr{(?:(?:un)?signed\s+)?char}, |
| 359 | qr{(?:unsigned\s+)?short}, | 386 | qr{(?:(?:un)?signed\s+)?short\s+int}, |
| 360 | qr{(?:unsigned\s+)?int}, | 387 | qr{(?:(?:un)?signed\s+)?short}, |
| 361 | qr{(?:unsigned\s+)?long}, | 388 | qr{(?:(?:un)?signed\s+)?int}, |
| 362 | qr{(?:unsigned\s+)?long\s+int}, | 389 | qr{(?:(?:un)?signed\s+)?long\s+int}, |
| 363 | qr{(?:unsigned\s+)?long\s+long}, | 390 | qr{(?:(?:un)?signed\s+)?long\s+long\s+int}, |
| 364 | qr{(?:unsigned\s+)?long\s+long\s+int}, | 391 | qr{(?:(?:un)?signed\s+)?long\s+long}, |
| 365 | qr{unsigned}, | 392 | qr{(?:(?:un)?signed\s+)?long}, |
| 393 | qr{(?:un)?signed}, | ||
| 366 | qr{float}, | 394 | qr{float}, |
| 367 | qr{double}, | 395 | qr{double}, |
| 368 | qr{bool}, | 396 | qr{bool}, |
| @@ -372,6 +400,7 @@ our @typeList = ( | |||
| 372 | qr{${Ident}_t}, | 400 | qr{${Ident}_t}, |
| 373 | qr{${Ident}_handler}, | 401 | qr{${Ident}_handler}, |
| 374 | qr{${Ident}_handler_fn}, | 402 | qr{${Ident}_handler_fn}, |
| 403 | @typeListMisordered, | ||
| 375 | ); | 404 | ); |
| 376 | our @typeListWithAttr = ( | 405 | our @typeListWithAttr = ( |
| 377 | @typeList, | 406 | @typeList, |
| @@ -399,20 +428,41 @@ foreach my $entry (@mode_permission_funcs) { | |||
| 399 | $mode_perms_search .= $entry->[0]; | 428 | $mode_perms_search .= $entry->[0]; |
| 400 | } | 429 | } |
| 401 | 430 | ||
| 402 | our $declaration_macros = qr{(?x: | ||
| 403 | (?:$Storage\s+)?(?:DECLARE|DEFINE)_[A-Z]+\s*\(| | ||
| 404 | (?:$Storage\s+)?LIST_HEAD\s*\( | ||
| 405 | )}; | ||
| 406 | |||
| 407 | our $allowed_asm_includes = qr{(?x: | 431 | our $allowed_asm_includes = qr{(?x: |
| 408 | irq| | 432 | irq| |
| 409 | memory | 433 | memory| |
| 434 | time| | ||
| 435 | reboot | ||
| 410 | )}; | 436 | )}; |
| 411 | # memory.h: ARM has a custom one | 437 | # memory.h: ARM has a custom one |
| 412 | 438 | ||
| 439 | # Load common spelling mistakes and build regular expression list. | ||
| 440 | my $misspellings; | ||
| 441 | my @spelling_list; | ||
| 442 | my %spelling_fix; | ||
| 443 | open(my $spelling, '<', $spelling_file) | ||
| 444 | or die "$P: Can't open $spelling_file for reading: $!\n"; | ||
| 445 | while (<$spelling>) { | ||
| 446 | my $line = $_; | ||
| 447 | |||
| 448 | $line =~ s/\s*\n?$//g; | ||
| 449 | $line =~ s/^\s*//g; | ||
| 450 | |||
| 451 | next if ($line =~ m/^\s*#/); | ||
| 452 | next if ($line =~ m/^\s*$/); | ||
| 453 | |||
| 454 | my ($suspect, $fix) = split(/\|\|/, $line); | ||
| 455 | |||
| 456 | push(@spelling_list, $suspect); | ||
| 457 | $spelling_fix{$suspect} = $fix; | ||
| 458 | } | ||
| 459 | close($spelling); | ||
| 460 | $misspellings = join("|", @spelling_list); | ||
| 461 | |||
| 413 | sub build_types { | 462 | sub build_types { |
| 414 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; | 463 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; |
| 415 | my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; | 464 | my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; |
| 465 | my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; | ||
| 416 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; | 466 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; |
| 417 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; | 467 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; |
| 418 | $NonptrType = qr{ | 468 | $NonptrType = qr{ |
| @@ -424,6 +474,13 @@ sub build_types { | |||
| 424 | ) | 474 | ) |
| 425 | (?:\s+$Modifier|\s+const)* | 475 | (?:\s+$Modifier|\s+const)* |
| 426 | }x; | 476 | }x; |
| 477 | $NonptrTypeMisordered = qr{ | ||
| 478 | (?:$Modifier\s+|const\s+)* | ||
| 479 | (?: | ||
| 480 | (?:${Misordered}\b) | ||
| 481 | ) | ||
| 482 | (?:\s+$Modifier|\s+const)* | ||
| 483 | }x; | ||
| 427 | $NonptrTypeWithAttr = qr{ | 484 | $NonptrTypeWithAttr = qr{ |
| 428 | (?:$Modifier\s+|const\s+)* | 485 | (?:$Modifier\s+|const\s+)* |
| 429 | (?: | 486 | (?: |
| @@ -435,10 +492,16 @@ sub build_types { | |||
| 435 | }x; | 492 | }x; |
| 436 | $Type = qr{ | 493 | $Type = qr{ |
| 437 | $NonptrType | 494 | $NonptrType |
| 438 | (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)? | 495 | (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? |
| 496 | (?:\s+$Inline|\s+$Modifier)* | ||
| 497 | }x; | ||
| 498 | $TypeMisordered = qr{ | ||
| 499 | $NonptrTypeMisordered | ||
| 500 | (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? | ||
| 439 | (?:\s+$Inline|\s+$Modifier)* | 501 | (?:\s+$Inline|\s+$Modifier)* |
| 440 | }x; | 502 | }x; |
