Skip to contentSkip to conversation

checkpatch: enhance check for seq_printf uses that could be seq_puts

PATCH Superseded Heba Aamer 2 participants 2 messages Jan 31, 2015 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Heba Aamer

author
#0 lore raw

PATCH 1/1 checkpatch: enhance check for seq_printf uses that could be seq_puts

This patch enhances the check for seq_printf uses that could be seq_puts.

It was considering the escape of % is \%, but it is %%. This led to skipping some valid cases related to that warning.

---
 scripts/checkpatch.pl |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
scripts/checkpatch.pl +8 -5
index f0bb6d6..0b125ca 100755
@@ -4804,11 +4804,14 @@ sub process {
 # check for seq_printf uses that could be seq_puts
 		if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
 			my $fmt = get_quoted_string($line, $rawline);
-			if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
-				if (WARN("PREFER_SEQ_PUTS",
-					 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
-				    $fix) {
-					$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
+			if ($fmt ne "") {
+				$fmt =~ s/%%//g;
+				if ($fmt !~ /%/) {
+					if (WARN("PREFER_SEQ_PUTS",
+						 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
+					}
 				}
 			}
 		}
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 5 lines · Heba Aamer

This patch enhances the check for seq_printf uses that could be seq_puts.

It was considering the escape of % is \%, but it is %%. This led to skipping some valid cases related to that warning.

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 10 lines
scripts/checkpatch.pl +1 -5
@@ -4804,11 +4804,14 @@ sub process {
 # check for seq_printf uses that could be seq_puts
 		if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
 			my $fmt = get_quoted_string($line, $rawline);
-			if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
-				if (WARN("PREFER_SEQ_PUTS",
-					 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
-				    $fix) {
-					$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
+			if ($fmt ne "") {

scripts/checkpatch.pl sub process { · line 4817

Quoted 10 lines
scripts/checkpatch.pl +7 -0
+				$fmt =~ s/%%//g;
+				if ($fmt !~ /%/) {
+					if (WARN("PREFER_SEQ_PUTS",
+						 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
+					}
 				}
 			}
 		}

Probably be simpler to use:

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index 059c032..7f1804e 100755
@@ -4854,7 +4854,8 @@ sub process {
 # check for seq_printf uses that could be seq_puts
 		if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
 			my $fmt = get_quoted_string($line, $rawline);
-			if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
+			$fmt =~ s/%%//g;
+			if ($fmt !~ /%/) {
 				if (WARN("PREFER_SEQ_PUTS",
 					 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
 				    $fix) {