Skip to contentSkip to conversation

scripts: checkpatch: Check multiple blank lines when deleting code

PATCH Joe Perches 2 participants 2 messages Mar 1, 2019 – Mar 2, 2019 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

scripts/checkpatch.pl

Quoted 23 lines · Alexandre Ghiti

By matching only current line starting with '+', we miss the case when deleting code makes consecutive blank lines appear: this patch then makes it possible to detect this case by also matching current line starting with ' ', which is an already existing blank line.

On the following example, checkpatch --subjective now complains about multiple blank lines:

static long hugepage_subpool_get_pages(struct hugepage_subpool *spool, {

(quoted diff) +0 -2
 	long ret = delta;
 
-	if (!spool)
-		return ret;
 
 	spin_lock(&spool->lock);
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 3304

Quoted 9 lines
scripts/checkpatch.pl +1 -1
@@ -3298,7 +3298,7 @@ sub process {
 
 # check for multiple consecutive blank lines
 		if ($prevline =~ /^[\+ ]\s*$/ &&
-		    $line =~ /^\+\s*$/ &&
+		    $line =~ /^[\+ ]\s*$/ &&
 		    $last_blank_line != ($linenr - 1)) {
 			if (CHK("LINE_SPACING",
 				"Please don't use multiple blank lines\n" . $hereprev) &&

I believe this screws up the --fix option just below this if the line does not start with +

#2 lore raw
Quoted 18 lines · Joe Perches
Quoted 17 lines · Alexandre Ghiti

By matching only current line starting with '+', we miss the case when deleting code makes consecutive blank lines appear: this patch then makes it possible to detect this case by also matching current line starting with ' ', which is an already existing blank line.

On the following example, checkpatch --subjective now complains about multiple blank lines:

  static long hugepage_subpool_get_pages(struct hugepage_subpool *spool,
  {
  	long ret = delta;
(quoted diff) +0 -2
-	if (!spool)
-		return ret;
 
  	spin_lock(&spool->lock);
Quoted 7 lines

scripts/checkpatch.pl

Quoted 6 lines
---
  scripts/checkpatch.pl | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0

[]

I do not understand what you mean here, can you clarify for v2 please ?

Thanks !

Quoted 13 lines

scripts/checkpatch.pl sub process { · line 3304

Quoted 9 lines
scripts/checkpatch.pl +1 -1
@@ -3298,7 +3298,7 @@ sub process {
 
  # check for multiple consecutive blank lines
  		if ($prevline =~ /^[\+ ]\s*$/ &&
-		    $line =~ /^\+\s*$/ &&
+		    $line =~ /^[\+ ]\s*$/ &&
  		    $last_blank_line != ($linenr - 1)) {
  			if (CHK("LINE_SPACING",
  				"Please don't use multiple blank lines\n" . $hereprev) &&

I believe this screws up the --fix option just below this if the line does not start with +

Totally, you're right, thanks.

Quoted 2 lines