checkpatch: fix spacing check for return with parentheses
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
@@ -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 · 6 lines
2.27.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 10 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); }
Quoted 7 lines
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.
Looks good. How do you discover these errors?
Are you creating a test suite for checkpatch?
Lukas
Quoted 27 lines
Signed-off-by Dwaipayan Ray <[email protected]>--- scripts/checkpatch.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)scripts/checkpatch.pl +6
-4@@ -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 2 lines
2.27.0
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 16 lines · Lukas Bulwahn
Quoted 14 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.
Quoted 8 lines
Quoted 3 lines
Fix the spacing check. Also add --fix option to
the check.Looks good. How do you discover these errors?
Are you creating a test suite for checkpatch?
Hi,
Actually not really a test suite, I was just randomly testing out these style related checks and it was pure luck that I happened to come across this one :)
Honestly, a proper test suite would be really cool but is it worth the effort given that there are so many warnings in checkpatch?
Thanks,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees