Commit 86f9d059c6bc548f6337f01117897a4c823cb4ee

Authored by Andy Whitcroft
Committed by Linus Torvalds
1 parent 1e85572697

checkpatch: allow parentheses on return for comparisons

It seems to be a common idiom to include braces on conditionals in all
contexts including return.  Allow this exception to the return is not a
function checks.  Reported by Kay Sievers.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 3 additions and 2 deletions Side-by-side Diff

scripts/checkpatch.pl
... ... @@ -127,6 +127,7 @@
127 127  
128 128 our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*};
129 129 our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
  130 +our $Compare = qr{<=|>=|==|!=|<|>};
130 131 our $Operators = qr{
131 132 <=|>=|==|!=|
132 133 =>|->|<<|>>|<|>|!|~|
133 134  
... ... @@ -1983,9 +1984,9 @@
1983 1984 my $spacing = $1;
1984 1985 my $value = $2;
1985 1986  
1986   - # Flatten any parentheses and braces
  1987 + # Flatten any parentheses
1987 1988 $value =~ s/\)\(/\) \(/g;
1988   - while ($value =~ s/\([^\(\)]*\)/1/) {
  1989 + while ($value !~ /(?:$Ident|-?$Constant)\s*$Compare\s*(?:$Ident|-?$Constant)/ && $value =~ s/\([^\(\)]*\)/1/) {
1989 1990 }
1990 1991  
1991 1992 if ($value =~ /^(?:$Ident|-?$Constant)$/) {