diff options
author | Joe Perches <joe@perches.com> | 2017-07-10 18:52:19 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-10 19:32:35 -0400 |
commit | a0ad75964e58cd7d9b6910e2bbb8a7e8656c0f51 (patch) | |
tree | d8fa1c454226dfb8dc05502e8706912369611ed1 | |
parent | 948b133a1b62441bd2ae98b866f409017191fdd3 (diff) |
checkpatch: improve tests for multiple line function definitions
Add a block that identifies multiple line function definitions.
Save the function name into $context_function to improve the embedded
function name test.
Look for misplaced open brace on the function definition.
Emit an OPEN_BRACE error when the function definition is similar to
void foo(int arg1,
int arg2) {
Miscellanea:
o Remove the $realfile test in function declaration w/o named arguments test
o Comment the function declaration w/o named arguments test
Link: http://lkml.kernel.org/r/de620ed6ebab75fdfa323741ada2134a0f545892.1496835238.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Tested-by: David Kershner <david.kershner@unisys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rwxr-xr-x | scripts/checkpatch.pl | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e9618ca31251..a103f4fc30a2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -5899,7 +5899,8 @@ sub process { | |||
5899 | "externs should be avoided in .c files\n" . $herecurr); | 5899 | "externs should be avoided in .c files\n" . $herecurr); |
5900 | } | 5900 | } |
5901 | 5901 | ||
5902 | if ($realfile =~ /\.[ch]$/ && defined $stat && | 5902 | # check for function declarations that have arguments without identifier names |
5903 | if (defined $stat && | ||
5903 | $stat =~ /^.\s*(?:extern\s+)?$Type\s*$Ident\s*\(\s*([^{]+)\s*\)\s*;/s && | 5904 | $stat =~ /^.\s*(?:extern\s+)?$Type\s*$Ident\s*\(\s*([^{]+)\s*\)\s*;/s && |
5904 | $1 ne "void") { | 5905 | $1 ne "void") { |
5905 | my $args = trim($1); | 5906 | my $args = trim($1); |
@@ -5912,6 +5913,29 @@ sub process { | |||
5912 | } | 5913 | } |
5913 | } | 5914 | } |
5914 | 5915 | ||
5916 | # check for function definitions | ||
5917 | if ($^V && $^V ge 5.10.0 && | ||
5918 | defined $stat && | ||
5919 | $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) { | ||
5920 | $context_function = $1; | ||
5921 | |||
5922 | # check for multiline function definition with misplaced open brace | ||
5923 | my $ok = 0; | ||
5924 | my $cnt = statement_rawlines($stat); | ||
5925 | my $herectx = $here . "\n"; | ||
5926 | for (my $n = 0; $n < $cnt; $n++) { | ||
5927 | my $rl = raw_line($linenr, $n); | ||
5928 | $herectx .= $rl . "\n"; | ||
5929 | $ok = 1 if ($rl =~ /^[ \+]\{/); | ||
5930 | $ok = 1 if ($rl =~ /\{/ && $n == 0); | ||
5931 | last if $rl =~ /^[ \+].*\{/; | ||
5932 | } | ||
5933 | if (!$ok) { | ||
5934 | ERROR("OPEN_BRACE", | ||
5935 | "open brace '{' following function definitions go on the next line\n" . $herectx); | ||
5936 | } | ||
5937 | } | ||
5938 | |||
5915 | # checks for new __setup's | 5939 | # checks for new __setup's |
5916 | if ($rawline =~ /\b__setup\("([^"]*)"/) { | 5940 | if ($rawline =~ /\b__setup\("([^"]*)"/) { |
5917 | my $name = $1; | 5941 | my $name = $1; |