From: Josh Triplett <josh@joshtriplett.org>
To: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Manfred Spraul <manfred@colorfullife.com>,
Andy Whitcroft <apw@canonical.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] checkpatch: Add tests for function pointer style misuses
Date: Thu, 26 Dec 2013 12:07:23 -0800 [thread overview]
Message-ID: <20131226200723.GA7267@leaf> (raw)
In-Reply-To: <4c5453ce99c368d91032e2a6614fe270fa94d122.1388085015.git.joe@perches.com>
On Thu, Dec 26, 2013 at 11:20:28AM -0800, Joe Perches wrote:
> Kernel style uses function pointers in this form:
> "type (*funcptr)(args...)"
>
> Emit warnings when this function pointer form isn't used.
>
> Signed-off-by: Joe Perches <joe@perches.com>
Two comments below.
> scripts/checkpatch.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 59 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 0fcbc5f..f5d4560 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2810,6 +2810,65 @@ sub process {
> }
> }
>
> +# Function pointer declarations
> +# check spacing between type, funcptr, and args
> +# canonical declaration is "type (*funcptr)(args...)"
> +#
> +# the $Declare variable will capture all spaces after the type
> +# so check it for multiple spaces
> + if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)$Ident(\s*)\)(\s*)\(/) {
> + my $declare = $1;
> + my $pre_pointer_space = $2;
> + my $post_pointer_space = $3;
> + my $funcname = $4;
> + my $post_funcname_space = $5;
> + my $pre_args_space = $6;
> +
> + if ($declare !~ /\s$/) {
> + WARN("SPACING",
> + "missing space after return type\n" . $herecurr);
> + }
> +
> +# unnecessary space "type (*funcptr)(args...)"
> + elsif ($declare =~ /\s{2,}$/) {
> + WARN("SPACING",
> + "Multiple spaces after return type\n" . $herecurr);
> + }
> +
> +# unnecessary space "type ( *funcptr)(args...)"
> + if (defined $pre_pointer_space &&
> + $pre_pointer_space =~ /^\s/) {
> + WARN("SPACING",
> + "Unnecessary space after function pointer open parenthesis\n" . $herecurr);
There are two parentheticals in a proper function pointer declaration,
so this is slightly ambiguous. Perhaps "between open parenthesis and
'*' in function pointer declaration"?
> +# unnecessary space "type (* funcptr)(args...)"
> + if (defined $post_pointer_space &&
> + $post_pointer_space =~ /^\s/) {
> + WARN("SPACING",
> + "Unnecessary space before function pointer name\n" . $herecurr);
> + }
> +
> +# unnecessary space "type (*funcptr )(args...)"
> + if (defined $post_funcname_space &&
> + $post_funcname_space =~ /^\s/) {
> + WARN("SPACING",
> + "Unnecessary space after function pointer name\n" . $herecurr);
> + }
> +
> +# unnecessary space "type (*funcptr) (args...)"
> + if (defined $pre_args_space &&
> + $pre_args_space =~ /^\s/) {
> + WARN("SPACING",
> + "Unnecessary space before function pointer name\n" . $herecurr);
Copy/paste problem here? I think this should be "Unnecessary space
before function pointer argument types" or similar.
With both of the above two issues fixed:
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
next prev parent reply other threads:[~2013-12-26 20:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-26 19:20 [PATCH 0/5] checkpatch: A few corrections and updates Joe Perches
2013-12-26 19:20 ` [PATCH 1/5] checkpatch: Add tests for function pointer style misuses Joe Perches
2013-12-26 20:07 ` Josh Triplett [this message]
2013-12-27 0:58 ` Josh Triplett
2013-12-27 1:25 ` Joe Perches
2013-12-26 19:20 ` [PATCH 2/5] checkpatch: Add a --fix-inplace option Joe Perches
2013-12-26 20:08 ` Josh Triplett
2013-12-26 19:20 ` [PATCH 3/5] checkpatch: Improve space before tab --fix option Joe Perches
2013-12-26 19:20 ` [PATCH 4/5] checkpatch: check for if's with unnecessary parentheses Joe Perches
2013-12-26 20:09 ` Josh Triplett
2013-12-26 19:20 ` [PATCH 5/5] checkpatch: Update the FSF/GPL address check Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131226200723.GA7267@leaf \
--to=josh@joshtriplett.org \
--cc=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox