linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Warn if trace_printk and friends are called
@ 2020-08-25  7:09 Nicolas Boichat
  2020-08-25  7:23 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Boichat @ 2020-08-25  7:09 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: Steven Rostedt, Nicolas Boichat, linux-kernel

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@chromium.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.

 scripts/checkpatch.pl | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4aa1d9d5e62c5b0..4b4988f25223c6a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4272,6 +4272,14 @@ 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*\(/) {
+			my $func = $1;
+
+			WARN("TRACE_PRINTK",
+			     "Do not use $func() in production code (this can be ignored if built only behind 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] checkpatch: Warn if trace_printk and friends are called
  2020-08-25  7:09 [PATCH] checkpatch: Warn if trace_printk and friends are called Nicolas Boichat
@ 2020-08-25  7:23 ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2020-08-25  7:23 UTC (permalink / raw)
  To: Nicolas Boichat, Andy Whitcroft, Andrew Morton
  Cc: Steven Rostedt, linux-kernel

On Tue, 2020-08-25 at 15:09 +0800, Nicolas Boichat wrote:
> 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@chromium.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.

I don't have a real objection, just some nits.

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -4272,6 +4272,14 @@ 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*\(/) {
> +			my $func = $1;
> +
> +			WARN("TRACE_PRINTK",
> +			     "Do not use $func() in production code (this can be ignored if built only behind a debug config option).\n" . $herecurr);

You don't need to do an assign, you could use $1 directly.
I think 'built only behind' could be "building only with'.
No periods before the newline either.

> +		}
> +
>  # 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-25  7:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25  7:09 [PATCH] checkpatch: Warn if trace_printk and friends are called Nicolas Boichat
2020-08-25  7:23 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).