Skip to contentSkip to conversation

checkpatch: report warning with files ending with blank lines

PATCH In review Christian Marangi 2 participants 10 messages Oct 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch: report warning with files ending with blank lines

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:
+ };
+

---
Changes v2:
- Move EOF check as last check

 scripts/checkpatch.pl | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
scripts/checkpatch.pl +19 -0
index 8a7787d228a6..d12e0e62def5 100755
@@ -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)$/);
 
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 3 lines · Christian Marangi

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

I was not clear enough in my first reply.

I meant that the test should be done only once, not for each line of the input.

After the end of the process() loop of

	foreach my $rawline (@rawlines) {
		[...]
	}

a single test of $rawlines[-1] could be done.

#2 lore raw
Quoted 10 lines · Joe Perches
Quoted 3 lines · Christian Marangi

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

I was not clear enough in my first reply.

I meant that the test should be done only once, not for each line of the input.

Quoted 7 lines

After the end of the process() loop of

	foreach my $rawline (@rawlines) {
		[...]
	}

a single test of $rawlines[-1] could be done.

Yes I also was with that idea but then I quickly figure it out that we are not testing if the .patch have blank line at EOF. But if the single file of the patch have blank line at EOF.

That can only be done in the process() while scanning each line as it does progressively check new files in it.

