Skip to content

Commit

Permalink
checkpatch: prefer ftrace over function entry/exit printks
Browse files Browse the repository at this point in the history
Prefer using ftrace over function entry/exit logging messages.

Warn with various function entry/exit only logging that only
use __func__ with or without descriptive decoration.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Joe Perches <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Feb 26, 2021
1 parent ea7dbab commit adb2da8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,30 @@ sub hash_show_words {
Cc:
)};

our $tracing_logging_tags = qr{(?xi:
[=-]*> |
<[=-]* |
\[ |
\] |
start |
called |
entered |
entry |
enter |
in |
inside |
here |
begin |
exit |
end |
done |
leave |
completed |
out |
return |
[\.\!:\s]*
)};

sub edit_distance_min {
my (@arr) = @_;
my $len = scalar @arr;
Expand Down Expand Up @@ -5972,6 +5996,17 @@ sub process {
"Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
}

# check for unnecessary function tracing like uses
# This does not use $logFunctions because there are many instances like
# 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions
if ($rawline =~ /^\+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s*__func__\s*\)\s*;/) {
if (WARN("TRACING_LOGGING",
"Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
$fix) {
fix_delete_line($fixlinenr, $rawline);
}
}

# check for spaces before a quoted newline
if ($rawline =~ /^.*\".*\s\\n/) {
if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
Expand Down

0 comments on commit adb2da8

Please sign in to comment.