Skip to content

Commit

Permalink
checkpatch: warn if trace_printk and friends are called
Browse files Browse the repository at this point in the history
trace_printk is meant as a debugging tool, and should not be compiled into
production code without specific debug Kconfig options enabled, or source
code changes, as indicated by the warning that shows up on boot if any
trace_printk is called:

 **   NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE   **
 **                                                      **
 ** trace_printk() being used. Allocating extra memory.  **
 **                                                      **
 ** This means that this is a DEBUG kernel and it is     **
 ** unsafe for production use.                           **

Let's warn developers when they try to submit such a change.

Signed-off-by: Nicolas Boichat <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Joe Perches <[email protected]>
Link: https://lkml.kernel.org/r/20200825193600.v2.1.I723c43c155f02f726c97501be77984f1e6bb740a@changeid
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
drinkcat authored and torvalds committed Oct 16, 2020
1 parent ed4761f commit 8020b25
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4274,6 +4274,12 @@ sub process {
"Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
}

# trace_printk should not be used in production code.
if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) {
WARN("TRACE_PRINTK",
"Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr);
}

# ENOSYS means "bad syscall nr" and nothing else. This will have a small
# number of false positives, but assembly files are not checked, so at
# least the arch entry code will not trigger this warning.
Expand Down

0 comments on commit 8020b25

Please sign in to comment.