mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] checkpatch: ignore removed lines in comment detection
@ 2025-11-09 16:00 Carlos Llamas
  0 siblings, 0 replies; only message in thread
From: Carlos Llamas @ 2025-11-09 16:00 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn
  Cc: kernel-team, linux-kernel, Carlos Llamas

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.

Signed-off-by: Carlos Llamas <cmllamas@google.com>
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 92669904eecc..c4432f88c58f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;
 		}
-- 
2.51.2.1041.gc1ab5b90ca-goog


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

only message in thread, other threads:[~2025-11-09 16:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-09 16:00 [PATCH] checkpatch: ignore removed lines in comment detection Carlos Llamas

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®