public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Mike Frysinger <vapier.adi@gmail.com>,
	Andy Whitcroft <apw@canonical.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] scripts/checkpatch.pl: Add warnings for static char that could be static const char
Date: Thu, 09 Sep 2010 12:21:46 -0700	[thread overview]
Message-ID: <1284060106.24986.215.camel@Joe-Laptop> (raw)
In-Reply-To: <AANLkTimAuA1oYyoaKsFTPEifdDsz9h=EzTB8gKudyAJk@mail.gmail.com>

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>
---
 scripts/checkpatch.pl |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2039acd..8df382b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1806,6 +1806,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/ &&



  parent reply	other threads:[~2010-09-09 19:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-09 18:22 [rfc patch] treewide: Convert "static const char <*> foo[] =" to "static const char <*> const foo[] =" Joe Perches
2010-09-09 18:29 ` Mike Frysinger
2010-09-09 18:48   ` Joe Perches
2010-09-09 19:16     ` Mike Frysinger
2010-09-09 19:33       ` Joe Perches
2010-09-09 19:40         ` Mike Frysinger
2010-09-09 19:48           ` Joe Perches
2010-09-09 19:50             ` Mike Frysinger
2010-09-09 20:05               ` Joe Perches
     [not found]                 ` <SNT104-W3438BE3FC4EAC0A537D57EBA900@phx.gbl>
2011-04-19 13:59                   ` Joe Perches
2010-09-09 19:21   ` Joe Perches [this message]
2010-09-09 19:24     ` [PATCH] scripts/checkpatch.pl: Add warnings for static char that could be static const char Mike Frysinger
2010-09-10  9:06       ` Andy Whitcroft
2010-09-10  9:30         ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284060106.24986.215.camel@Joe-Laptop \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vapier.adi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox