Re: [PATCH v2] checkpatch: Warn if trace_printk and friends are called

From: Joe Perches
Date: Tue Aug 25 2020 - 11:54:55 EST


On Tue, 2020-08-25 at 19:36 +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@xxxxxxxxxxxx>

thanks.

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