Skip to content

Commit

Permalink
checkpatch: warn when missing newline in return sysfs_emit() formats
Browse files Browse the repository at this point in the history
return sysfs_emit() uses should include a newline.

Suggest adding a newline when one is missing.
Add one using --fix too.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed May 7, 2021
1 parent e13d04e commit fbe7454
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7198,6 +7198,17 @@ sub process {
"Using $1 should generally have parentheses around the comparison\n" . $herecurr);
}

# return sysfs_emit(foo, fmt, ...) fmt without newline
if ($line =~ /\breturn\s+sysfs_emit\s*\(\s*$FuncArg\s*,\s*($String)/ &&
substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) {
my $offset = $+[6] - 1;
if (WARN("SYSFS_EMIT",
"return sysfs_emit(...) formats should include a terminating newline\n" . $herecurr) &&
$fix) {
substr($fixed[$fixlinenr], $offset, 0) = '\\n';
}
}

# nested likely/unlikely calls
if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
WARN("LIKELY_MISUSE",
Expand Down

0 comments on commit fbe7454

Please sign in to comment.