diff options
author | Joe Perches <joe@perches.com> | 2017-05-09 00:55:39 +0200 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-09 02:15:11 +0200 |
commit | 4dbed76f2429516b9519620dacdda6c750640e8d (patch) | |
tree | a0abeaa3adc83ad547c06d7d12df12bbc7b3b329 /scripts/checkpatch.pl | |
parent | checkpatch: add ability to find bad uses of vsprintf %p<foo> extensions (diff) | |
download | linux-4dbed76f2429516b9519620dacdda6c750640e8d.tar.xz linux-4dbed76f2429516b9519620dacdda6c750640e8d.zip |
checkpatch: improve EMBEDDED_FUNCTION_NAME test
The existing behavior relies on patch context to identify function
declarations. Add the ability to find function declarations when there
is an open brace in column 1.
This finds function declarations only in specific single line forms
where the function name is on a single line like:
int foo(args...)
{
and
int
foo(args...)
{
It does not recognize function declarations like:
int foo(int bar,
int baz)
{
Link: http://lkml.kernel.org/r/738d74bbbe1a06b80f11ed504818107c68903095.1488155636.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 732bb3e2fe9a..832e8150dba3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3126,6 +3126,17 @@ sub process { # check we are in a valid C source file if not then ignore this hunk next if ($realfile !~ /\.(h|c)$/); +# check if this appears to be the start function declaration, save the name + if ($sline =~ /^\+\{\s*$/ && + $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) { + $context_function = $1; + } + +# check if this appears to be the end of function declaration + if ($sline =~ /^\+\}\s*$/) { + undef $context_function; + } + # check indentation of any line with a bare else # (but not if it is a multiple line "if (foo) return bar; else return baz;") # if the previous line is a break or return and is indented 1 tab more... |