forked from Minki/linux
checkpatch: don't warn on some function pointer return styles
Checks for some function pointer return styles are too strict. Fix them. Multiple spaces after function pointer return types are allowed. int (*foo)(int bar) Spaces after function pointer returns of pointer types are not required. int *(*foo)(int bar) Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
43c1d77c39
commit
91f72e9c6e
@ -2848,10 +2848,7 @@ sub process {
|
|||||||
# Function pointer declarations
|
# Function pointer declarations
|
||||||
# check spacing between type, funcptr, and args
|
# check spacing between type, funcptr, and args
|
||||||
# canonical declaration is "type (*funcptr)(args...)"
|
# canonical declaration is "type (*funcptr)(args...)"
|
||||||
#
|
if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
|
||||||
# the $Declare variable will capture all spaces after the type
|
|
||||||
# so check it for trailing missing spaces or multiple spaces
|
|
||||||
if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)$Ident(\s*)\)(\s*)\(/) {
|
|
||||||
my $declare = $1;
|
my $declare = $1;
|
||||||
my $pre_pointer_space = $2;
|
my $pre_pointer_space = $2;
|
||||||
my $post_pointer_space = $3;
|
my $post_pointer_space = $3;
|
||||||
@ -2859,16 +2856,30 @@ sub process {
|
|||||||
my $post_funcname_space = $5;
|
my $post_funcname_space = $5;
|
||||||
my $pre_args_space = $6;
|
my $pre_args_space = $6;
|
||||||
|
|
||||||
if ($declare !~ /\s$/) {
|
# the $Declare variable will capture all spaces after the type
|
||||||
|
# so check it for a missing trailing missing space but pointer return types
|
||||||
|
# don't need a space so don't warn for those.
|
||||||
|
my $post_declare_space = "";
|
||||||
|
if ($declare =~ /(\s+)$/) {
|
||||||
|
$post_declare_space = $1;
|
||||||
|
$declare = rtrim($declare);
|
||||||
|
}
|
||||||
|
if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
|
||||||
WARN("SPACING",
|
WARN("SPACING",
|
||||||
"missing space after return type\n" . $herecurr);
|
"missing space after return type\n" . $herecurr);
|
||||||
|
$post_declare_space = " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
# unnecessary space "type (*funcptr)(args...)"
|
# unnecessary space "type (*funcptr)(args...)"
|
||||||
elsif ($declare =~ /\s{2,}$/) {
|
# This test is not currently implemented because these declarations are
|
||||||
WARN("SPACING",
|
# equivalent to
|
||||||
"Multiple spaces after return type\n" . $herecurr);
|
# int foo(int bar, ...)
|
||||||
}
|
# and this is form shouldn't/doesn't generate a checkpatch warning.
|
||||||
|
#
|
||||||
|
# elsif ($declare =~ /\s{2,}$/) {
|
||||||
|
# WARN("SPACING",
|
||||||
|
# "Multiple spaces after return type\n" . $herecurr);
|
||||||
|
# }
|
||||||
|
|
||||||
# unnecessary space "type ( *funcptr)(args...)"
|
# unnecessary space "type ( *funcptr)(args...)"
|
||||||
if (defined $pre_pointer_space &&
|
if (defined $pre_pointer_space &&
|
||||||
@ -2900,7 +2911,7 @@ sub process {
|
|||||||
|
|
||||||
if (show_type("SPACING") && $fix) {
|
if (show_type("SPACING") && $fix) {
|
||||||
$fixed[$linenr - 1] =~
|
$fixed[$linenr - 1] =~
|
||||||
s/^(.\s*$Declare)\(\s*\*\s*($Ident)\s*\)\s*\(/rtrim($1) . " " . "\(\*$2\)\("/ex;
|
s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user