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