[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200825193600.v2.1.I723c43c155f02f726c97501be77984f1e6bb740a@changeid>
Date: Tue, 25 Aug 2020 19:36:06 +0800
From: Nicolas Boichat <drinkcat@...omium.org>
To: Andy Whitcroft <apw@...onical.com>, Joe Perches <joe@...ches.com>
Cc: Steven Rostedt <rostedt@...dmis.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Nicolas Boichat <drinkcat@...omium.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] checkpatch: Warn if trace_printk and friends are called
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 <drinkcat@...omium.org>
---
See also extensive discussion under this thread:
https://lkml.org/lkml/2020/8/20/244
This seems to be the simplest way to try to reduce the number
of trace_printk that make it into the kernel.
Changes in v2:
- Use $1 directly, fix wording, remove final period.
scripts/checkpatch.pl | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4aa1d9d5e62c5b0..1102aa0ec2f7a05 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4272,6 +4272,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.
--
2.28.0.297.g1956fa8f8d-goog
Powered by blists - more mailing lists