From: Carlos Llamas <cmllamas@google.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>
Cc: kernel-team@android.com, linux-kernel@vger.kernel.org,
Carlos Llamas <cmllamas@google.com>
Subject: [PATCH] checkpatch: ignore removed lines in comment detection
Date: Sun, 9 Nov 2025 16:00:35 +0000 [thread overview]
Message-ID: <20251109160036.643864-1-cmllamas@google.com> (raw)
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
reply other threads:[~2025-11-09 16:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251109160036.643864-1-cmllamas@google.com \
--to=cmllamas@google.com \
--cc=apw@canonical.com \
--cc=dwaipayanray1@gmail.com \
--cc=joe@perches.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®