checkpatch not warning for some split strings
Subsystems (2)
Joe Perches
maintainerHey Josh.
Back when you added commit ca56dc098ca ("checkpatch: check for quoted strings broken across lines")
You added this test case:
Test case:
void context(void)
{
struct { unsigned magic; const char *strdata; } foo[] = {
{ 42, "these strings"
"do not produce warnings" },
{ 256, "though perhaps"
"they should" },
};which avoids emitting a warning on split strings across multiple lines without a function-call like '(' use on the line above.
Perhaps the "\(" test should be removed as checkpatch doesn't emit a warning for some uses like:
drivers/net/wireless/iwlwifi/mvm/rs.c +0 -0
[]
@@ -1868,7 +1865,8 @@ static void rs_rate_scale_perform(struct iwl_mvm *mvm,
/* Else poor success; go back to mode in "active" table */
} else {
IWL_DEBUG_RATE(mvm,
- "LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
+ "GOING BACK TO THE OLD TABLE: SR %d "
+ "cur-tpt %d old-tpt %d\n",
window->success_ratio,
window->average_tpt,
lq_sta->last_tpt);Quoted 28 lines · Joe Perches
Hey Josh.
Back when you added commit
ca56dc098ca("checkpatch: check for quoted strings broken across lines")You added this test case:
Test case: void context(void) { struct { unsigned magic; const char *strdata; } foo[] = { { 42, "these strings" "do not produce warnings" }, { 256, "though perhaps" "they should" }, };which avoids emitting a warning on split strings across multiple lines without a function-call like '(' use on the line above.
Perhaps the "\(" test should be removed as checkpatch doesn't emit a warning for some uses like:
drivers/net/wireless/iwlwifi/mvm/rs.c +0
-0[]
drivers/net/wireless/iwlwifi/mvm/rs.c static void rs_rate_scale_perform(struct iwl_mvm *mvm, · line 1872
Quoted 9 lines
drivers/net/wireless/iwlwifi/mvm/rs.c +2
-1@@ -1868,7 +1865,8 @@ static void rs_rate_scale_perform(struct iwl_mvm *mvm,/* Else poor success; go back to mode in "active" table */ }else {IWL_DEBUG_RATE (mvm, -"LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n" , +"GOING BACK TO THE OLD TABLE: SR %d " +"cur-tpt %d old-tpt %d\n" , window->success_ratio, window->average_tpt, lq_sta->last_tpt);
That one should definitely emit a warning. However, removing the \( test entirely will introduce warnings on many other strings embedded in data structures; only drop that test if you've diffed the checkpatch output for the kernel with and without it and you're comfortable with the *huge* number of additional warnings it'll introduce.
- Josh Triplett
Joe Perches
maintainerPATCH 1/1 checkpatch: More comprehensive split strings warning
The current checkpatch test for split strings does not find several cases that should be found.
For instance:
drivers/net/wireless/iwlwifi/mvm/rs.c +0 -0
[]
@@ -1868,7 +1865,8 @@ static void rs_rate_scale_perform(struct iwl_mvm *mvm,
/* Else poor success; go back to mode in "active" table */ } else {
IWL_DEBUG_RATE(mvm,
- "LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n", + "GOING BACK TO THE OLD TABLE: SR %d " + "cur-tpt %d old-tpt %d\n",
window->success_ratio, window->average_tpt,
lq_sta->last_tpt);
does not currently emit a warning.
Improve the test to find these cases.
Add more exceptions to reduce false positives for
assembly and octal/hex string constants.
--- scripts/checkpatch.pl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
scripts/checkpatch.pl +4 -8
@@ -2049,16 +2049,12 @@ sub process { } # Check for user-visible strings broken across lines, which breaks the ability -# to grep for the string. Limited to strings used as parameters (those -# following an open parenthesis), which almost completely eliminates false -# positives, as well as warning only once per parameter rather than once per -# line of the string. Make an exception when the previous string ends in a -# newline (multiple lines in one string constant) or \n\t (common in inline -# assembly to indent the instruction on the following line). +# to grep for the string. Make exceptions when the previous string ends in a +# newline (multiple lines in one string constant) or '\t', '\r', ';', or '{' +# (common in inline assembly) or is a octal \123 or hexadecimal \xaf value if ($line =~ /^\+\s*"/ && $prevline =~ /"\s*$/ && - $prevline =~ /\(/ && - $prevrawline !~ /\\n(?:\\t)*"\s*$/) { + $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) { WARN("SPLIT_STRING", "quoted string split across lines\n" . $hereprev); }
Re: [PATCH] checkpatch: More comprehensive split strings warning
Quoted 18 lines · Joe Perches
The current checkpatch test for split strings does not find several cases that should be found.
For instance:
drivers/net/wireless/iwlwifi/mvm/rs.c +0
-0[]
drivers/net/wireless/iwlwifi/mvm/rs.c +2
-1@@ -1868,7 +1865,8 @@ static void rs_rate_scale_perform(struct iwl_mvm *mvm,/* Else poor success; go back to mode in "active" table */ }else {IWL_DEBUG_RATE (mvm, -"LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n" , +"GOING BACK TO THE OLD TABLE: SR %d " +"cur-tpt %d old-tpt %d\n" , window->success_ratio, window->average_tpt, lq_sta->last_tpt);
Quoted 6 lines
does not currently emit a warning.
Improve the test to find these cases.
Add more exceptions to reduce false positives for
assembly and octal/hex string constants.
Nice choice of exceptions; that should work quite well.
Quoted 1 line
Signed-off-by Joe Perches <[email protected]>
Quoted 30 lines
scripts/checkpatch.pl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)scripts/checkpatch.pl +4
-8@@ -2049,16 +2049,12 @@ sub process { } # Check for user-visible strings broken across lines, which breaks the ability -# to grep for the string. Limited to strings used as parameters (those -# following an open parenthesis), which almost completely eliminates false -# positives, as well as warning only once per parameter rather than once per -# line of the string. Make an exception when the previous string ends in a -# newline (multiple lines in one string constant) or \n\t (common in inline -# assembly to indent the instruction on the following line). +# to grep for the string. Make exceptions when the previous string ends in a +# newline (multiple lines in one string constant) or '\t', '\r', ';', or '{' +# (common in inline assembly) or is a octal \123 or hexadecimal \xaf value if ($line =~ /^\+\s*"/ && $prevline =~ /"\s*$/ && - $prevline =~ /\(/ && - $prevrawline !~ /\\n(?:\\t)*"\s*$/) { + $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) { WARN("SPLIT_STRING", "quoted string split across lines\n" . $hereprev); }