There are about 100,000 uses of 'static const <type>' but about 400 uses of 'static <type> const' in the kernel where type is not a pointer. The kernel almost always uses "static const" over "const static" as there is a compiler warning for that declaration style. But there is no compiler warning for "static <type> const". So add a checkpatch warning for the atypical declaration uses of. const static <type> <foo> and static <type> const <foo> For example: $ ./scripts/checkpatch.pl -f --emacs --quiet --nosummary -types=static_const arch/arm/crypto/aes-ce-glue.c arch/arm/crypto/aes-ce-glue.c:75: WARNING: Move const after static - use 'static const u8' #75: FILE: arch/arm/crypto/aes-ce-glue.c:75: + static u8 const rcon[] = {
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -4232,6 +4232,18 @@ sub process { · 4231 unmodified lines | ||
| 4232 | 4232 | } |
| 4233 | 4233 | } |
| 4234 | 4234 | |
| 4235 | +# check for const static or static <non ptr type> const declarations | |
| 4236 | +# prefer 'static const <foo>' over 'const static <foo>' and 'static <foo> const' | |
| 4237 | + if ($sline =~ /^\+\s*const\s+static\s+($Type)\b/ || | |
| 4238 | + $sline =~ /^\+\s*static\s+($BasicType)\s+const\b/) { | |
| 4239 | + if (WARN("STATIC_CONST", | |
| 4240 | + "Move const after static - use 'static const $1'\n" . $herecurr) && | |
| 4241 | + $fix) { | |
| 4242 | + $fixed[$fixlinenr] =~ s/\bconst\s+static\b/static const/; | |
| 4243 | + $fixed[$fixlinenr] =~ s/\bstatic\s+($BasicType)\s+const\b/static const $1/; | |
| 4244 | + } | |
| 4245 | + } | |
| 4246 | + | |
| 4235 | 4247 | # check for non-global char *foo[] = {"bar", ...} declarations. |
| 4236 | 4248 | if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { |
| 4237 | 4249 | WARN("STATIC_CONST_CHAR_ARRAY", |