lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20140227224401.GA30335@cloud>
Date:	Thu, 27 Feb 2014 14:44:01 -0800
From:	josh@...htriplett.org
To:	Joe Perches <joe@...ches.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	Julia Lawall <julia.lawall@...6.fr>,
	Monam Agarwal <monamagarwal123@...il.com>,
	opw-kernel@...glegroups.com, Greg KH <gregkh@...uxfoundation.org>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [OPW kernel] [PATCH] checkpatch: Make "return is not a
 function" test quieter

On Thu, Feb 27, 2014 at 11:27:10AM -0800, Joe Perches wrote:
> This test is a bit noisy and opinions seem to agree that
> it should not warn in a lot more situations.
> 
> It seems people agree that:
> 
> 	return (foo || bar);
> and
> 	return foo || bar;
> 
> are both acceptable style and checkpatch should be silent
> about them.
> 
> For now, it warns on parentheses around a simple constant
> or a single function or a ternary.
> 
> 	return (foo);
> 	return (foo(bar));
> 	return (foo ? bar : baz);
> 
> The last ternary test may be quieted in the future.
> 
> Modify the deparenthesize function to only strip balanced
> leading and trailing parentheses.
> 
> Signed-off-by: Joe Perches <joe@...ches.com>

I'd suggest dropping the warning for parenthesized ternaries as well,
but in any case:

Reviewed-by: Josh Triplett <josh@...htriplett.org>

>  scripts/checkpatch.pl | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 91308be..be4be81 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -439,9 +439,14 @@ our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
>  sub deparenthesize {
>  	my ($string) = @_;
>  	return "" if (!defined($string));
> -	$string =~ s@^\s*\(\s*@@g;
> -	$string =~ s@\s*\)\s*$@@g;
> +
> +	while ($string =~ /^\s*\(.*\)\s*$/) {
> +		$string =~ s@^\s*\(\s*@@;
> +		$string =~ s@\s*\)\s*$@@;
> +	}
> +
>  	$string =~ s@\s+@ @g;
> +
>  	return $string;
>  }
>  
> @@ -3362,14 +3367,17 @@ sub process {
>  			}
>  		}
>  
> -# Return is not a function.
> +# return is not a function
>  		if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
>  			my $spacing = $1;
>  			if ($^V && $^V ge 5.10.0 &&
> -			    $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
> -				ERROR("RETURN_PARENTHESES",
> -				      "return is not a function, parentheses are not required\n" . $herecurr);
> -
> +			    $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
> +				my $value = $1;
> +				$value = deparenthesize($value);
> +				if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
> +					ERROR("RETURN_PARENTHESES",
> +					      "return is not a function, parentheses are not required\n" . $herecurr);
> +				}
>  			} elsif ($spacing !~ /\s+/) {
>  				ERROR("SPACING",
>  				      "space required before the open parenthesis '('\n" . $herecurr);
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups "opw-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to opw-kernel+unsubscribe@...glegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