Skip to contentSkip to conversation

checkpatch: ignore removed lines in comment detection

PATCH New Carlos Llamas 1 participant 1 message Nov 9, 2025 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: ignore removed lines in comment detection

The comment detection logic in ctx_locate_comment() can be confused by removed lines in a patch. When a removed line is encountered, any previously detected comments are ignored.

For example, in the following change checkpatch fails to detect the existing comment and reports: "WARNING: data_race without comment".

         /* explanation */
 -       if (data_race(priv->init))
 +       if (data_race(priv->init) && bytes)
                 break;

Fix this by explicitly ignoring any removed lines when looking at the context. This ensures that comments are correctly associated to the added lines.

---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)
scripts/checkpatch.pl +1 -0
index 92669904eecc..c4432f88c58f 100755
@@ -1990,6 +1990,7 @@ sub ctx_locate_comment {
 	for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
 		my $line = $rawlines[$linenr - 1];
 		#warn "           $line\n";
+		next if ($line =~ m@^-@); # skip removed lines
 		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
 			$in_comment = 1;
 		}
Signature · 1 line
2.51.2.1041.gc1ab5b90ca-goog