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] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 05 Nov 2014 14:12:55 -0500
From:	Peter Hurley <peter@...leysoftware.com>
To:	Joe Perches <joe@...ches.com>,
	Andrew Morton <akpm@...ux-foundation.org>
CC:	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] checkpatch: Add --strict test for function pointer calling
 style

On 11/05/2014 01:41 PM, Joe Perches wrote:
> Peter Hurley wrote:
> 
> The use of older function ptr calling style, (*fn)(), makes static
> analysis more error-prone; replace with modern fn() style.
> 
> So make checkpatch emit a --strict test for that condition.
> 
> Update the unnecessary parentheses test for dereferencing
> objects at the same time and create a $fix mechanism too.

Cool.

perl's not my thing; how does it know not to trip up on

	initcall_t *call;

	(*call)();

[which I verified it properly does not flag in drivers/tty/tty_io.c]

Regards,
Peter Hurley


> Signed-off-by: Joe Perches <joe@...ches.com>
> ---
>  scripts/checkpatch.pl | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 24d6702..552e5dd 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3838,9 +3838,27 @@ sub process {
>  # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
>  
>  		while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
> -			CHK("UNNECESSARY_PARENTHESES",
> -			    "Unnecessary parentheses around $1\n" . $herecurr);
> -		    }
> +			my $var = $1;
> +			if (CHK("UNNECESSARY_PARENTHESES",
> +				"Unnecessary parentheses around $var\n" . $herecurr) &&
> +			    $fix) {
> +				$fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
> +			}
> +		}
> +
> +# check for unnecessary parentheses around function pointer uses
> +# ie: (foo->bar)(); should be foo->bar();
> +# but not "if (foo->bar) (" to avoid some false positives
> +		if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
> +			my $var = $2;
> +			if (CHK("UNNECESSARY_PARENTHESES",
> +				"Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
> +			    $fix) {
> +				my $var2 = deparenthesize($var);
> +				$var2 =~ s/\s//g;
> +				$fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
> +			}
> +		}
>  
>  #goto labels aren't indented, allow a single space however
>  		if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
> 
> 

--
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