summaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2018-08-22 00:57:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-22 13:52:48 -0400
commit79682c0c00893c683678d85a402392b75e90311d (patch)
treea876d2f790da19e013a4099751d850ff13431669 /scripts/checkpatch.pl
parentd729593e492e1e4c7cd8a418ee227d0bd4d5f36d (diff)
checkpatch: add --fix for CONCATENATED_STRING and STRING_FRAGMENTS
Add the ability to --fix these string issues. e.g.: printk(KERN_INFO"bar" "baz"QUX); converts to printk(KERN_INFO "barbaz" QUX); Link: http://lkml.kernel.org/r/a9fb505ccfedffc5869d08832a7ff05a21d85621.camel@perches.com 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>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl23
1 files changed, 18 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5cb7cfd08ce2..f2e00dc0ae89 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5330,15 +5330,28 @@ sub process {
5330 } 5330 }
5331 5331
5332# concatenated string without spaces between elements 5332# concatenated string without spaces between elements
5333 if ($line =~ /$String[A-Z_]/ || $line =~ /[A-Za-z0-9_]$String/) { 5333 if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
5334 CHK("CONCATENATED_STRING", 5334 if (CHK("CONCATENATED_STRING",
5335 "Concatenated strings should use spaces between elements\n" . $herecurr); 5335 "Concatenated strings should use spaces between elements\n" . $herecurr) &&
5336 $fix) {
5337 while ($line =~ /($String)/g) {
5338 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
5339 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
5340 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
5341 }
5342 }
5336 } 5343 }
5337 5344
5338# uncoalesced string fragments 5345# uncoalesced string fragments
5339 if ($line =~ /$String\s*"/) { 5346 if ($line =~ /$String\s*"/) {
5340 WARN("STRING_FRAGMENTS", 5347 if (WARN("STRING_FRAGMENTS",
5341 "Consecutive strings are generally better as a single string\n" . $herecurr); 5348 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
5349 $fix) {
5350 while ($line =~ /($String)(?=\s*")/g) {
5351 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
5352 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
5353 }
5354 }
5342 } 5355 }
5343 5356
5344# check for non-standard and hex prefixed decimal printf formats 5357# check for non-standard and hex prefixed decimal printf formats