checkpatch: emit a warning on embedded filenames
authorJoe Perches <joe@perches.com>
Fri, 16 Oct 2020 03:12:19 +0000 (20:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 16 Oct 2020 18:11:21 +0000 (11:11 -0700)
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.

[akpm@linux-foundation.org: remove stray " di"]

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Link: https://lkml.kernel.org/r/1fd5f9188a14acdca703ca00301ee323de672a8d.camel@perches.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index f40a81f24d434947f55041ff0029d0ca71c04de5..5424134e201d226ff279da30bb78a9c954096a09 100755 (executable)
@@ -3271,6 +3271,12 @@ sub process {
                        }
                }
 
+# check for embedded filenames
+               if ($rawline =~ /^\+.*\Q$realfile\E/) {
+                       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)$/);