Skip to contentSkip to conversation

checkpatch: error if file terminates without a new-line

PATCH Prasad Pandit 4 participants 5 messages Apr 16, 2024 – Apr 17, 2024 1 message not in the archive Checkpatch

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

[+linux-kernel]

On Saturday, 30 March, 2024 at 09:09:12 am IST, Prasad Pandit <[email protected]> wrote:
From: Prasad Pandit <[email protected]>

Add check to flag an error if a patch terminates a file without a new line (\n) character.

---
scripts/checkpatch.pl | 7 +++++++

1 file changed, 7 insertions(+)

-> https://lore.kernel.org/all/CAE8KmOxG=3sWKpeB5fdWTK-SCipS=JyDE-_DNgY--DtoSQZ0Qw@mail.gmail.com/T/#t

scripts/checkpatch.pl +0 -0
index 9c4c4a61bc83..df34c0709410 100755
@@ -2795,6 +2795,13 @@ sub process {

            $is_patch = 1;
        }

+# check if patch terminates file without a new line (\n)
+        if ($line =~ /^\\ No newline at end of file$/
+            and $rawlines[$linenr - 2] =~ /^\+.*$/) {
+            ERROR("NOEOL_FILE",
+                  "patch terminates file without a new line (\\n)."); +        }
+
#extract the line range in the file after the patch is applied if (!$in_commit_log &&
            $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {

Signature · 1 line
2.44.0
#2 lore raw
Quoted 3 lines · Prasad Pandit

[+linux-kernel]

On Saturday, 30 March, 2024 at 09:09:12 am IST, Prasad Pandit <[email protected]> wrote:

Why are these lines in a changelog of a patch to submit? That's not going to work :(

I suggest taking some time and talking to some other kernel developers in red hat as to how to submit changes, that will make things much easier.

Quoted 7 lines

From: Prasad Pandit <[email protected]>

Add check to flag an error if a patch terminates a file without a new line (\n) character.

Also, I see 3 different emails for you here, none of which match, pick one for kernel development and stick with it?

Quoted 11 lines

---
scripts/checkpatch.pl | 7 +++++++

1 file changed, 7 insertions(+)

-> https://lore.kernel.org/all/CAE8KmOxG=3sWKpeB5fdWTK-SCipS=JyDE-_DNgY--DtoSQZ0Qw@mail.gmail.com/T/#t

scripts/checkpatch.pl +0 -0
index 9c4c4a61bc83..df34c0709410 100755

scripts/checkpatch.pl sub process { · line 2803

Quoted 9 lines
scripts/checkpatch.pl +6 -0
@@ -2795,6 +2795,13 @@ sub process {
             $is_patch = 1;
         }
 
+# check if patch terminates file without a new line (\n)
+        if ($line =~ /^\\ No newline at end of file$/
+            and $rawlines[$linenr - 2] =~ /^\+.*$/) {
+            ERROR("NOEOL_FILE",
+                  "patch terminates file without a new line (\\n).");
+        }

Why is this a problem? files without a new line should not cause problems with a compiler, right? You don't have a justification for why this change needs to be checked for anywhere.

thanks,

greg k-h

#3 lore raw
Quoted 8 lines · Greg KH
Quoted 8 lines
scripts/checkpatch.pl +0 -0
index 9c4c4a61bc83..df34c0709410 100755
@@ -2795,6 +2795,13 @@ sub process {
             $is_patch = 1;
         }
 
Quoted 11 lines

scripts/checkpatch.pl sub process { · line 2803

Quoted 6 lines
scripts/checkpatch.pl +6 -0
+# check if patch terminates file without a new line (\n)
+        if ($line =~ /^\\ No newline at end of file$/
+            and $rawlines[$linenr - 2] =~ /^\+.*$/) {
+            ERROR("NOEOL_FILE",
+                  "patch terminates file without a new line (\\n).");
+        }

Why is this a problem? files without a new line should not cause problems with a compiler, right? You don't have a justification for why this change needs to be checked for anywhere.

I gave him such a good reason too... It breaks cat file.c. Plus, it looks weird in git log -p because it has a "No newline at the end of file" comment.

regards,
dan carpenter

test.c new file +12 -0
new file mode 100644
index 000000000000..d808cac2d962
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include "check_debug.h"
+
+void kfree(int *p);
+
+int *p;
+int main(void)
+{
+       kfree(p);
+       *p = 1;
+}
\ No newline at end of file

commit f4a997924122d0094675c897a220371f0a129d90

maintainer
#4 lore raw
Quoted 48 lines · Dan Carpenter
Quoted 8 lines · Greg KH
Quoted 8 lines
scripts/checkpatch.pl +0 -0
index 9c4c4a61bc83..df34c0709410 100755
@@ -2795,6 +2795,13 @@ sub process {
             $is_patch = 1;
         }
 
Quoted 11 lines

scripts/checkpatch.pl sub process { · line 2803

Quoted 6 lines
scripts/checkpatch.pl +6 -0
+# check if patch terminates file without a new line (\n)
+        if ($line =~ /^\\ No newline at end of file$/
+            and $rawlines[$linenr - 2] =~ /^\+.*$/) {
+            ERROR("NOEOL_FILE",
+                  "patch terminates file without a new line (\\n).");
+        }

Why is this a problem? files without a new line should not cause problems with a compiler, right? You don't have a justification for why this change needs to be checked for anywhere.

I gave him such a good reason too... It breaks cat file.c. Plus, it looks weird in git log -p because it has a "No newline at the end of file" comment.

regards,
dan carpenter

test.c new file +12 -0
new file mode 100644
index 000000000000..d808cac2d962
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include "check_debug.h"
+
+void kfree(int *p);
+
+int *p;
+int main(void)
+{
+       kfree(p);
+       *p = 1;
+}
\ No newline at end of file
Quoted 2 lines

commit f4a997924122d0094675c897a220371f0a129d90

There's an existing check for this.
I believe it at least used to work.
Fix that instead.

# check for adding lines without a newline.
		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
			if (WARN("MISSING_EOF_NEWLINE",
			         "adding a line without newline at end of file\n" . $herecurr) &&
			    $fix) {
				fix_delete_line($fixlinenr+1, "No newline at end of file");
			}
		}
#5 lore raw
Quoted 9 lines · Joe Perches

There's an existing check for this. Fix that instead.

# check for adding lines without a newline.
       if ($line =~ /^\+/ && defined $lines[$linenr]
           && $lines[$linenr] =~ /^\\ No newline >at end of file/) {
           if (WARN("MISSING_EOF_NEWLINE",
                   "adding a line without newline at end of file\n" . $herecurr) &&
               $fix) {
               fix_delete_line($fixlinenr+1, "No newline at end of file");

Okay, will check; Thank you.
---
  -Prasad