Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 77cb8546 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

checkpatch: warn on embedded function names

Embedded function names are less appropriate to use when refactoring can
cause function renaming.  Prefer the use of "%s", __func__ to embedded
function names.

Link: http://lkml.kernel.org/r/ac9631fdbac5af3507c5bfe88ad9064f0ed764ec.1483510416.git.joe@perches.com


Signed-off-by: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarAndy Whitcroft <apw@canonical.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 69c78423
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -2154,6 +2154,7 @@ sub process {
	my $realline = 0;
	my $realcnt = 0;
	my $here = '';
	my $context_function;		#undef'd unless there's a known function
	my $in_comment = 0;
	my $comment_edge = 0;
	my $first_line = 0;
@@ -2192,7 +2193,8 @@ sub process {
			}
			#next;
		}
		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
		if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
			my $context = $4;
			$realline=$1-1;
			if (defined $2) {
				$realcnt=$3+1;
@@ -2201,6 +2203,12 @@ sub process {
			}
			$in_comment = 0;

			if ($context =~ /\b(\w+)\s*\(/) {
				$context_function = $1;
			} else {
				undef $context_function;
			}

			# Guestimate if this is a continuing comment.  Run
			# the context looking for a comment "edge".  If this
			# edge is a close comment then we must be in a comment
@@ -5157,6 +5165,16 @@ sub process {
			     "break quoted strings at a space character\n" . $hereprev);
		}

#check for an embedded function name in a string when the function is known
# as part of a diff.  This does not work for -f --file checking as it
#depends on patch context providing the function name
		if ($line =~ /^\+.*$String/ &&
		    defined($context_function) &&
		    get_quoted_string($line, $rawline) =~ /\b$context_function\b/) {
			WARN("EMBEDDED_FUNCTION_NAME",
			     "Prefer using \"%s\", __func__ to embedded function names\n" . $herecurr);
		}

# check for spaces before a quoted newline
		if ($rawline =~ /^.*\".*\s\\n/) {
			if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",