(unless I'm missing something)

Signature · 1 line
	Ansuel
maintainer
#3 lore raw
Quoted 17 lines · Christian Marangi

On Wed, Oct 07, 2026 at 09:49:48AM -0700, Joe Perches wrote:

Quoted 9 lines · Christian Marangi
Quoted 2 lines

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

I was not clear enough in my first reply.

I meant that the test should be done only once, not for each line of the input.

After the end of the process() loop of

	foreach my $rawline (@rawlines) {
		[...]
	}
Quoted 2 lines

a single test of $rawlines[-1] could be done.

Quoted 8 lines

Yes I also was with that idea but then I quickly figure it out that we are not testing if the .patch have blank line at EOF. But if the single file of the patch have blank line at EOF.

That can only be done in the process() while scanning each line as it does progressively check new files in it.

(unless I'm missing something)

Dunno. Maybe I'm missing something but maybe something like this:

scripts/checkpatch.pl +7 -0
index f424dafce5bce..d2f99127a9a9a 100755
@@ -7850,6 +7850,13 @@ sub process {
 		exit(0);
 	}
 
+	# check if the last line is a blank line
+	if (($is_patch && $rawlines[-1] =~ /^\+\s*$/) ||
+	    (!$is_patch && $rawlines[-1] =~ /^\s*$/)) {
+		WARN("LINE_SPACING",
+		     "Blank lines at EOF are not good\n");
+	}
+
 	# In mailback mode only produce a report in the negative, for
 	# things that appear to be patches.
 	if ($mailback && ($clean == 1 || !$is_patch)) {
#4 lore raw
Quoted 37 lines · Joe Perches
Quoted 17 lines · Christian Marangi

On Wed, Oct 07, 2026 at 09:49:48AM -0700, Joe Perches wrote:

Quoted 9 lines · Christian Marangi
Quoted 2 lines

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

I was not clear enough in my first reply.

I meant that the test should be done only once, not for each line of the input.

After the end of the process() loop of

	foreach my $rawline (@rawlines) {
		[...]
	}
Quoted 2 lines

a single test of $rawlines[-1] could be done.

Quoted 8 lines

Yes I also was with that idea but then I quickly figure it out that we are not testing if the .patch have blank line at EOF. But if the single file of the patch have blank line at EOF.

That can only be done in the process() while scanning each line as it does progressively check new files in it.

(unless I'm missing something)

Dunno. Maybe I'm missing something but maybe something like this:

scripts/checkpatch.pl +0 -0
index f424dafce5bce..d2f99127a9a9a 100755
@@ -7850,6 +7850,13 @@ sub process {
 		exit(0);
 	}
 

scripts/checkpatch.pl sub process { · line 7862

Quoted 10 lines
scripts/checkpatch.pl +7 -0
+	# check if the last line is a blank line
+	if (($is_patch && $rawlines[-1] =~ /^\+\s*$/) ||
+	    (!$is_patch && $rawlines[-1] =~ /^\s*$/)) {
+		WARN("LINE_SPACING",
+		     "Blank lines at EOF are not good\n");
+	}
+
 	# In mailback mode only produce a report in the negative, for
 	# things that appear to be patches.
 	if ($mailback && ($clean == 1 || !$is_patch)) {

Yes if you think about this, this will read the last line of the .patch, not the last line of a new file that will be generated by the .patch.

MAINTAINERS +6 -0
index 70a11f2ff61d..0b9946c532af 100644
@@ -785,3 +785,9 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml
 F:	drivers/spi/spi-airoha-snfi.c
 
+AIROHA USB PHY DRIVER
+M:	Christian Marangi <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml
+
Signature · 9 lines
2.55.0

It's to catch situation like this. Example for entire new file or adding
stuff at the end of a file, where a new line is introduced.

git am will complain about this.

-- 
	Ansuel
maintainer
#5 lore raw
In reply to Christian Marangi
Quoted 24 lines · Christian Marangi

Yes if you think about this, this will read the last line of the .patch, not the last line of a new file that will be generated by the .patch.

MAINTAINERS +6 -0
index 70a11f2ff61d..0b9946c532af 100644
@@ -785,3 +785,9 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml
 F:	drivers/spi/spi-airoha-snfi.c
 
+AIROHA USB PHY DRIVER
+M:	Christian Marangi <[[email protected]](mailto:[email protected])>
+L:	[[email protected]](mailto:[email protected]) (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml
+
Signature · 6 lines
2.55.0

It's to catch situation like this. Example for entire new file or adding
stuff at the end of a file, where a new line is introduced.

git am will complain about this.

It seems there's something odd about the patch content as there aren't any context lines after the addition.

How was it generated ?

#6 lore raw
Quoted 24 lines · Joe Perches
Quoted 23 lines · Christian Marangi

Yes if you think about this, this will read the last line of the .patch, not the last line of a new file that will be generated by the .patch.

MAINTAINERS +6 -0
index 70a11f2ff61d..0b9946c532af 100644
@@ -785,3 +785,9 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml
 F:	drivers/spi/spi-airoha-snfi.c
 
+AIROHA USB PHY DRIVER
+M:	Christian Marangi <[[email protected]](mailto:[email protected])>
+L:	[[email protected]](mailto:[email protected]) (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml
+
Signature · 4 lines
2.55.0

It's to catch situation like this. Example for entire new file or adding
stuff at the end of a file, where a new line is introduced.
Quoted 6 lines
Quoted 1 line

git am will complain about this.

It seems there's something odd about the patch content as there aren't any context lines after the addition.

How was it generated ?

It was just an example, it's not the full patch. Just the last patch.

Signature · 1 line
	Ansuel
maintainer
#7 lore raw
Quoted 11 lines · Christian Marangi
Quoted 9 lines
Quoted 4 lines

It's to catch situation like this. Example for entire new file or adding stuff at the end of a file, where a new line is introduced.

git am will complain about this.

It seems there's something odd about the patch content as there aren't any context lines after the addition.

How was it generated ?

It was just an example, it's not the full patch. Just the last patch.

Send more correct examples.

author Reviewed-by Krzysztof Kozlowski
#8 lore raw

Il giorno mer 7 ott 2026 alle ore 20:48 Joe Perches <[email protected]> ha scritto:

Quoted 8 lines · Christian Marangi
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

It's to catch situation like this. Example for entire new file or adding stuff at the end of a file, where a new line is introduced.

git am will complain about this.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

It seems there's something odd about the patch content as there aren't any context lines after the addition.

How was it generated ?

It was just an example, it's not the full patch. Just the last patch.

Send more correct examples.

Here... the DT file adds a whitespace at the end of file. With this patch checkpatch
correctly report the problem.

From 530fb038855d8e64023a3fd14ebd0396bbfc780a Mon Sep 17 00:00:00 2001
From: Christian Marangi <[email protected]>
Date: Fri, 7 Feb 2025 13:25:28 +0100
Subject: [PATCH v12 1/3] dt-bindings: phy: Add documentation for Airoha AN7581
USB PHY

Add documentation for Airoha AN7581 USB PHY that describe the USB PHY for the USB controller.

Airoha AN7581 SoC support a maximum of 2 USB port. The USB 2.0 mode is always supported. The USB 3.0 mode is optional and depends on the Serdes mode currently configured on the system for the relevant USB port.

To correctly calibrate, the USB 2.0 port require correct value in "airoha,usb2-monitor-clk-sel" property. Both the 2 USB 2.0 port permit selecting one of the 4 monitor clock for calibration (internal clock not exposed to the system) but each port have only one of the 4 actually connected in HW hence the correct value needs to be specified in DT based on board and the physical port. Normally it's monitor clock 1 for USB1 and monitor clock 2 for USB2.

To correctly setup the Serdes mode attached to the USB 3.0 mode, a phys property is required with the phandle pointing to the correct Serdes port provided by the SCU node. Providing the phys property is optional if USB 3.0 is not used.

---
 .../bindings/phy/airoha,an7581-usb-phy.yaml   | 62 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 68 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml

(quoted diff) +0 -0

b/Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml new file mode 100644
index 000000000000..f42e3d49a61f

Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml new file +62 -0

62 lines not on this page · raw message

MAINTAINERS +6 -0
index 70a11f2ff61d..0b9946c532af 100644
@@ -785,6 +785,12 @@ S: Maintained
 F: Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml
 F: drivers/spi/spi-airoha-snfi.c
 
+AIROHA USB PHY DRIVER
+M: Christian Marangi <[email protected]>
+L: [email protected] (moderated for non-subscribers)
+S: Maintained
+F: Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml
+
 AIRSPY MEDIA DRIVER
 L: [email protected]
 S: Orphan
Signature · 1 line
2.55.0