mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] checkpatch: report warning with files ending with blank lines
@ 2026-10-06 10:21 Christian Marangi
  2026-10-06 17:46 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Marangi @ 2026-10-06 10:21 UTC (permalink / raw)
  To: Vinod Koul, Andy Whitcroft, Joe Perches, linux-kernel; +Cc: Christian Marangi

On applying patch, git, depending on the default configuration, might
complain for any file having blank lines at end of file.

These blank lines can go unnotice by the patch submitter as they are not
reported by checkpatch.pl with the maintainer only noticing the error when
the patch is applied. This result in the submitter getting confused asking
further info to the maintainer making the review process longer.

To address this, add a simple logic to catch this error and report as
warning. Example:

WARNING: blank line at end of file
102: FILE: Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml:62:
+    };
+

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 scripts/checkpatch.pl | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8a7787d228a6..0363828b9bd8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2968,6 +2968,25 @@ sub process {
 		my $herecurr = "$here\n$rawline\n";
 		my $hereprev = "$here\n$prevrawline\n$rawline\n";
 
+# Check for blank line at end of file
+		if ($rawline =~ /^\+[ \t]*$/ &&
+		    (!defined $rawlines[$linenr] ||
+		     $rawlines[$linenr] =~ /^diff --git / ||
+		     $rawlines[$linenr] =~ /^-- $/)) {
+			my $context = $rawline;
+
+			for (my $i = $linenr - 2; $i >= 0; $i--) {
+				last if ($rawlines[$i] !~ /^\+/);
+
+				$context = $rawlines[$i] . "\n" . $context;
+
+				last if ($rawlines[$i] !~ /^\+[ \t]*$/);
+			}
+
+			WARN("BLANK_AT_EOF",
+			      "blank line at end of file\n" . $here . "\n" . $context . "\n");
+		}
+
 		$cnt_lines++ if ($realcnt != 0);
 
 # Verify the existence of a commit log if appropriate
-- 
2.55.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-06 17:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-06 10:21 [PATCH] checkpatch: report warning with files ending with blank lines Christian Marangi
2026-10-06 17:46 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®