diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7bed4ed2c519..2d5ece798c4c 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -10,7 +10,7 @@ use strict; | |||
10 | my $P = $0; | 10 | my $P = $0; |
11 | $P =~ s@.*/@@g; | 11 | $P =~ s@.*/@@g; |
12 | 12 | ||
13 | my $V = '0.26'; | 13 | my $V = '0.28'; |
14 | 14 | ||
15 | use Getopt::Long qw(:config no_auto_abbrev); | 15 | use Getopt::Long qw(:config no_auto_abbrev); |
16 | 16 | ||
@@ -110,7 +110,8 @@ our $Sparse = qr{ | |||
110 | __iomem| | 110 | __iomem| |
111 | __must_check| | 111 | __must_check| |
112 | __init_refok| | 112 | __init_refok| |
113 | __kprobes | 113 | __kprobes| |
114 | __ref | ||
114 | }x; | 115 | }x; |
115 | our $Attribute = qr{ | 116 | our $Attribute = qr{ |
116 | const| | 117 | const| |
@@ -411,13 +412,15 @@ sub ctx_statement_block { | |||
411 | 412 | ||
412 | my $type = ''; | 413 | my $type = ''; |
413 | my $level = 0; | 414 | my $level = 0; |
414 | my @stack = ([$type, $level]); | 415 | my @stack = (); |
415 | my $p; | 416 | my $p; |
416 | my $c; | 417 | my $c; |
417 | my $len = 0; | 418 | my $len = 0; |
418 | 419 | ||
419 | my $remainder; | 420 | my $remainder; |
420 | while (1) { | 421 | while (1) { |
422 | @stack = (['', 0]) if ($#stack == -1); | ||
423 | |||
421 | #warn "CSB: blk<$blk> remain<$remain>\n"; | 424 | #warn "CSB: blk<$blk> remain<$remain>\n"; |
422 | # If we are about to drop off the end, pull in more | 425 | # If we are about to drop off the end, pull in more |
423 | # context. | 426 | # context. |
@@ -1238,7 +1241,8 @@ sub process { | |||
1238 | $realfile =~ s@^([^/]*)/@@; | 1241 | $realfile =~ s@^([^/]*)/@@; |
1239 | 1242 | ||
1240 | $p1_prefix = $1; | 1243 | $p1_prefix = $1; |
1241 | if ($tree && $p1_prefix ne '' && -e "$root/$p1_prefix") { | 1244 | if (!$file && $tree && $p1_prefix ne '' && |
1245 | -e "$root/$p1_prefix") { | ||
1242 | WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); | 1246 | WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); |
1243 | } | 1247 | } |
1244 | 1248 | ||
@@ -1581,9 +1585,9 @@ sub process { | |||
1581 | } | 1585 | } |
1582 | # TEST: allow direct testing of the attribute matcher. | 1586 | # TEST: allow direct testing of the attribute matcher. |
1583 | if ($dbg_attr) { | 1587 | if ($dbg_attr) { |
1584 | if ($line =~ /^.\s*$Attribute\s*$/) { | 1588 | if ($line =~ /^.\s*$Modifier\s*$/) { |
1585 | ERROR("TEST: is attr\n" . $herecurr); | 1589 | ERROR("TEST: is attr\n" . $herecurr); |
1586 | } elsif ($dbg_attr > 1 && $line =~ /^.+($Attribute)/) { | 1590 | } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) { |
1587 | ERROR("TEST: is not attr ($1 is)\n". $herecurr); | 1591 | ERROR("TEST: is not attr ($1 is)\n". $herecurr); |
1588 | } | 1592 | } |
1589 | next; | 1593 | next; |
@@ -1655,7 +1659,7 @@ sub process { | |||
1655 | 1659 | ||
1656 | # * goes on variable not on type | 1660 | # * goes on variable not on type |
1657 | # (char*[ const]) | 1661 | # (char*[ const]) |
1658 | if ($line =~ m{\($NonptrType(\s*\*[\s\*]*(?:$Modifier\s*)*)\)}) { | 1662 | if ($line =~ m{\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\)}) { |
1659 | my ($from, $to) = ($1, $1); | 1663 | my ($from, $to) = ($1, $1); |
1660 | 1664 | ||
1661 | # Should start with a space. | 1665 | # Should start with a space. |
@@ -1663,14 +1667,14 @@ sub process { | |||
1663 | # Should not end with a space. | 1667 | # Should not end with a space. |
1664 | $to =~ s/\s+$//; | 1668 | $to =~ s/\s+$//; |
1665 | # '*'s should not have spaces between. | 1669 | # '*'s should not have spaces between. |
1666 | while ($to =~ s/(.)\s\*/$1\*/) { | 1670 | while ($to =~ s/\*\s+\*/\*\*/) { |
1667 | } | 1671 | } |
1668 | 1672 | ||
1669 | #print "from<$from> to<$to>\n"; | 1673 | #print "from<$from> to<$to>\n"; |
1670 | if ($from ne $to) { | 1674 | if ($from ne $to) { |
1671 | ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); | 1675 | ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); |
1672 | } | 1676 | } |
1673 | } elsif ($line =~ m{\b$NonptrType(\s*\*[\s\*]*(?:$Modifier\s*)?)($Ident)}) { | 1677 | } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) { |
1674 | my ($from, $to, $ident) = ($1, $1, $2); | 1678 | my ($from, $to, $ident) = ($1, $1, $2); |
1675 | 1679 | ||
1676 | # Should start with a space. | 1680 | # Should start with a space. |
@@ -1678,13 +1682,13 @@ sub process { | |||
1678 | # Should not end with a space. | 1682 | # Should not end with a space. |
1679 | $to =~ s/\s+$//; | 1683 | $to =~ s/\s+$//; |
1680 | # '*'s should not have spaces between. | 1684 | # '*'s should not have spaces between. |
1681 | while ($to =~ s/(.)\s\*/$1\*/) { | 1685 | while ($to =~ s/\*\s+\*/\*\*/) { |
1682 | } | 1686 | } |
1683 | # Modifiers should have spaces. | 1687 | # Modifiers should have spaces. |
1684 | $to =~ s/(\b$Modifier$)/$1 /; | 1688 | $to =~ s/(\b$Modifier$)/$1 /; |
1685 | 1689 | ||
1686 | #print "from<$from> to<$to>\n"; | 1690 | #print "from<$from> to<$to> ident<$ident>\n"; |
1687 | if ($from ne $to) { | 1691 | if ($from ne $to && $ident !~ /^$Modifier$/) { |
1688 | ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); | 1692 | ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); |
1689 | } | 1693 | } |
1690 | } | 1694 | } |
@@ -1883,11 +1887,11 @@ sub process { | |||
1883 | if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { | 1887 | if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { |
1884 | ERROR("space required before that '$op' $at\n" . $hereptr); | 1888 | ERROR("space required before that '$op' $at\n" . $hereptr); |
1885 | } | 1889 | } |
1886 | if ($op eq '*' && $cc =~/\s*const\b/) { | 1890 | if ($op eq '*' && $cc =~/\s*$Modifier\b/) { |
1887 | # A unary '*' may be const | 1891 | # A unary '*' may be const |
1888 | 1892 | ||
1889 | } elsif ($ctx =~ /.xW/) { | 1893 | } elsif ($ctx =~ /.xW/) { |
1890 | ERROR("space prohibited after that '$op' $at\n" . $hereptr); | 1894 | ERROR("Aspace prohibited after that '$op' $at\n" . $hereptr); |
1891 | } | 1895 | } |
1892 | 1896 | ||
1893 | # unary ++ and unary -- are allowed no space on one side. | 1897 | # unary ++ and unary -- are allowed no space on one side. |
@@ -2014,7 +2018,11 @@ sub process { | |||
2014 | 2018 | ||
2015 | # Flatten any parentheses | 2019 | # Flatten any parentheses |
2016 | $value =~ s/\)\(/\) \(/g; | 2020 | $value =~ s/\)\(/\) \(/g; |
2017 | while ($value !~ /(?:$Ident|-?$Constant)\s*$Compare\s*(?:$Ident|-?$Constant)/ && $value =~ s/\([^\(\)]*\)/1/) { | 2021 | while ($value =~ s/\[[^\{\}]*\]/1/ || |
2022 | $value !~ /(?:$Ident|-?$Constant)\s* | ||
2023 | $Compare\s* | ||
2024 | (?:$Ident|-?$Constant)/x && | ||
2025 | $value =~ s/\([^\(\)]*\)/1/) { | ||
2018 | } | 2026 | } |
2019 | 2027 | ||
2020 | if ($value =~ /^(?:$Ident|-?$Constant)$/) { | 2028 | if ($value =~ /^(?:$Ident|-?$Constant)$/) { |
@@ -2102,6 +2110,11 @@ sub process { | |||
2102 | ERROR("trailing statements should be on next line\n" . $herecurr); | 2110 | ERROR("trailing statements should be on next line\n" . $herecurr); |
2103 | } | 2111 | } |
2104 | } | 2112 | } |
2113 | # if should not continue a brace | ||
2114 | if ($line =~ /}\s*if\b/) { | ||
2115 | ERROR("trailing statements should be on next line\n" . | ||
2116 | $herecurr); | ||
2117 | } | ||
2105 | # case and default should not have general statements after them | 2118 | # case and default should not have general statements after them |
2106 | if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g && | 2119 | if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g && |
2107 | $line !~ /\G(?: | 2120 | $line !~ /\G(?: |
@@ -2516,9 +2529,10 @@ sub process { | |||
2516 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); | 2529 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); |
2517 | } | 2530 | } |
2518 | # check for struct file_operations, ensure they are const. | 2531 | # check for struct file_operations, ensure they are const. |
2519 | if ($line =~ /\bstruct\s+file_operations\b/ && | 2532 | if ($line !~ /\bconst\b/ && |
2520 | $line !~ /\bconst\b/) { | 2533 | $line =~ /\bstruct\s+(file_operations|seq_operations)\b/) { |
2521 | WARN("struct file_operations should normally be const\n" . $herecurr); | 2534 | WARN("struct $1 should normally be const\n" . |
2535 | $herecurr); | ||
2522 | } | 2536 | } |
2523 | 2537 | ||
2524 | # use of NR_CPUS is usually wrong | 2538 | # use of NR_CPUS is usually wrong |
@@ -2548,7 +2562,7 @@ sub process { | |||
2548 | if ($line =~ /\bin_atomic\s*\(/) { | 2562 | if ($line =~ /\bin_atomic\s*\(/) { |
2549 | if ($realfile =~ m@^drivers/@) { | 2563 | if ($realfile =~ m@^drivers/@) { |
2550 | ERROR("do not use in_atomic in drivers\n" . $herecurr); | 2564 | ERROR("do not use in_atomic in drivers\n" . $herecurr); |
2551 | } else { | 2565 | } elsif ($realfile !~ m@^kernel/@) { |
2552 | WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); | 2566 | WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); |
2553 | } | 2567 | } |
2554 | } | 2568 | } |