diff options
author | Joe Perches <joe@perches.com> | 2013-04-29 19:18:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-29 21:28:19 -0400 |
commit | a6962d7273d8f89c136fe9ea3d61d7f47adcd823 (patch) | |
tree | 67d260393e057398039f81acf41c4d35d7c6a01f /scripts/checkpatch.pl | |
parent | 972fdea2e6ece7578915d386a5447bc78d3fb8b8 (diff) |
checkpatch: Prefer seq_puts to seq_printf
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>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index a820249a3fce..b8b03aa52beb 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -628,6 +628,13 @@ sub sanitise_line { | |||
628 | return $res; | 628 | return $res; |
629 | } | 629 | } |
630 | 630 | ||
631 | sub get_quoted_string { | ||
632 | my ($line, $rawline) = @_; | ||
633 | |||
634 | return "" if ($line !~ m/(\"[X]+\")/g); | ||
635 | return substr($rawline, $-[0], $+[0] - $-[0]); | ||
636 | } | ||
637 | |||
631 | sub ctx_statement_block { | 638 | sub ctx_statement_block { |
632 | my ($linenr, $remain, $off) = @_; | 639 | my ($linenr, $remain, $off) = @_; |
633 | my $line = $linenr - 1; | 640 | my $line = $linenr - 1; |
@@ -3373,6 +3380,15 @@ sub process { | |||
3373 | "struct spinlock should be spinlock_t\n" . $herecurr); | 3380 | "struct spinlock should be spinlock_t\n" . $herecurr); |
3374 | } | 3381 | } |
3375 | 3382 | ||
3383 | # check for seq_printf uses that could be seq_puts | ||
3384 | if ($line =~ /\bseq_printf\s*\(/) { | ||
3385 | my $fmt = get_quoted_string($line, $rawline); | ||
3386 | if ($fmt !~ /[^\\]\%/) { | ||
3387 | WARN("PREFER_SEQ_PUTS", | ||
3388 | "Prefer seq_puts to seq_printf\n" . $herecurr); | ||
3389 | } | ||
3390 | } | ||
3391 | |||
3376 | # Check for misused memsets | 3392 | # Check for misused memsets |
3377 | if ($^V && $^V ge 5.10.0 && | 3393 | if ($^V && $^V ge 5.10.0 && |
3378 | defined $stat && | 3394 | defined $stat && |