]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
checkpatch: Prefer seq_puts to seq_printf
authorJoe Perches <joe@perches.com>
Wed, 20 Mar 2013 04:07:46 +0000 (15:07 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Mar 2013 04:23:01 +0000 (15:23 +1100)
Add a check for seq_printf use with a constant format without additional
arguments.  Suggest seq_puts instead.

Signed-off-by: Joe Perches <joe@perches.com>
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
scripts/checkpatch.pl

index 7ef2b4bd0145a7c463bc3732e7909eb8cbe326a7..3540bcf1cd22b3692c3f0b567da32b7f230702c7 100755 (executable)
@@ -628,6 +628,13 @@ sub sanitise_line {
        return $res;
 }
 
+sub get_quoted_string {
+       my ($line, $rawline) = @_;
+
+       return "" if ($line !~ m/(\"[X]+\")/g);
+       return substr($rawline, $-[0], $+[0] - $-[0]);
+}
+
 sub ctx_statement_block {
        my ($linenr, $remain, $off) = @_;
        my $line = $linenr - 1;
@@ -3372,6 +3379,15 @@ sub process {
                             "struct spinlock should be spinlock_t\n" . $herecurr);
                }
 
+# check for seq_printf uses that could be seq_puts
+               if ($line =~ /\bseq_printf\s*\(/) {
+                       my $fmt = get_quoted_string($line, $rawline);
+                       if ($fmt !~ /[^\\]\%/) {
+                               WARN("PREFER_SEQ_PUTS",
+                                    "Prefer seq_puts to seq_printf\n" . $herecurr);
+                       }
+               }
+
 # Check for misused memsets
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&