diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 82fd120df0c2..19e8e862c1b9 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -2811,6 +2811,65 @@ sub process { | |||
| 2811 | } | 2811 | } |
| 2812 | } | 2812 | } |
| 2813 | 2813 | ||
| 2814 | # Function pointer declarations | ||
| 2815 | # check spacing between type, funcptr, and args | ||
| 2816 | # canonical declaration is "type (*funcptr)(args...)" | ||
| 2817 | # | ||
| 2818 | # the $Declare variable will capture all spaces after the type | ||
| 2819 | # so check it for trailing missing spaces or multiple spaces | ||
| 2820 | if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)$Ident(\s*)\)(\s*)\(/) { | ||
| 2821 | my $declare = $1; | ||
| 2822 | my $pre_pointer_space = $2; | ||
| 2823 | my $post_pointer_space = $3; | ||
| 2824 | my $funcname = $4; | ||
| 2825 | my $post_funcname_space = $5; | ||
| 2826 | my $pre_args_space = $6; | ||
| 2827 | |||
| 2828 | if ($declare !~ /\s$/) { | ||
| 2829 | WARN("SPACING", | ||
| 2830 | "missing space after return type\n" . $herecurr); | ||
| 2831 | } | ||
| 2832 | |||
| 2833 | # unnecessary space "type (*funcptr)(args...)" | ||
| 2834 | elsif ($declare =~ /\s{2,}$/) { | ||
| 2835 | WARN("SPACING", | ||
| 2836 | "Multiple spaces after return type\n" . $herecurr); | ||
| 2837 | } | ||
| 2838 | |||
| 2839 | # unnecessary space "type ( *funcptr)(args...)" | ||
| 2840 | if (defined $pre_pointer_space && | ||
| 2841 | $pre_pointer_space =~ /^\s/) { | ||
| 2842 | WARN("SPACING", | ||
| 2843 | "Unnecessary space after function pointer open parenthesis\n" . $herecurr); | ||
| 2844 | } | ||
| 2845 | |||
| 2846 | # unnecessary space "type (* funcptr)(args...)" | ||
| 2847 | if (defined $post_pointer_space && | ||
| 2848 | $post_pointer_space =~ /^\s/) { | ||
| 2849 | WARN("SPACING", | ||
| 2850 | "Unnecessary space before function pointer name\n" . $herecurr); | ||
| 2851 | } | ||
| 2852 | |||
| 2853 | # unnecessary space "type (*funcptr )(args...)" | ||
| 2854 | if (defined $post_funcname_space && | ||
| 2855 | $post_funcname_space =~ /^\s/) { | ||
| 2856 | WARN("SPACING", | ||
| 2857 | "Unnecessary space after function pointer name\n" . $herecurr); | ||
| 2858 | } | ||
| 2859 | |||
| 2860 | # unnecessary space "type (*funcptr) (args...)" | ||
| 2861 | if (defined $pre_args_space && | ||
| 2862 | $pre_args_space =~ /^\s/) { | ||
| 2863 | WARN("SPACING", | ||
| 2864 | "Unnecessary space before function pointer arguments\n" . $herecurr); | ||
| 2865 | } | ||
| 2866 | |||
| 2867 | if (show_type("SPACING") && $fix) { | ||
| 2868 | $fixed[$linenr - 1] =~ | ||
| 2869 | s/^(.\s*$Declare)\(\s*\*\s*($Ident)\s*\)\s*\(/rtrim($1) . " " . "\(\*$2\)\("/ex; | ||
| 2870 | } | ||
| 2871 | } | ||
| 2872 | |||
| 2814 | # check for spacing round square brackets; allowed: | 2873 | # check for spacing round square brackets; allowed: |
| 2815 | # 1. with a type on the left -- int [] a; | 2874 | # 1. with a type on the left -- int [] a; |
| 2816 | # 2. at the beginning of a line for slice initialisers -- [0...10] = 5, | 2875 | # 2. at the beginning of a line for slice initialisers -- [0...10] = 5, |
