Skip to content

Commit a6962d7

Browse files
JoePerchestorvalds
authored andcommitted
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 <[email protected]> Suggested-by: Bjorn Helgaas <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 972fdea commit a6962d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

scripts/checkpatch.pl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,13 @@ sub sanitise_line {
628628
return $res;
629629
}
630630

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+
631638
sub ctx_statement_block {
632639
my ($linenr, $remain, $off) = @_;
633640
my $line = $linenr - 1;
@@ -3373,6 +3380,15 @@ sub process {
33733380
"struct spinlock should be spinlock_t\n" . $herecurr);
33743381
}
33753382

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+
33763392
# Check for misused memsets
33773393
if ($^V && $^V ge 5.10.0 &&
33783394
defined $stat &&

0 commit comments

Comments
 (0)