mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rashika Kheria <rashika.kheria@gmail.com>
To: opw-kernel@googlegroups.com, gregkh@linuxfoundation.org,
	Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] Scripts: checkpatch.pl: Fix incorrect warning in multi-line seq_printf()
Date: Tue, 29 Oct 2013 03:02:42 +0530	[thread overview]
Message-ID: <1382995962-7023-1-git-send-email-rashika.kheria@gmail.com> (raw)

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(-)

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;
 			}
 		}
 
-- 
1.7.9.5


             reply	other threads:[~2013-10-28 21:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-28 21:32 Rashika Kheria [this message]
2013-10-28 21:56 ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1382995962-7023-1-git-send-email-rashika.kheria@gmail.com \
    --to=rashika.kheria@gmail.com \
    --cc=apw@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=opw-kernel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®