[PATCH] checkpatch: Emit a warning on embedded filenames

From: Joe Perches
Date: Thu Oct 01 2020 - 14:28:14 EST


Embedding the complete filename path inside the file
isn't particularly useful as often the path is moved
around and becomes incorrect.

Emit a warning when the source contains the filename.

Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
---
scripts/checkpatch.pl | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a213cdb82ab0..84d2ee118c55 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3273,6 +3273,12 @@ sub process {
}
}

+# check for embedded filenames
+ if ($rawline =~ /^\+.*\Q$realfile\E/) { di
+ WARN("EMBEDDED_FILENAME",
+ "It's generally not useful to have the filename in the file\n" . $herecurr);
+ }
+
# check we are in a valid source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);