Skip to contentSkip to conversation

checkpatch: improve EMBEDDED_FUNCTION_NAME test

PATCH New [email protected] 1 participant 1 message May 8, 2017 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 23/114 checkpatch: improve EMBEDDED_FUNCTION_NAME test

From: Joe Perches <[email protected]>
Subject: 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)
{

---

 scripts/checkpatch.pl |   11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-improve-embedded_function_name-test +11 -0
diff -puN scripts/checkpatch.pl~checkpatch-improve-embedded_function_name-test 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...

_