Skip to contentSkip to conversation

checkpatch: fix spacing check for return with parentheses

PATCH In review Dwaipayan Ray 1 participant 2 messages Nov 17, 2020 – Nov 18, 2020 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: fix spacing check for return with parentheses

The spacing check is unreachable for return statements followed by an opening parentheses.
For example:

int foo(int bar, int baz)

{
	return(bar+baz);
}

There should be an error emitted for a space between return and the opening parentheses but checkpatch doesn't emit one.

Fix the spacing check. Also add --fix option to
the check.

---
 scripts/checkpatch.pl | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +6 -3
index 8da6cde20c68..07feeb3321e2 100755
@@ -5176,10 +5176,13 @@ sub process {
 				if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
 					ERROR("RETURN_PARENTHESES",
 					      "return is not a function, parentheses are not required\n" . $herecurr);
+				} elsif ($spacing !~ /\s+/) {
+					if (ERROR("SPACING",
+						  "space required before the open parenthesis '('\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/\breturn\s*\(/return \(/;
+					}
 				}
-			} elsif ($spacing !~ /\s+/) {
-				ERROR("SPACING",
-				      "space required before the open parenthesis '('\n" . $herecurr);
 			}
 		}
 
Signature · 1 line
2.27.0
#1 lore raw
Quoted 44 lines · Dwaipayan Ray

The spacing check is unreachable for return statements followed by an opening parentheses.
For example:

int foo(int bar, int baz)

{
        return(bar+baz);
}

There should be an error emitted for a space between return and the opening parentheses but checkpatch doesn't emit one.

Fix the spacing check. Also add --fix option to
the check.

---
 scripts/checkpatch.pl | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +6 -4
index 8da6cde20c68..07feeb3321e2 100755
@@ -5176,10 +5176,13 @@ sub process {
                                if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
                                        ERROR("RETURN_PARENTHESES",
                                              "return is not a function, parentheses are not required\n" . $herecurr);
+                               } elsif ($spacing !~ /\s+/) {
+                                       if (ERROR("SPACING",
+                                                 "space required before the open parenthesis '('\n" . $herecurr) &&
+                                           $fix) {
+                                               $fixed[$fixlinenr] =~ s/\breturn\s*\(/return \(/;
+                                       }
                                }
-                       } elsif ($spacing !~ /\s+/) {
-                               ERROR("SPACING",
-                                     "space required before the open parenthesis '('\n" . $herecurr);
                        }
                }
 
--
Quoted 1 line

2.27.0

Sorry for the ping Joe. Just wanted to know if this got missed.

Thanks,
Dwaipayan.