diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 263 |
1 files changed, 192 insertions, 71 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 374abf443636..f0bb6d60c07b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -7,10 +7,11 @@ | |||
| 7 | 7 | ||
| 8 | use strict; | 8 | use strict; |
| 9 | use POSIX; | 9 | use POSIX; |
| 10 | use File::Basename; | ||
| 11 | use Cwd 'abs_path'; | ||
| 10 | 12 | ||
| 11 | my $P = $0; | 13 | my $P = $0; |
| 12 | $P =~ s@(.*)/@@g; | 14 | my $D = dirname(abs_path($P)); |
| 13 | my $D = $1; | ||
| 14 | 15 | ||
| 15 | my $V = '0.32'; | 16 | my $V = '0.32'; |
| 16 | 17 | ||
| @@ -438,26 +439,29 @@ our $allowed_asm_includes = qr{(?x: | |||
| 438 | 439 | ||
| 439 | # Load common spelling mistakes and build regular expression list. | 440 | # Load common spelling mistakes and build regular expression list. |
| 440 | my $misspellings; | 441 | my $misspellings; |
| 441 | my @spelling_list; | ||
| 442 | my %spelling_fix; | 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 | 443 | ||
| 448 | $line =~ s/\s*\n?$//g; | 444 | if (open(my $spelling, '<', $spelling_file)) { |
| 449 | $line =~ s/^\s*//g; | 445 | my @spelling_list; |
| 446 | while (<$spelling>) { | ||
| 447 | my $line = $_; | ||
| 450 | 448 | ||
| 451 | next if ($line =~ m/^\s*#/); | 449 | $line =~ s/\s*\n?$//g; |
| 452 | next if ($line =~ m/^\s*$/); | 450 | $line =~ s/^\s*//g; |
| 453 | 451 | ||
| 454 | my ($suspect, $fix) = split(/\|\|/, $line); | 452 | next if ($line =~ m/^\s*#/); |
| 453 | next if ($line =~ m/^\s*$/); | ||
| 455 | 454 | ||
| 456 | push(@spelling_list, $suspect); | 455 | my ($suspect, $fix) = split(/\|\|/, $line); |
| 457 | $spelling_fix{$suspect} = $fix; | 456 | |
| 457 | push(@spelling_list, $suspect); | ||
| 458 | $spelling_fix{$suspect} = $fix; | ||
| 459 | } | ||
| 460 | close($spelling); | ||
| 461 | $misspellings = join("|", @spelling_list); | ||
| 462 | } else { | ||
| 463 | warn "No typos will be found - file '$spelling_file': $!\n"; | ||
| 458 | } | 464 | } |
| 459 | close($spelling); | ||
| 460 | $misspellings = join("|", @spelling_list); | ||
| 461 | 465 | ||
| 462 | sub build_types { | 466 | sub build_types { |
| 463 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; | 467 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; |
| @@ -942,7 +946,7 @@ sub sanitise_line { | |||
| 942 | sub get_quoted_string { | 946 | sub get_quoted_string { |
| 943 | my ($line, $rawline) = @_; | 947 | my ($line, $rawline) = @_; |
| 944 | 948 | ||
| 945 | return "" if ($line !~ m/(\"[X]+\")/g); | 949 | return "" if ($line !~ m/(\"[X\t]+\")/g); |
| 946 | return substr($rawline, $-[0], $+[0] - $-[0]); | 950 | return substr($rawline, $-[0], $+[0] - $-[0]); |
| 947 | } | 951 | } |
| 948 | 952 | ||
| @@ -1843,6 +1847,7 @@ sub process { | |||
| 1843 | my $non_utf8_charset = 0; | 1847 | my $non_utf8_charset = 0; |
| 1844 | 1848 | ||
| 1845 | my $last_blank_line = 0; | 1849 | my $last_blank_line = 0; |
| 1850 | my $last_coalesced_string_linenr = -1; | ||
| 1846 | 1851 | ||
| 1847 | our @report = (); | 1852 | our @report = (); |
| 1848 | our $cnt_lines = 0; | 1853 | our $cnt_lines = 0; |
| @@ -2078,6 +2083,12 @@ sub process { | |||
| 2078 | $in_commit_log = 0; | 2083 | $in_commit_log = 0; |
| 2079 | } | 2084 | } |
| 2080 | 2085 | ||
| 2086 | # Check if MAINTAINERS is being updated. If so, there's probably no need to | ||
| 2087 | # emit the "does MAINTAINERS need updating?" message on file add/move/delete | ||
| 2088 | if ($line =~ /^\s*MAINTAINERS\s*\|/) { | ||
| 2089 | $reported_maintainer_file = 1; | ||
| 2090 | } | ||
| 2091 | |||
| 2081 | # Check signature styles | 2092 | # Check signature styles |
| 2082 | if (!$in_header_lines && | 2093 | if (!$in_header_lines && |
| 2083 | $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) { | 2094 | $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) { |
| @@ -2246,7 +2257,7 @@ sub process { | |||
| 2246 | } | 2257 | } |
| 2247 | 2258 | ||
| 2248 | # Check for various typo / spelling mistakes | 2259 | # Check for various typo / spelling mistakes |
| 2249 | if ($in_commit_log || $line =~ /^\+/) { | 2260 | if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) { |
| 2250 | while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { | 2261 | while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) { |
| 2251 | my $typo = $1; | 2262 | my $typo = $1; |
| 2252 | my $typo_fix = $spelling_fix{lc($typo)}; | 2263 | my $typo_fix = $spelling_fix{lc($typo)}; |
| @@ -2403,33 +2414,6 @@ sub process { | |||
| 2403 | "line over $max_line_length characters\n" . $herecurr); | 2414 | "line over $max_line_length characters\n" . $herecurr); |
| 2404 | } | 2415 | } |
| 2405 | 2416 | ||
| 2406 | # Check for user-visible strings broken across lines, which breaks the ability | ||
| 2407 | # to grep for the string. Make exceptions when the previous string ends in a | ||
| 2408 | # newline (multiple lines in one string constant) or '\t', '\r', ';', or '{' | ||
| 2409 | # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value | ||
| 2410 | if ($line =~ /^\+\s*"/ && | ||
| 2411 | $prevline =~ /"\s*$/ && | ||
| 2412 | $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) { | ||
| 2413 | WARN("SPLIT_STRING", | ||
| 2414 | "quoted string split across lines\n" . $hereprev); | ||
| 2415 | } | ||
| 2416 | |||
| 2417 | # check for missing a space in a string concatination | ||
| 2418 | if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) { | ||
| 2419 | WARN('MISSING_SPACE', | ||
| 2420 | "break quoted strings at a space character\n" . $hereprev); | ||
| 2421 | } | ||
| 2422 | |||
| 2423 | # check for spaces before a quoted newline | ||
| 2424 | if ($rawline =~ /^.*\".*\s\\n/) { | ||
| 2425 | if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", | ||
| 2426 | "unnecessary whitespace before a quoted newline\n" . $herecurr) && | ||
| 2427 | $fix) { | ||
| 2428 | $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/; | ||
| 2429 | } | ||
| 2430 | |||
| 2431 | } | ||
| 2432 | |||
| 2433 | # check for adding lines without a newline. | 2417 | # check for adding lines without a newline. |
| 2434 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { | 2418 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { |
| 2435 | WARN("MISSING_EOF_NEWLINE", | 2419 | WARN("MISSING_EOF_NEWLINE", |
| @@ -2515,7 +2499,8 @@ sub process { | |||
| 2515 | } | 2499 | } |
| 2516 | } | 2500 | } |
| 2517 | 2501 | ||
| 2518 | if ($line =~ /^\+.*\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|{)/) { | 2502 | if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;\({\[\<\>])/ && |
| 2503 | (!defined($1) || $1 !~ /sizeof\s*/)) { | ||
| 2519 | if (CHK("SPACING", | 2504 | if (CHK("SPACING", |
| 2520 | "No space is necessary after a cast\n" . $herecurr) && | 2505 | "No space is necessary after a cast\n" . $herecurr) && |
| 2521 | $fix) { | 2506 | $fix) { |
| @@ -3563,14 +3548,33 @@ sub process { | |||
| 3563 | } | 3548 | } |
| 3564 | } | 3549 | } |
| 3565 | 3550 | ||
| 3566 | # , must have a space on the right. | 3551 | # , must not have a space before and must have a space on the right. |
| 3567 | } elsif ($op eq ',') { | 3552 | } elsif ($op eq ',') { |
| 3553 | my $rtrim_before = 0; | ||
| 3554 | my $space_after = 0; | ||
| 3555 | if ($ctx =~ /Wx./) { | ||
| 3556 | if (ERROR("SPACING", | ||
| 3557 | "space prohibited before that '$op' $at\n" . $hereptr)) { | ||
| 3558 | $line_fixed = 1; | ||
| 3559 | $rtrim_before = 1; | ||
| 3560 | } | ||
| 3561 | } | ||
| 3568 | if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { | 3562 | if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { |
| 3569 | if (ERROR("SPACING", | 3563 | if (ERROR("SPACING", |
| 3570 | "space required after that '$op' $at\n" . $hereptr)) { | 3564 | "space required after that '$op' $at\n" . $hereptr)) { |
| 3571 | $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " "; | ||
| 3572 | $line_fixed = 1; | 3565 | $line_fixed = 1; |
| 3573 | $last_after = $n; | 3566 | $last_after = $n; |
| 3567 | $space_after = 1; | ||
| 3568 | } | ||
| 3569 | } | ||
| 3570 | if ($rtrim_before || $space_after) { | ||
| 3571 | if ($rtrim_before) { | ||
| 3572 | $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); | ||
| 3573 | } else { | ||
| 3574 | $good = $fix_elements[$n] . trim($fix_elements[$n + 1]); | ||
| 3575 | } | ||
| 3576 | if ($space_after) { | ||
| 3577 | $good .= " "; | ||
| 3574 | } | 3578 | } |
| 3575 | } | 3579 | } |
| 3576 | 3580 | ||
| @@ -3814,9 +3818,27 @@ sub process { | |||
| 3814 | # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar | 3818 | # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar |
| 3815 | 3819 | ||
| 3816 | while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) { | 3820 | while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) { |
| 3817 | CHK("UNNECESSARY_PARENTHESES", | 3821 | my $var = $1; |
| 3818 | "Unnecessary parentheses around $1\n" . $herecurr); | 3822 | if (CHK("UNNECESSARY_PARENTHESES", |
| 3819 | } | 3823 | "Unnecessary parentheses around $var\n" . $herecurr) && |
| 3824 | $fix) { | ||
| 3825 | $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/; | ||
| 3826 | } | ||
| 3827 | } | ||
| 3828 | |||
| 3829 | # check for unnecessary parentheses around function pointer uses | ||
| 3830 | # ie: (foo->bar)(); should be foo->bar(); | ||
| 3831 | # but not "if (foo->bar) (" to avoid some false positives | ||
| 3832 | if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) { | ||
| 3833 | my $var = $2; | ||
| 3834 | if (CHK("UNNECESSARY_PARENTHESES", | ||
| 3835 | "Unnecessary parentheses around function pointer $var\n" . $herecurr) && | ||
| 3836 | $fix) { | ||
| 3837 | my $var2 = deparenthesize($var); | ||
| 3838 | $var2 =~ s/\s//g; | ||
| 3839 | $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/; | ||
| 3840 | } | ||
| 3841 | } | ||
| 3820 | 3842 | ||
| 3821 | #goto labels aren't indented, allow a single space however | 3843 | #goto labels aren't indented, allow a single space however |
| 3822 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and | 3844 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
| @@ -4056,7 +4078,9 @@ sub process { | |||
| 4056 | #Ignore Page<foo> variants | 4078 | #Ignore Page<foo> variants |
| 4057 | $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && | 4079 | $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && |
| 4058 | #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) | 4080 | #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) |
| 4059 | $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) { | 4081 | $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ && |
| 4082 | #Ignore some three character SI units explicitly, like MiB and KHz | ||
| 4083 | $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) { | ||
| 4060 | while ($var =~ m{($Ident)}g) { | 4084 | while ($var =~ m{($Ident)}g) { |
| 4061 | my $word = $1; | 4085 | my $word = $1; |
| 4062 | next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/); | 4086 | next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/); |
| @@ -4408,12 +4432,85 @@ sub process { | |||
| 4408 | "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); | 4432 | "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); |
| 4409 | } | 4433 | } |
| 4410 | 4434 | ||
| 4435 | # Check for user-visible strings broken across lines, which breaks the ability | ||
| 4436 | # to grep for the string. Make exceptions when the previous string ends in a | ||
| 4437 | # newline (multiple lines in one string constant) or '\t', '\r', ';', or '{' | ||
| 4438 | # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value | ||
| 4439 | if ($line =~ /^\+\s*"[X\t]*"/ && | ||
| 4440 | $prevline =~ /"\s*$/ && | ||
| 4441 | $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) { | ||
| 4442 | if (WARN("SPLIT_STRING", | ||
| 4443 | "quoted string split across lines\n" . $hereprev) && | ||
| 4444 | $fix && | ||
| 4445 | $prevrawline =~ /^\+.*"\s*$/ && | ||
| 4446 | $last_coalesced_string_linenr != $linenr - 1) { | ||
| 4447 | my $extracted_string = get_quoted_string($line, $rawline); | ||
| 4448 | my $comma_close = ""; | ||
| 4449 | if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) { | ||
| 4450 | $comma_close = $1; | ||
| 4451 | } | ||
| 4452 | |||
| 4453 | fix_delete_line($fixlinenr - 1, $prevrawline); | ||
| 4454 | fix_delete_line($fixlinenr, $rawline); | ||
| 4455 | my $fixedline = $prevrawline; | ||
| 4456 | $fixedline =~ s/"\s*$//; | ||
| 4457 | $fixedline .= substr($extracted_string, 1) . trim($comma_close); | ||
| 4458 | fix_insert_line($fixlinenr - 1, $fixedline); | ||
| 4459 | $fixedline = $rawline; | ||
| 4460 | $fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//; | ||
| 4461 | if ($fixedline !~ /\+\s*$/) { | ||
| 4462 | fix_insert_line($fixlinenr, $fixedline); | ||
| 4463 | } | ||
| 4464 | $last_coalesced_string_linenr = $linenr; | ||
| 4465 | } | ||
| 4466 | } | ||
| 4467 | |||
| 4468 | # check for missing a space in a string concatenation | ||
| 4469 | if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) { | ||
| 4470 | WARN('MISSING_SPACE', | ||
| 4471 | "break quoted strings at a space character\n" . $hereprev); | ||
| 4472 | } | ||
| 4473 | |||
| 4474 | # check for spaces before a quoted newline | ||
| 4475 | if ($rawline =~ /^.*\".*\s\\n/) { | ||
| 4476 | if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", | ||
| 4477 | "unnecessary whitespace before a quoted newline\n" . $herecurr) && | ||
| 4478 | $fix) { | ||
| 4479 | $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/; | ||
| 4480 | } | ||
| 4481 | |||
| 4482 | } | ||
| 4483 | |||
| 4411 | # concatenated string without spaces between elements | 4484 | # concatenated string without spaces between elements |
| 4412 | if ($line =~ /"X+"[A-Z_]+/ || $line =~ /[A-Z_]+"X+"/) { | 4485 | if ($line =~ /"X+"[A-Z_]+/ || $line =~ /[A-Z_]+"X+"/) { |
| 4413 | CHK("CONCATENATED_STRING", | 4486 | CHK("CONCATENATED_STRING", |
| 4414 | "Concatenated strings should use spaces between elements\n" . $herecurr); | 4487 | "Concatenated strings should use spaces between elements\n" . $herecurr); |
| 4415 | } | 4488 | } |
| 4416 | 4489 | ||
| 4490 | # uncoalesced string fragments | ||
| 4491 | if ($line =~ /"X*"\s*"/) { | ||
| 4492 | WARN("STRING_FRAGMENTS", | ||
| 4493 | "Consecutive strings are generally better as a single string\n" . $herecurr); | ||
| 4494 | } | ||
| 4495 | |||
| 4496 | # check for %L{u,d,i} in strings | ||
| 4497 | my $string; | ||
| 4498 | while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) { | ||
| 4499 | $string = substr($rawline, $-[1], $+[1] - $-[1]); | ||
| 4500 | $string =~ s/%%/__/g; | ||
| 4501 | if ($string =~ /(?<!%)%L[udi]/) { | ||
| 4502 | WARN("PRINTF_L", | ||
| 4503 | "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr); | ||
| 4504 | last; | ||
| 4505 | } | ||
| 4506 | } | ||
| 4507 | |||
| 4508 | # check for line continuations in quoted strings with odd counts of " | ||
| 4509 | if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { | ||
| 4510 | WARN("LINE_CONTINUATIONS", | ||
| 4511 | "Avoid line continuations in quoted strings\n" . $herecurr); | ||
| 4512 | } | ||
| 4513 | |||
| 4417 | # warn about #if 0 | 4514 | # warn about #if 0 |
| 4418 | if ($line =~ /^.\s*\#\s*if\s+0\b/) { | 4515 | if ($line =~ /^.\s*\#\s*if\s+0\b/) { |
| 4419 | CHK("REDUNDANT_CODE", | 4516 | CHK("REDUNDANT_CODE", |
| @@ -4426,7 +4523,7 @@ sub process { | |||
| 4426 | my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;'; | 4523 | my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;'; |
| 4427 | if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?)$expr/) { | 4524 | if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?)$expr/) { |
| 4428 | WARN('NEEDLESS_IF', | 4525 | WARN('NEEDLESS_IF', |
| 4429 | "$1(NULL) is safe this check is probably not required\n" . $hereprev); | 4526 | "$1(NULL) is safe and this check is probably not required\n" . $hereprev); |
| 4430 | } | 4527 | } |
| 4431 | } | 4528 | } |
| 4432 | 4529 | ||
| @@ -4458,6 +4555,28 @@ sub process { | |||
| 4458 | } | 4555 | } |
| 4459 | } | 4556 | } |
| 4460 | 4557 | ||
| 4558 | # check for mask then right shift without a parentheses | ||
| 4559 | if ($^V && $^V ge 5.10.0 && | ||
| 4560 | $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ && | ||
| 4561 | $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so | ||
| 4562 | WARN("MASK_THEN_SHIFT", | ||
| 4563 | "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr); | ||
| 4564 | } | ||
| 4565 | |||
| 4566 | # check for pointer comparisons to NULL | ||
| 4567 | if ($^V && $^V ge 5.10.0) { | ||
| 4568 | while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) { | ||
| 4569 | my $val = $1; | ||
| 4570 | my $equal = "!"; | ||
| 4571 | $equal = "" if ($4 eq "!="); | ||
| 4572 | if (CHK("COMPARISON_TO_NULL", | ||
| 4573 | "Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) && | ||
| 4574 | $fix) { | ||
| 4575 | $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/; | ||
| 4576 | } | ||
| 4577 | } | ||
| 4578 | } | ||
| 4579 | |||
| 4461 | # check for bad placement of section $InitAttribute (e.g.: __initdata) | 4580 | # check for bad placement of section $InitAttribute (e.g.: __initdata) |
| 4462 | if ($line =~ /(\b$InitAttribute\b)/) { | 4581 | if ($line =~ /(\b$InitAttribute\b)/) { |
| 4463 | my $attr = $1; | 4582 | my $attr = $1; |
| @@ -4652,6 +4771,15 @@ sub process { | |||
| 4652 | } | 4771 | } |
| 4653 | } | 4772 | } |
| 4654 | 4773 | ||
| 4774 | # Check for __attribute__ weak, or __weak declarations (may have link issues) | ||
| 4775 | if ($^V && $^V ge 5.10.0 && | ||
| 4776 | $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && | ||
| 4777 | ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || | ||
| 4778 | $line =~ /\b__weak\b/)) { | ||
| 4779 | ERROR("WEAK_DECLARATION", | ||
| 4780 | "Using weak declarations can have unintended link defects\n" . $herecurr); | ||
| 4781 | } | ||
| 4782 | |||
| 4655 | # check for sizeof(&) | 4783 | # check for sizeof(&) |
| 4656 | if ($line =~ /\bsizeof\s*\(\s*\&/) { | 4784 | if ($line =~ /\bsizeof\s*\(\s*\&/) { |
| 4657 | WARN("SIZEOF_ADDRESS", | 4785 | WARN("SIZEOF_ADDRESS", |
| @@ -4667,12 +4795,6 @@ sub process { | |||
| 4667 | } | 4795 | } |
| 4668 | } | 4796 | } |
| 4669 | 4797 | ||
| 4670 | # check for line continuations in quoted strings with odd counts of " | ||
| 4671 | if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { | ||
| 4672 | WARN("LINE_CONTINUATIONS", | ||
| 4673 | "Avoid line continuations in quoted strings\n" . $herecurr); | ||
| 4674 | } | ||
| 4675 | |||
| 4676 | # check for struct spinlock declarations | 4798 | # check for struct spinlock declarations |
| 4677 | if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) { | 4799 | if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) { |
| 4678 | WARN("USE_SPINLOCK_T", | 4800 | WARN("USE_SPINLOCK_T", |
| @@ -4908,6 +5030,17 @@ sub process { | |||
| 4908 | } | 5030 | } |
| 4909 | } | 5031 | } |
| 4910 | 5032 | ||
| 5033 | # check for #defines like: 1 << <digit> that could be BIT(digit) | ||
| 5034 | if ($line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) { | ||
| 5035 | my $ull = ""; | ||
| 5036 | $ull = "_ULL" if (defined($1) && $1 =~ /ll/i); | ||
| 5037 | if (CHK("BIT_MACRO", | ||
| 5038 | "Prefer using the BIT$ull macro\n" . $herecurr) && | ||
| 5039 | $fix) { | ||
| 5040 | $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/; | ||
| 5041 | } | ||
| 5042 | } | ||
| 5043 | |||
| 4911 | # check for case / default statements not preceded by break/fallthrough/switch | 5044 | # check for case / default statements not preceded by break/fallthrough/switch |
| 4912 | if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { | 5045 | if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { |
| 4913 | my $has_break = 0; | 5046 | my $has_break = 0; |
| @@ -5071,18 +5204,6 @@ sub process { | |||
| 5071 | "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr); | 5204 | "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr); |
| 5072 | } | 5205 | } |
| 5073 | 5206 | ||
| 5074 | # check for %L{u,d,i} in strings | ||
| 5075 | my $string; | ||
| 5076 | while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) { | ||
| 5077 | $string = substr($rawline, $-[1], $+[1] - $-[1]); | ||
| 5078 | $string =~ s/%%/__/g; | ||
| 5079 | if ($string =~ /(?<!%)%L[udi]/) { | ||
| 5080 | WARN("PRINTF_L", | ||
| 5081 | "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr); | ||
| 5082 | last; | ||
| 5083 | } | ||
| 5084 | } | ||
| 5085 | |||
| 5086 | # whine mightly about in_atomic | 5207 | # whine mightly about in_atomic |
| 5087 | if ($line =~ /\bin_atomic\s*\(/) { | 5208 | if ($line =~ /\bin_atomic\s*\(/) { |
| 5088 | if ($realfile =~ m@^drivers/@) { | 5209 | if ($realfile =~ m@^drivers/@) { |
