checkpatch: add tests for function pointer style misuses
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> Cc: Andy Whitcroft <apw@shadowen.org> Cc: Derek Perrin <d.roc16@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
3e2232f2d0
Коммит
31070b5d44
|
@ -2811,6 +2811,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 trailing missing spaces or 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);
|
||||
}
|
||||
|
||||
# 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 arguments\n" . $herecurr);
|
||||
}
|
||||
|
||||
if (show_type("SPACING") && $fix) {
|
||||
$fixed[$linenr - 1] =~
|
||||
s/^(.\s*$Declare)\(\s*\*\s*($Ident)\s*\)\s*\(/rtrim($1) . " " . "\(\*$2\)\("/ex;
|
||||
}
|
||||
}
|
||||
|
||||
# check for spacing round square brackets; allowed:
|
||||
# 1. with a type on the left -- int [] a;
|
||||
# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
|
||||
|
|
Загрузка…
Ссылка в новой задаче