Skip to content

Commit 79682c0

Browse files
JoePerchestorvalds
authored andcommitted
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/[email protected] Signed-off-by: Joe Perches <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d729593 commit 79682c0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

scripts/checkpatch.pl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,15 +5330,28 @@ sub process {
53305330
}
53315331

53325332
# concatenated string without spaces between elements
5333-
if ($line =~ /$String[A-Z_]/ || $line =~ /[A-Za-z0-9_]$String/) {
5334-
CHK("CONCATENATED_STRING",
5335-
"Concatenated strings should use spaces between elements\n" . $herecurr);
5333+
if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
5334+
if (CHK("CONCATENATED_STRING",
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+
}
53365343
}
53375344

53385345
# uncoalesced string fragments
53395346
if ($line =~ /$String\s*"/) {
5340-
WARN("STRING_FRAGMENTS",
5341-
"Consecutive strings are generally better as a single string\n" . $herecurr);
5347+
if (WARN("STRING_FRAGMENTS",
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+
}
53425355
}
53435356

53445357
# check for non-standard and hex prefixed decimal printf formats

0 commit comments

Comments
 (0)