checkpatch: warn on const char foo[] = "bar"; declarations
These declarations should generally be static const to avoid poor compilation and runtime performance where compilers tend to initialize the const declaration for every call instead of using .rodata for the string. Miscellanea: - Convert spaces to tabs for indentation in 2 adjacent checks Link: http://lkml.kernel.org/r/10ea5f4b087dc911e41e187a4a2b5e79c7529aa3.camel@perches.com Signed-off-by: Joe Perches <joe@perches.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
05391772a7
commit
77b8c0a8e4
|
@ -3892,6 +3892,15 @@ sub process {
|
|||
$herecurr);
|
||||
}
|
||||
|
||||
# check for initialized const char arrays that should be static const
|
||||
if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
|
||||
if (WARN("STATIC_CONST_CHAR_ARRAY",
|
||||
"const array should probably be static const\n" . $herecurr) &&
|
||||
$fix) {
|
||||
$fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
|
||||
}
|
||||
}
|
||||
|
||||
# check for static char foo[] = "bar" declarations.
|
||||
if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
|
||||
WARN("STATIC_CONST_CHAR_ARRAY",
|
||||
|
|
Loading…
Reference in New Issue