From: Christian Marangi <ansuelsmth@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
linux-kernel@vger.kernel.org
Cc: Christian Marangi <ansuelsmth@gmail.com>
Subject: [PATCH v2] checkpatch: report warning with files ending with blank lines
Date: Wed, 7 Oct 2026 14:28:31 +0200 [thread overview]
Message-ID: <20261007122837.2995-1-ansuelsmth@gmail.com> (raw)
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>
---
Changes v2:
- Move EOF check as last check
scripts/checkpatch.pl | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8a7787d228a6..d12e0e62def5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3887,6 +3887,25 @@ sub process {
"It's generally not useful to have the filename in the file\n" . $herecurr);
}
+# 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");
+ }
+
# check we are in a valid source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|rs|s|S|sh|dtsi|dts)$/);
--
2.55.0
next reply other threads:[~2026-10-07 12:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 12:28 Christian Marangi [this message]
2026-10-07 16:49 ` Joe Perches
2026-10-07 16:52 ` Christian Marangi
2026-10-07 17:50 ` Joe Perches
2026-10-07 17:54 ` Christian Marangi
2026-10-07 18:30 ` Joe Perches
2026-10-07 18:31 ` Christian Marangi
2026-10-07 18:48 ` Joe Perches
2026-10-07 18:50 ` Christian Marangi (Ansuel)
2026-10-07 17:58 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261007122837.2995-1-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®