Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
trace: Add CONFIG_DISABLE_TRACE_PRINTK option
Browse files Browse the repository at this point in the history
Poorly made kernel trees often use trace_printk() without
properly guarding them in a #ifdef macro.
Such usage of trace_printk() causes a warning at
boot and additional memory allocation.

This option serves to disable those all at once with ease.

Signed-off-by: Park Ju Hyung <[email protected]>
Signed-off-by: Alex Naidis <[email protected]>
Signed-off-by: UtsavBalar1231 <[email protected]>
Change-Id: I7af2f2d3ba700fc53d5f573ed13c0210adfe11c9
  • Loading branch information
arter97 authored and UtsavBalar1231 committed May 2, 2022
1 parent 6581493 commit 43b668b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ do { \
* let gcc optimize the rest.
*/

#ifdef CONFIG_DISABLE_TRACE_PRINTK
#define trace_printk pr_debug
#else
#define trace_printk(fmt, ...) \
do { \
char _______STR[] = __stringify((__VA_ARGS__)); \
Expand All @@ -709,6 +712,7 @@ do { \
else \
__trace_printk(_THIS_IP_, fmt, ##args); \
} while (0)
#endif

extern __printf(2, 3)
int __trace_bprintk(unsigned long ip, const char *fmt, ...);
Expand Down
14 changes: 14 additions & 0 deletions kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ config GENERIC_TRACER
bool
select TRACING

if TRACING

config DISABLE_TRACE_PRINTK
bool "Force disable trace_printk() usage"
default y
help
When trace_printk() is used in any of the kernel source, it enables
debugging functions which are not desired for production kernel.
Enabling this option will replace trace_printk() with pr_debug().

If in doubt, say Y.

endif

#
# Minimum requirements an architecture has to meet for us to
# be able to offer generic tracing facilities:
Expand Down

0 comments on commit 43b668b

Please sign in to comment.