Skip to content

Commit

Permalink
checkpatch: Prefer seq_puts to seq_printf
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Joe Perches authored and Linus Torvalds committed Apr 30, 2013
1 parent 972fdea commit a6962d7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3373,6 +3380,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 &&
Expand Down

0 comments on commit a6962d7

Please sign in to comment.