Skip to content

Commit

Permalink
scripts/checkpatch.pl: add warnings for static char that could be sta…
Browse files Browse the repository at this point in the history
…tic const char

Add warnings for possible missing const uses of
	static char foo[] = "bar"
    that could be
	static const char foo[] = "bar"
and
	static const char *foo[] = {"bar", "baz"}
    that could be
	static const char * const foo[] = {"bar", "baz"}

Signed-off-by: Joe Perches <joe@perches.com>
Cc: Mike Frysinger <vapier.adi@gmail.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Joe Perches authored and Linus Torvalds committed Oct 26, 2010
1 parent 267ad8f commit cb710ec
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,18 @@ sub process {
$herecurr);
}

# check for static const char * arrays.
if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
WARN("static const char * array should probably be static const char * const\n" .
$herecurr);
}

# check for static char foo[] = "bar" declarations.
if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
WARN("static char array declaration should probably be static const char\n" .
$herecurr);
}

# check for new typedefs, only function parameters and sparse annotations
# make sense.
if ($line =~ /\btypedef\s/ &&
Expand Down

0 comments on commit cb710ec

Please sign in to comment.