checkpatch: add test for consecutive string fragments
authorJoe Perches <joe@perches.com>
Wed, 10 Dec 2014 23:51:59 +0000 (15:51 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Dec 2014 01:41:12 +0000 (17:41 -0800)
Emit a warning when single line string coalescing occurs.

Code that uses compiler string concatenation on a single line like:

    printk("foo" "bar");

is generally better to read concatenated like:

    printk("foobar");

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index d06b6be2841e29c86e3510a262a594c993d5a674..5e63dce2e4281c0afc8c9e34db570bf731b2c020 100755 (executable)
@@ -4464,6 +4464,12 @@ sub process {
                            "Concatenated strings should use spaces between elements\n" . $herecurr);
                }
 
+# uncoalesced string fragments
+               if ($line =~ /"X*"\s*"/) {
+                       WARN("STRING_FRAGMENTS",
+                            "Consecutive strings are generally better as a single string\n" . $herecurr);
+               }
+
 # warn about #if 0
                if ($line =~ /^.\s*\#\s*if\s+0\b/) {
                        CHK("REDUNDANT_CODE",