[PATCH] checkpatch: ignore deleted lines for comment context

Andreas Dilger posted 1 patch 1 year, 12 months ago
There is a newer version of this series
scripts/checkpatch.pl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] checkpatch: ignore deleted lines for comment context
Posted by Andreas Dilger 1 year, 12 months ago
From: Andreas Dilger <adilger@dilger.ca>

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)

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 25fdb7fda112..272e30b8adbe 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;
 		}
-- 
2.25.1
Re: [PATCH] checkpatch: ignore deleted lines for comment context
Posted by Joe Perches 1 year, 12 months ago
On Fri, 2023-12-22 at 16:05 -0700, Andreas Dilger wrote:
> From: Andreas Dilger <adilger@dilger.ca>
> 
> 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)
> 
> Signed-off-by: Andreas Dilger <adilger@dilger.ca>

OK, but:

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -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

> +		next if ($line =~ /^-/); # ignore lines removed by patch
>  		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
>  			$in_comment = 1;
>  		}
Re: [PATCH] checkpatch: ignore deleted lines for comment context
Posted by Andreas Dilger 1 year, 12 months ago
On Dec 22, 2023, at 4:15 PM, Joe Perches <joe@perches.com> wrote:
> 
> On Fri, 2023-12-22 at 16:05 -0700, Andreas Dilger wrote:
>> From: Andreas Dilger <adilger@dilger.ca>
>> 
>> 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)
>> 
>> Signed-off-by: Andreas Dilger <adilger@dilger.ca>
> 
> OK, but:
> 
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
>> @@ -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...

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


Cheers, Andreas