[PATCH] checkpatch: ignore deleted lines for comment context

Andreas Dilger posted 1 patch 2 months, 3 weeks ago
scripts/checkpatch.pl | 1 +
1 file changed, 1 insertion(+)
[PATCH] checkpatch: ignore deleted lines for comment context
Posted by Andreas Dilger 2 months, 3 weeks ago
Don't consider lines being removed by a patch as part of the context.
Otherwise, false "WARNING: memory barrier without comment" and similar
warnings can be reported when a comment exists on the previous line.

For example, a change like below was previously incorrectly flagged:

	/* matched by smp_store_release() in some_function() */
 -	if (smp_load_acquire(&list->tail) == head))
 +	if (smp_load_acquire(&list->tail) == head) && flags == 0)

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 664f7b7a622c..dc90a0871a0e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1989,6 +1989,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 =~ /^-/); # ignore lines removed by patch
 		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
 			$in_comment = 1;
 		}
-- 
2.43.5