diff mbox

[OPW,kernel] Scripts: checkpatch.pl: Fix incorrect warning in multi-line seq_printf()

Message ID 20131022200003.GA25502@gmail.com
State New, archived
Headers show

Commit Message

Rashika Oct. 22, 2013, 8 p.m. UTC
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.

Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com>
---
 scripts/checkpatch.pl |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

Comments

gregkh@linuxfoundation.org Oct. 28, 2013, 9:21 p.m. UTC | #1
On Wed, Oct 23, 2013 at 01:30:03AM +0530, Rashika Kheria wrote:
> 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.
> 
> Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com>

This looks good to me, care to send it to the "correct" people for this
file?

You can get that by running scripts/get_maintainer.pl:

 $ ./scripts/get_maintainer.pl --file scripts/checkpatch.pl
 Andy Whitcroft <apw@canonical.com> (maintainer:CHECKPATCH)
 Joe Perches <joe@perches.com> (maintainer:CHECKPATCH)
 linux-kernel@vger.kernel.org (open list)

Also feel free to cc: me and the opw-kernel mailing list as well on the
patch.

thanks,

greg k-h
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 66cad50..954568f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;
 			}
 		}