Skip to contentSkip to conversation

checkpatch: ignore deleted lines for comment context

PATCH In review Andreas Dilger 3 participants 3 messages Dec 22, 2023 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: ignore deleted lines for comment context

From: Andreas Dilger <[email protected]>

Don't consider lines being removed by a patch as part of a comment. Otherwise, false "WARNING: memory barrier without comment" and similar issues can be reported when a comment does exist 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)

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index 25fdb7fda112..272e30b8adbe 100755
@@ -1972,7 +1972,8 @@ sub ctx_locate_comment {
 	$current_comment = '';
 	for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
 		my $line = $rawlines[$linenr - 1];
-		#warn "           $line\n";
+		#warn "LINE($linenr): $line\n";
+		next if ($line =~ /^-/); # ignore lines removed by patch
 		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
 			$in_comment = 1;
 		}
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 6 lines · Andreas Dilger

From: Andreas Dilger <[email protected]>

Don't consider lines being removed by a patch as part of a comment. Otherwise, false "WARNING: memory barrier without comment" and similar issues can be reported when a comment does exist on the previous line.

Quoted 7 lines

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)

OK, but:

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub ctx_locate_comment { · line 1975

Quoted 6 lines
scripts/checkpatch.pl +1 -1
@@ -1972,7 +1972,8 @@ sub ctx_locate_comment {
 	$current_comment = '';
 	for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
 		my $line = $rawlines[$linenr - 1];
-		#warn "           $line\n";
+		#warn "LINE($linenr): $line\n";

This is a superfluous change

Quoted 4 lines
scripts/checkpatch.pl +1 -0
+		next if ($line =~ /^-/); # ignore lines removed by patch
 		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
 			$in_comment = 1;
 		}
#2 lore raw
Quoted 20 lines · Joe Perches
Quoted 12 lines · Andreas Dilger

From: Andreas Dilger <[email protected]>

Don't consider lines being removed by a patch as part of a comment. Otherwise, false "WARNING: memory barrier without comment" and similar issues can be reported when a comment does exist on the previous line.

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

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

OK, but:

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 8 lines

scripts/checkpatch.pl sub ctx_locate_comment { · line 1975

Quoted 6 lines
scripts/checkpatch.pl +1 -1
@@ -1972,7 +1972,8 @@ sub ctx_locate_comment {
 	$current_comment = '';
 	for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
 		my $line = $rawlines[$linenr - 1];
-		#warn "           $line\n";
+		#warn "LINE($linenr): $line\n";

This is a superfluous change

Sure, I can resubmit without it if you want. I found it helpful when debugging why this code didn't work in the first place...

Quoted 6 lines

scripts/checkpatch.pl sub ctx_locate_comment { · line 1979

Quoted 5 lines
scripts/checkpatch.pl +1 -0
+		next if ($line =~ /^-/); # ignore lines removed by patch
 		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
 			$in_comment = 1;
 		}

Cheers, Andreas