Scripts: checkpatch.pl: Fix incorrect warning in multi-line seq_printf()
PATCH 1/1 Scripts: checkpatch.pl: Fix incorrect warning in multi-line seq_printf()
This patch fixes the following incorrect warning given by checkpatch.pl in case of multi-line seq_printf() statements-
"WARNING: Prefer seq_puts to seq_printf"
The previous code block producing the above warning was evaluating on line by line basis and hence was printing a warning if the format specifier was absent in the first line.
In this patch, we maintain a state flag $is_seq_printf_block indicating that the same seq_printf() statement is continuing in the next line and throw a warning if no format specifier is found in any of the lines as indicated by flag $has_format_specifier.
--- scripts/checkpatch.pl | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
scripts/checkpatch.pl +18 -6
@@ -13,6 +13,9 @@ $P =~ s@.*/@@g; my $V = '0.32'; +my $is_seq_printf_block = 0; +my $has_format_specifier = 0; + use Getopt::Long qw(:config no_auto_abbrev); my $quiet = 0;
@@ -3903,14 +3906,23 @@ sub string_find_replace { } # check for seq_printf uses that could be seq_puts - if ($line =~ /\bseq_printf\s*\(/) { + if ($line =~ /\bseq_printf\s*\(/ || $is_seq_printf_block) { my $fmt = get_quoted_string($line, $rawline); - if ($fmt !~ /[^\\]\%/) { - if (WARN("PREFER_SEQ_PUTS", - "Prefer seq_puts to seq_printf\n" . $herecurr) && - $fix) { - $fixed[$linenr - 1] =~ s/\bseq_printf\b/seq_puts/; + if ($fmt =~ /[^\\]\%/) { + $has_format_specifier = 1; + } + if ($line =~ m/\;$/) { + $is_seq_printf_block = 0; + if ($has_format_specifier == 0) { + if (WARN("PREFER_SEQ_PUTS", + "Prefer seq_puts to seq_printf\n" . $herecurr) && + $fix) { + $fixed[$linenr - 1] =~ s/\bseq_printf\b/seq_puts/; + } } + $has_format_specifier = 0; + } else { + $is_seq_printf_block = 1; } }
Signature · 1 line
1.7.9.5
Joe Perches
maintainerQuoted 2 lines · Rashika Kheria
This patch fixes the following incorrect warning given by checkpatch.pl in case of multi-line
seq_printf()statements-
I believe this is already fixed in -next
Quoted 1 line
From
7f1b7c2810888bba02311ec75b19e0cbd598ef83Mon Sep 17 00:00:00 2001
From: Joe Perches <[email protected]>
Date: Fri, 27 Sep 2013 10:14:51 +1000
Subject: [PATCH] checkpatch: update seq_<foo> tests
seq_vprintf, seq_printf and seq_puts are logging functions and should be allowed to exceed the maximium line length.
Add maximum line length exceptions for these functions.
Also, suggesting seq_printf conversions to seq_puts should be tested for arguments after the format.
--- scripts/checkpatch.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +4 -3
@@ -323,7 +323,8 @@ our $logFunctions = qr{(?x: (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| WARN(?:_RATELIMIT|_ONCE|)| panic| - MODULE_[A-Z_]+ + MODULE_[A-Z_]+| + seq_vprintf|seq_printf|seq_puts )}; our $signature_tags = qr{(?xi:
@@ -3909,9 +3910,9 @@ sub string_find_replace { } # check for seq_printf uses that could be seq_puts - if ($line =~ /\bseq_printf\s*\(/) { + if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) { my $fmt = get_quoted_string($line, $rawline); - if ($fmt !~ /[^\\]\%/) { + if ($fmt ne "" && $fmt !~ /[^\\]\%/) { if (WARN("PREFER_SEQ_PUTS", "Prefer seq_puts to seq_printf\n" . $herecurr) && $fix) {