diff options
| author | Ingo Molnar <mingo@kernel.org> | 2014-04-14 10:44:42 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2014-04-14 10:44:42 -0400 |
| commit | 740c699a8d316c8bf8593f19e2ca47795e690622 (patch) | |
| tree | a78886955770a477945c5d84e06b2e7678733b54 /scripts/checkpatch.pl | |
| parent | e69af4657e7764d03ad555f0b583d9c4217bcefa (diff) | |
| parent | c9eaa447e77efe77b7fa4c953bd62de8297fd6c5 (diff) | |
Merge tag 'v3.15-rc1' into perf/urgent
Pick up the latest fixes.
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 235 |
1 files changed, 179 insertions, 56 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 464dcef79b35..34eb2160489d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -281,7 +281,7 @@ our $Attribute = qr{ | |||
| 281 | __weak | 281 | __weak |
| 282 | }x; | 282 | }x; |
| 283 | our $Modifier; | 283 | our $Modifier; |
| 284 | our $Inline = qr{inline|__always_inline|noinline}; | 284 | our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__}; |
| 285 | our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; | 285 | our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; |
| 286 | our $Lval = qr{$Ident(?:$Member)*}; | 286 | our $Lval = qr{$Ident(?:$Member)*}; |
| 287 | 287 | ||
| @@ -289,13 +289,14 @@ our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u}; | |||
| 289 | our $Binary = qr{(?i)0b[01]+$Int_type?}; | 289 | our $Binary = qr{(?i)0b[01]+$Int_type?}; |
| 290 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; | 290 | our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; |
| 291 | our $Int = qr{[0-9]+$Int_type?}; | 291 | our $Int = qr{[0-9]+$Int_type?}; |
| 292 | our $Octal = qr{0[0-7]+$Int_type?}; | ||
| 292 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; | 293 | our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; |
| 293 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; | 294 | our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; |
| 294 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; | 295 | our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; |
| 295 | our $Float = qr{$Float_hex|$Float_dec|$Float_int}; | 296 | our $Float = qr{$Float_hex|$Float_dec|$Float_int}; |
| 296 | our $Constant = qr{$Float|$Binary|$Hex|$Int}; | 297 | our $Constant = qr{$Float|$Binary|$Octal|$Hex|$Int}; |
| 297 | our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; | 298 | our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; |
| 298 | our $Compare = qr{<=|>=|==|!=|<|>}; | 299 | our $Compare = qr{<=|>=|==|!=|<|(?<!-)>}; |
| 299 | our $Arithmetic = qr{\+|-|\*|\/|%}; | 300 | our $Arithmetic = qr{\+|-|\*|\/|%}; |
| 300 | our $Operators = qr{ | 301 | our $Operators = qr{ |
| 301 | <=|>=|==|!=| | 302 | <=|>=|==|!=| |
| @@ -303,6 +304,8 @@ our $Operators = qr{ | |||
| 303 | &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic | 304 | &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic |
| 304 | }x; | 305 | }x; |
| 305 | 306 | ||
| 307 | our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; | ||
| 308 | |||
| 306 | our $NonptrType; | 309 | our $NonptrType; |
| 307 | our $NonptrTypeWithAttr; | 310 | our $NonptrTypeWithAttr; |
| 308 | our $Type; | 311 | our $Type; |
| @@ -378,6 +381,22 @@ our @modifierList = ( | |||
| 378 | qr{fastcall}, | 381 | qr{fastcall}, |
| 379 | ); | 382 | ); |
| 380 | 383 | ||
| 384 | our @mode_permission_funcs = ( | ||
| 385 | ["module_param", 3], | ||
| 386 | ["module_param_(?:array|named|string)", 4], | ||
| 387 | ["module_param_array_named", 5], | ||
| 388 | ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2], | ||
| 389 | ["proc_create(?:_data|)", 2], | ||
| 390 | ["(?:CLASS|DEVICE|SENSOR)_ATTR", 2], | ||
| 391 | ); | ||
| 392 | |||
| 393 | #Create a search pattern for all these functions to speed up a loop below | ||
| 394 | our $mode_perms_search = ""; | ||
| 395 | foreach my $entry (@mode_permission_funcs) { | ||
| 396 | $mode_perms_search .= '|' if ($mode_perms_search ne ""); | ||
| 397 | $mode_perms_search .= $entry->[0]; | ||
| 398 | } | ||
| 399 | |||
| 381 | our $allowed_asm_includes = qr{(?x: | 400 | our $allowed_asm_includes = qr{(?x: |
| 382 | irq| | 401 | irq| |
| 383 | memory | 402 | memory |
| @@ -412,7 +431,7 @@ sub build_types { | |||
| 412 | (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)? | 431 | (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)? |
| 413 | (?:\s+$Inline|\s+$Modifier)* | 432 | (?:\s+$Inline|\s+$Modifier)* |
| 414 | }x; | 433 | }x; |
| 415 | $Declare = qr{(?:$Storage\s+)?$Type}; | 434 | $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type}; |
| 416 | } | 435 | } |
| 417 | build_types(); | 436 | build_types(); |
| 418 | 437 | ||
| @@ -423,15 +442,20 @@ our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; | |||
| 423 | # Any use must be runtime checked with $^V | 442 | # Any use must be runtime checked with $^V |
| 424 | 443 | ||
| 425 | our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; | 444 | our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; |
| 426 | our $LvalOrFunc = qr{($Lval)\s*($balanced_parens{0,1})\s*}; | 445 | our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*}; |
| 427 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; | 446 | our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)}; |
| 428 | 447 | ||
| 429 | sub deparenthesize { | 448 | sub deparenthesize { |
| 430 | my ($string) = @_; | 449 | my ($string) = @_; |
| 431 | return "" if (!defined($string)); | 450 | return "" if (!defined($string)); |
| 432 | $string =~ s@^\s*\(\s*@@g; | 451 | |
| 433 | $string =~ s@\s*\)\s*$@@g; | 452 | while ($string =~ /^\s*\(.*\)\s*$/) { |
| 453 | $string =~ s@^\s*\(\s*@@; | ||
| 454 | $string =~ s@\s*\)\s*$@@; | ||
| 455 | } | ||
| 456 | |||
| 434 | $string =~ s@\s+@ @g; | 457 | $string =~ s@\s+@ @g; |
| 458 | |||
| 435 | return $string; | 459 | return $string; |
| 436 | } | 460 | } |
| 437 | 461 | ||
| @@ -1421,21 +1445,25 @@ sub possible { | |||
| 1421 | my $prefix = ''; | 1445 | my $prefix = ''; |
| 1422 | 1446 | ||
| 1423 | sub show_type { | 1447 | sub show_type { |
| 1424 | return defined $use_type{$_[0]} if (scalar keys %use_type > 0); | 1448 | my ($type) = @_; |
| 1449 | |||
| 1450 | return defined $use_type{$type} if (scalar keys %use_type > 0); | ||
| 1425 | 1451 | ||
| 1426 | return !defined $ignore_type{$_[0]}; | 1452 | return !defined $ignore_type{$type}; |
| 1427 | } | 1453 | } |
| 1428 | 1454 | ||
| 1429 | sub report { | 1455 | sub report { |
| 1430 | if (!show_type($_[1]) || | 1456 | my ($level, $type, $msg) = @_; |
| 1431 | (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) { | 1457 | |
| 1458 | if (!show_type($type) || | ||
| 1459 | (defined $tst_only && $msg !~ /\Q$tst_only\E/)) { | ||
| 1432 | return 0; | 1460 | return 0; |
| 1433 | } | 1461 | } |
| 1434 | my $line; | 1462 | my $line; |
| 1435 | if ($show_types) { | 1463 | if ($show_types) { |
| 1436 | $line = "$prefix$_[0]:$_[1]: $_[2]\n"; | 1464 | $line = "$prefix$level:$type: $msg\n"; |
| 1437 | } else { | 1465 | } else { |
| 1438 | $line = "$prefix$_[0]: $_[2]\n"; | 1466 | $line = "$prefix$level: $msg\n"; |
| 1439 | } | 1467 | } |
| 1440 | $line = (split('\n', $line))[0] . "\n" if ($terse); | 1468 | $line = (split('\n', $line))[0] . "\n" if ($terse); |
| 1441 | 1469 | ||
| @@ -1443,12 +1471,15 @@ sub report { | |||
| 1443 | 1471 | ||
| 1444 | return 1; | 1472 | return 1; |
| 1445 | } | 1473 | } |
| 1474 | |||
| 1446 | sub report_dump { | 1475 | sub report_dump { |
| 1447 | our @report; | 1476 | our @report; |
| 1448 | } | 1477 | } |
| 1449 | 1478 | ||
| 1450 | sub ERROR { | 1479 | sub ERROR { |
| 1451 | if (report("ERROR", $_[0], $_[1])) { | 1480 | my ($type, $msg) = @_; |
| 1481 | |||
| 1482 | if (report("ERROR", $type, $msg)) { | ||
| 1452 | our $clean = 0; | 1483 | our $clean = 0; |
| 1453 | our $cnt_error++; | 1484 | our $cnt_error++; |
| 1454 | return 1; | 1485 | return 1; |
| @@ -1456,7 +1487,9 @@ sub ERROR { | |||
| 1456 | return 0; | 1487 | return 0; |
| 1457 | } | 1488 | } |
| 1458 | sub WARN { | 1489 | sub WARN { |
| 1459 | if (report("WARNING", $_[0], $_[1])) { | 1490 | my ($type, $msg) = @_; |
| 1491 | |||
| 1492 | if (report("WARNING", $type, $msg)) { | ||
| 1460 | our $clean = 0; | 1493 | our $clean = 0; |
| 1461 | our $cnt_warn++; | 1494 | our $cnt_warn++; |
| 1462 | return 1; | 1495 | return 1; |
| @@ -1464,7 +1497,9 @@ sub WARN { | |||
| 1464 | return 0; | 1497 | return 0; |
| 1465 | } | 1498 | } |
| 1466 | sub CHK { | 1499 | sub CHK { |
| 1467 | if ($check && report("CHECK", $_[0], $_[1])) { | 1500 | my ($type, $msg) = @_; |
| 1501 | |||
| 1502 | if ($check && report("CHECK", $type, $msg)) { | ||
| 1468 | our $clean = 0; | 1503 | our $clean = 0; |
| 1469 | our $cnt_chk++; | 1504 | our $cnt_chk++; |
| 1470 | return 1; | 1505 | return 1; |
| @@ -1574,7 +1609,7 @@ sub pos_last_openparen { | |||
| 1574 | } | 1609 | } |
| 1575 | } | 1610 | } |
| 1576 | 1611 | ||
| 1577 | return $last_openparen + 1; | 1612 | return length(expand_tabs(substr($line, 0, $last_openparen))) + 1; |
| 1578 | } | 1613 | } |
| 1579 | 1614 | ||
| 1580 | sub process { | 1615 | sub process { |
| @@ -1891,6 +1926,12 @@ sub process { | |||
| 1891 | } | 1926 | } |
| 1892 | } | 1927 | } |
| 1893 | 1928 | ||
| 1929 | # Check for unwanted Gerrit info | ||
| 1930 | if ($in_commit_log && $line =~ /^\s*change-id:/i) { | ||
| 1931 | ERROR("GERRIT_CHANGE_ID", | ||
| 1932 | "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); | ||
| 1933 | } | ||
| 1934 | |||
| 1894 | # Check for wrappage within a valid hunk of the file | 1935 | # Check for wrappage within a valid hunk of the file |
| 1895 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { | 1936 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { |
| 1896 | ERROR("CORRUPTED_PATCH", | 1937 | ERROR("CORRUPTED_PATCH", |
| @@ -2041,13 +2082,17 @@ sub process { | |||
| 2041 | } | 2082 | } |
| 2042 | 2083 | ||
| 2043 | # check for DT compatible documentation | 2084 | # check for DT compatible documentation |
| 2044 | if (defined $root && $realfile =~ /\.dts/ && | 2085 | if (defined $root && |
| 2045 | $rawline =~ /^\+\s*compatible\s*=/) { | 2086 | (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) || |
| 2087 | ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) { | ||
| 2088 | |||
| 2046 | my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g; | 2089 | my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g; |
| 2047 | 2090 | ||
| 2091 | my $dt_path = $root . "/Documentation/devicetree/bindings/"; | ||
| 2092 | my $vp_file = $dt_path . "vendor-prefixes.txt"; | ||
| 2093 | |||
| 2048 | foreach my $compat (@compats) { | 2094 | foreach my $compat (@compats) { |
| 2049 | my $compat2 = $compat; | 2095 | my $compat2 = $compat; |
| 2050 | my $dt_path = $root . "/Documentation/devicetree/bindings/"; | ||
| 2051 | $compat2 =~ s/\,[a-z]*\-/\,<\.\*>\-/; | 2096 | $compat2 =~ s/\,[a-z]*\-/\,<\.\*>\-/; |
| 2052 | `grep -Erq "$compat|$compat2" $dt_path`; | 2097 | `grep -Erq "$compat|$compat2" $dt_path`; |
| 2053 | if ( $? >> 8 ) { | 2098 | if ( $? >> 8 ) { |
| @@ -2055,14 +2100,12 @@ sub process { | |||
| 2055 | "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr); | 2100 | "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr); |
| 2056 | } | 2101 | } |
| 2057 | 2102 | ||
| 2058 | my $vendor = $compat; | 2103 | next if $compat !~ /^([a-zA-Z0-9\-]+)\,/; |
| 2059 | my $vendor_path = $dt_path . "vendor-prefixes.txt"; | 2104 | my $vendor = $1; |
| 2060 | next if (! -f $vendor_path); | 2105 | `grep -Eq "^$vendor\\b" $vp_file`; |
| 2061 | $vendor =~ s/^([a-zA-Z0-9]+)\,.*/$1/; | ||
| 2062 | `grep -Eq "$vendor" $vendor_path`; | ||
| 2063 | if ( $? >> 8 ) { | 2106 | if ( $? >> 8 ) { |
| 2064 | WARN("UNDOCUMENTED_DT_STRING", | 2107 | WARN("UNDOCUMENTED_DT_STRING", |
| 2065 | "DT compatible string vendor \"$vendor\" appears un-documented -- check $vendor_path\n" . $herecurr); | 2108 | "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr); |
| 2066 | } | 2109 | } |
| 2067 | } | 2110 | } |
| 2068 | } | 2111 | } |
| @@ -2159,7 +2202,7 @@ sub process { | |||
| 2159 | 2202 | ||
| 2160 | # check multi-line statement indentation matches previous line | 2203 | # check multi-line statement indentation matches previous line |
| 2161 | if ($^V && $^V ge 5.10.0 && | 2204 | if ($^V && $^V ge 5.10.0 && |
| 2162 | $prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/) { | 2205 | $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|$Ident\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) { |
| 2163 | $prevline =~ /^\+(\t*)(.*)$/; | 2206 | $prevline =~ /^\+(\t*)(.*)$/; |
| 2164 | my $oldindent = $1; | 2207 | my $oldindent = $1; |
| 2165 | my $rest = $2; | 2208 | my $rest = $2; |
| @@ -2198,7 +2241,8 @@ sub process { | |||
| 2198 | 2241 | ||
| 2199 | if ($realfile =~ m@^(drivers/net/|net/)@ && | 2242 | if ($realfile =~ m@^(drivers/net/|net/)@ && |
| 2200 | $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ && | 2243 | $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ && |
| 2201 | $rawline =~ /^\+[ \t]*\*/) { | 2244 | $rawline =~ /^\+[ \t]*\*/ && |
| 2245 | $realline > 2) { | ||
| 2202 | WARN("NETWORKING_BLOCK_COMMENT_STYLE", | 2246 | WARN("NETWORKING_BLOCK_COMMENT_STYLE", |
| 2203 | "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); | 2247 | "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); |
| 2204 | } | 2248 | } |
| @@ -2221,6 +2265,21 @@ sub process { | |||
| 2221 | "networking block comments put the trailing */ on a separate line\n" . $herecurr); | 2265 | "networking block comments put the trailing */ on a separate line\n" . $herecurr); |
| 2222 | } | 2266 | } |
| 2223 | 2267 | ||
| 2268 | # check for missing blank lines after declarations | ||
| 2269 | if ($realfile =~ m@^(drivers/net/|net/)@ && | ||
| 2270 | $prevline =~ /^\+\s+$Declare\s+$Ident/ && | ||
| 2271 | !($prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || | ||
| 2272 | $prevline =~ /(?:\{\s*|\\)$/) && #extended lines | ||
| 2273 | $sline =~ /^\+\s+/ && #Not at char 1 | ||
| 2274 | !($sline =~ /^\+\s+$Declare/ || | ||
| 2275 | $sline =~ /^\+\s+$Ident\s+$Ident/ || #eg: typedef foo | ||
| 2276 | $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ || | ||
| 2277 | $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(])/ || | ||
| 2278 | $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) { | ||
| 2279 | WARN("SPACING", | ||
| 2280 | "networking uses a blank line after declarations\n" . $hereprev); | ||
| 2281 | } | ||
| 2282 | |||
| 2224 | # check for spaces at the beginning of a line. | 2283 | # check for spaces at the beginning of a line. |
| 2225 | # Exceptions: | 2284 | # Exceptions: |
| 2226 | # 1) within comments | 2285 | # 1) within comments |
| @@ -2665,6 +2724,13 @@ sub process { | |||
| 2665 | $herecurr); | 2724 | $herecurr); |
| 2666 | } | 2725 | } |
| 2667 | 2726 | ||
| 2727 | # check for non-global char *foo[] = {"bar", ...} declarations. | ||
| 2728 | if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { | ||
| 2729 | WARN("STATIC_CONST_CHAR_ARRAY", | ||
| 2730 | "char * array declaration might be better as static const\n" . | ||
| 2731 | $herecurr); | ||
| 2732 | } | ||
| 2733 | |||
| 2668 | # check for function declarations without arguments like "int foo()" | 2734 | # check for function declarations without arguments like "int foo()" |
| 2669 | if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { | 2735 | if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { |
| 2670 | if (ERROR("FUNCTION_WITHOUT_ARGS", | 2736 | if (ERROR("FUNCTION_WITHOUT_ARGS", |
| @@ -2799,7 +2865,7 @@ sub process { | |||
| 2799 | my $level2 = $level; | 2865 | my $level2 = $level; |
| 2800 | $level2 = "dbg" if ($level eq "debug"); | 2866 | $level2 = "dbg" if ($level eq "debug"); |
| 2801 | WARN("PREFER_PR_LEVEL", | 2867 | WARN("PREFER_PR_LEVEL", |
| 2802 | "Prefer netdev_$level2(netdev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr); | 2868 | "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr); |
| 2803 | } | 2869 | } |
| 2804 | 2870 | ||
| 2805 | if ($line =~ /\bpr_warning\s*\(/) { | 2871 | if ($line =~ /\bpr_warning\s*\(/) { |
| @@ -2848,10 +2914,7 @@ sub process { | |||
| 2848 | # Function pointer declarations | 2914 | # Function pointer declarations |
| 2849 | # check spacing between type, funcptr, and args | 2915 | # check spacing between type, funcptr, and args |
| 2850 | # canonical declaration is "type (*funcptr)(args...)" | 2916 | # canonical declaration is "type (*funcptr)(args...)" |
| 2851 | # | 2917 | if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) { |
| 2852 | # the $Declare variable will capture all spaces after the type | ||
| 2853 | # so check it for trailing missing spaces or multiple spaces | ||
| 2854 | if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)$Ident(\s*)\)(\s*)\(/) { | ||
| 2855 | my $declare = $1; | 2918 | my $declare = $1; |
| 2856 | my $pre_pointer_space = $2; | 2919 | my $pre_pointer_space = $2; |
| 2857 | my $post_pointer_space = $3; | 2920 | my $post_pointer_space = $3; |
| @@ -2859,16 +2922,30 @@ sub process { | |||
| 2859 | my $post_funcname_space = $5; | 2922 | my $post_funcname_space = $5; |
| 2860 | my $pre_args_space = $6; | 2923 | my $pre_args_space = $6; |
| 2861 | 2924 | ||
| 2862 | if ($declare !~ /\s$/) { | 2925 | # the $Declare variable will capture all spaces after the type |
| 2926 | # so check it for a missing trailing missing space but pointer return types | ||
| 2927 | # don't need a space so don't warn for those. | ||
| 2928 | my $post_declare_space = ""; | ||
| 2929 | if ($declare =~ /(\s+)$/) { | ||
| 2930 | $post_declare_space = $1; | ||
| 2931 | $declare = rtrim($declare); | ||
| 2932 | } | ||
| 2933 | if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) { | ||
| 2863 | WARN("SPACING", | 2934 | WARN("SPACING", |
| 2864 | "missing space after return type\n" . $herecurr); | 2935 | "missing space after return type\n" . $herecurr); |
| 2936 | $post_declare_space = " "; | ||
| 2865 | } | 2937 | } |
| 2866 | 2938 | ||
| 2867 | # unnecessary space "type (*funcptr)(args...)" | 2939 | # unnecessary space "type (*funcptr)(args...)" |
| 2868 | elsif ($declare =~ /\s{2,}$/) { | 2940 | # This test is not currently implemented because these declarations are |
| 2869 | WARN("SPACING", | 2941 | # equivalent to |
| 2870 | "Multiple spaces after return type\n" . $herecurr); | 2942 | # int foo(int bar, ...) |
| 2871 | } | 2943 | # and this is form shouldn't/doesn't generate a checkpatch warning. |
| 2944 | # | ||
| 2945 | # elsif ($declare =~ /\s{2,}$/) { | ||
| 2946 | # WARN("SPACING", | ||
| 2947 | # "Multiple spaces after return type\n" . $herecurr); | ||
| 2948 | # } | ||
| 2872 | 2949 | ||
| 2873 | # unnecessary space "type ( *funcptr)(args...)" | 2950 | # unnecessary space "type ( *funcptr)(args...)" |
| 2874 | if (defined $pre_pointer_space && | 2951 | if (defined $pre_pointer_space && |
| @@ -2900,7 +2977,7 @@ sub process { | |||
| 2900 | 2977 | ||
| 2901 | if (show_type("SPACING") && $fix) { | 2978 | if (show_type("SPACING") && $fix) { |
| 2902 | $fixed[$linenr - 1] =~ | 2979 | $fixed[$linenr - 1] =~ |
| 2903 | s/^(.\s*$Declare)\(\s*\*\s*($Ident)\s*\)\s*\(/rtrim($1) . " " . "\(\*$2\)\("/ex; | 2980 | s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex; |
| 2904 | } | 2981 | } |
| 2905 | } | 2982 | } |
| 2906 | 2983 | ||
| @@ -3061,10 +3138,13 @@ sub process { | |||
| 3061 | # // is a comment | 3138 | # // is a comment |
| 3062 | } elsif ($op eq '//') { | 3139 | } elsif ($op eq '//') { |
| 3063 | 3140 | ||
| 3141 | # : when part of a bitfield | ||
| 3142 | } elsif ($opv eq ':B') { | ||
| 3143 | # skip the bitfield test for now | ||
| 3144 | |||
| 3064 | # No spaces for: | 3145 | # No spaces for: |
| 3065 | # -> | 3146 | # -> |
| 3066 | # : when part of a bitfield | 3147 | } elsif ($op eq '->') { |
| 3067 | } elsif ($op eq '->' || $opv eq ':B') { | ||
| 3068 | if ($ctx =~ /Wx.|.xW/) { | 3148 | if ($ctx =~ /Wx.|.xW/) { |
| 3069 | if (ERROR("SPACING", | 3149 | if (ERROR("SPACING", |
| 3070 | "spaces prohibited around that '$op' $at\n" . $hereptr)) { | 3150 | "spaces prohibited around that '$op' $at\n" . $hereptr)) { |
| @@ -3334,14 +3414,17 @@ sub process { | |||
| 3334 | } | 3414 | } |
| 3335 | } | 3415 | } |
| 3336 | 3416 | ||
| 3337 | # Return is not a function. | 3417 | # return is not a function |
| 3338 | if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { | 3418 | if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { |
| 3339 | my $spacing = $1; | 3419 | my $spacing = $1; |
| 3340 | if ($^V && $^V ge 5.10.0 && | 3420 | if ($^V && $^V ge 5.10.0 && |
| 3341 | $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { | 3421 | $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { |
| 3342 | ERROR("RETURN_PARENTHESES", | 3422 | my $value = $1; |
| 3343 | "return is not a function, parentheses are not required\n" . $herecurr); | 3423 | $value = deparenthesize($value); |
| 3344 | 3424 | if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) { | |
| 3425 | ERROR("RETURN_PARENTHESES", | ||
| 3426 | "return is not a function, parentheses are not required\n" . $herecurr); | ||
| 3427 | } | ||
| 3345 | } elsif ($spacing !~ /\s+/) { | 3428 | } elsif ($spacing !~ /\s+/) { |
| 3346 | ERROR("SPACING", | 3429 | ERROR("SPACING", |
| 3347 | "space required before the open parenthesis '('\n" . $herecurr); | 3430 | "space required before the open parenthesis '('\n" . $herecurr); |
| @@ -3910,12 +3993,30 @@ sub process { | |||
| 3910 | } | 3993 | } |
| 3911 | } | 3994 | } |
| 3912 | 3995 | ||
| 3996 | # don't use __constant_<foo> functions outside of include/uapi/ | ||
| 3997 | if ($realfile !~ m@^include/uapi/@ && | ||
| 3998 | $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) { | ||
| 3999 | my $constant_func = $1; | ||
| 4000 | my $func = $constant_func; | ||
| 4001 | $func =~ s/^__constant_//; | ||
| 4002 | if (WARN("CONSTANT_CONVERSION", | ||
| 4003 | "$constant_func should be $func\n" . $herecurr) && | ||
| 4004 | $fix) { | ||
| 4005 | $fixed[$linenr - 1] =~ s/\b$constant_func\b/$func/g; | ||
| 4006 | } | ||
| 4007 | } | ||
| 4008 | |||
| 3913 | # prefer usleep_range over udelay | 4009 | # prefer usleep_range over udelay |
| 3914 | if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { | 4010 | if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { |
| 4011 | my $delay = $1; | ||
| 3915 | # ignore udelay's < 10, however | 4012 | # ignore udelay's < 10, however |
| 3916 | if (! ($1 < 10) ) { | 4013 | if (! ($delay < 10) ) { |
| 3917 | CHK("USLEEP_RANGE", | 4014 | CHK("USLEEP_RANGE", |
| 3918 | "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); | 4015 | "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr); |
| 4016 | } | ||
| 4017 | if ($delay > 2000) { | ||
| 4018 | WARN("LONG_UDELAY", | ||
| 4019 | "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr); | ||
| 3919 | } | 4020 | } |
| 3920 | } | 4021 | } |
| 3921 | 4022 | ||
| @@ -3923,7 +4024,7 @@ sub process { | |||
| 3923 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { | 4024 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { |
| 3924 | if ($1 < 20) { | 4025 | if ($1 < 20) { |
| 3925 | WARN("MSLEEP", | 4026 | WARN("MSLEEP", |
| 3926 | "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); | 4027 | "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr); |
| 3927 | } | 4028 | } |
| 3928 | } | 4029 | } |
| 3929 | 4030 | ||
| @@ -4149,7 +4250,7 @@ sub process { | |||
| 4149 | # check for naked sscanf | 4250 | # check for naked sscanf |
| 4150 | if ($^V && $^V ge 5.10.0 && | 4251 | if ($^V && $^V ge 5.10.0 && |
| 4151 | defined $stat && | 4252 | defined $stat && |
| 4152 | $stat =~ /\bsscanf\b/ && | 4253 | $line =~ /\bsscanf\b/ && |
| 4153 | ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ && | 4254 | ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ && |
| 4154 | $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ && | 4255 | $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ && |
| 4155 | $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) { | 4256 | $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) { |
| @@ -4240,12 +4341,6 @@ sub process { | |||
| 4240 | "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr); | 4341 | "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr); |
| 4241 | } | 4342 | } |
| 4242 | 4343 | ||
| 4243 | # check for GFP_NOWAIT use | ||
| 4244 | if ($line =~ /\b__GFP_NOFAIL\b/) { | ||
| 4245 | WARN("__GFP_NOFAIL", | ||
| 4246 | "Use of __GFP_NOFAIL is deprecated, no new users should be added\n" . $herecurr); | ||
| 4247 | } | ||
| 4248 | |||
| 4249 | # check for multiple semicolons | 4344 | # check for multiple semicolons |
| 4250 | if ($line =~ /;\s*;\s*$/) { | 4345 | if ($line =~ /;\s*;\s*$/) { |
| 4251 | if (WARN("ONE_SEMICOLON", | 4346 | if (WARN("ONE_SEMICOLON", |
| @@ -4457,6 +4552,34 @@ sub process { | |||
| 4457 | WARN("EXPORTED_WORLD_WRITABLE", | 4552 | WARN("EXPORTED_WORLD_WRITABLE", |
| 4458 | "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); | 4553 | "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); |
| 4459 | } | 4554 | } |
| 4555 | |||
| 4556 | # Mode permission misuses where it seems decimal should be octal | ||
| 4557 | # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop | ||
| 4558 | if ($^V && $^V ge 5.10.0 && | ||
| 4559 | $line =~ /$mode_perms_search/) { | ||
| 4560 | foreach my $entry (@mode_permission_funcs) { | ||
| 4561 | my $func = $entry->[0]; | ||
| 4562 | my $arg_pos = $entry->[1]; | ||
| 4563 | |||
| 4564 | my $skip_args = ""; | ||
| 4565 | if ($arg_pos > 1) { | ||
| 4566 | $arg_pos--; | ||
| 4567 | $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}"; | ||
| 4568 | } | ||
| 4569 | my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]"; | ||
| 4570 | if ($line =~ /$test/) { | ||
| 4571 | my $val = $1; | ||
| 4572 | $val = $6 if ($skip_args ne ""); | ||
| 4573 | |||
| 4574 | if ($val !~ /^0$/ && | ||
| 4575 | (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || | ||
| 4576 | length($val) ne 4)) { | ||
| 4577 | ERROR("NON_OCTAL_PERMISSIONS", | ||
| 4578 | "Use 4 digit octal (0777) not decimal permissions\n" . $herecurr); | ||
| 4579 | } | ||
| 4580 | } | ||
| 4581 | } | ||
| 4582 | } | ||
| 4460 | } | 4583 | } |
| 4461 | 4584 | ||
| 4462 | # If we have no input at all, then there is nothing to report on | 4585 | # If we have no input at all, then there is nothing to report on |
