The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] checkpatch: error on .orig and .rej files in patches
@ 2026-03-13  1:42 Matteo Croce
  0 siblings, 0 replies; only message in thread
From: Matteo Croce @ 2026-03-13  1:42 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: linux-kernel, Matteo Croce

From: Matteo Croce <teknoraver@meta.com>

Since commit 76be4f5a7845 ("Remove *.orig pattern from .gitignore"),
it's easier to accidentally slip a .orig file into a patch.

Add a RESIDUAL_FILE error when a patch modifies .orig or .rej files,
which are typically leftovers from a failed patch application. Skip all
further checks on the content of such files to avoid spurious warnings.

Signed-off-by: Matteo Croce <teknoraver@meta.com>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c0250244cf7a..d110afef1b57 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2701,6 +2701,7 @@ sub process {
 	my $comment_edge = 0;
 	my $first_line = 0;
 	my $p1_prefix = '';
+	my $skip_residual_file = 0;
 
 	my $prev_values = 'E';
 
@@ -2881,6 +2882,7 @@ sub process {
 			$realfile = $1;
 			$realfile =~ s@^([^/]*)/@@ if (!$file);
 			$in_commit_log = 0;
+			$skip_residual_file = 0;
 			$found_file = 1;
 		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
 			$realfile = $1;
@@ -2913,6 +2915,15 @@ sub process {
 		}
 
 		if ($found_file) {
+			if ($realfile =~ /\.(orig|rej)$/) {
+				if (!$skip_residual_file) {
+					ERROR("RESIDUAL_FILE",
+					      "patch modifies a .$1 file: '$realfile', likely leftover from a failed patch application\n");
+				}
+				$skip_residual_file = 1;
+				next;
+			}
+			$skip_residual_file = 0;
 			if (is_maintained_obsolete($realfile)) {
 				WARN("OBSOLETE",
 				     "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy.  No unnecessary modifications please.\n");
@@ -2939,6 +2950,8 @@ sub process {
 			next;
 		}
 
+		next if ($skip_residual_file);
+
 		$here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
 
 		my $hereline = "$here\n$rawline\n";
-- 
2.50.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-03-13  1:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13  1:42 [PATCH] checkpatch: error on .orig and .rej files in patches Matteo Croce

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