Skip to content

Commit c26ec79

Browse files
geertupmladek
authored andcommitted
dev_printk: Add and use dev_no_printk()
When printk-indexing is enabled, each dev_printk() invocation emits a pi_entry structure. This is even true when the dev_printk() is protected by an always-false check, as is typically the case for debug messages: while the actual code to print the message is optimized out by the compiler, the pi_entry structure is still emitted. Avoid emitting pi_entry structures for unavailable dev_printk() kernel messages by: 1. Introducing a dev_no_printk() helper, mimicked after the existing no_printk() helper, which calls _dev_printk() instead of dev_printk(), 2. Replacing all "if (0) dev_printk(...)" constructs by calls to the new helper. This reduces the size of an arm64 defconfig kernel with CONFIG_PRINTK_INDEX=y by 957 KiB. Fixes: ad7d61f ("printk: index: Add indexing support to dev_printk") Signed-off-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Reviewed-by: Chris Down <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/8583d54f1687c801c6cda8edddf2cf0344c6e883.1709127473.git.geert+renesas@glider.be Signed-off-by: Petr Mladek <[email protected]>
1 parent 8522f6b commit c26ec79

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

include/linux/dev_printk.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ void _dev_info(const struct device *dev, const char *fmt, ...)
129129
_dev_printk(level, dev, fmt, ##__VA_ARGS__); \
130130
})
131131

132+
/*
133+
* Dummy dev_printk for disabled debugging statements to use whilst maintaining
134+
* gcc's format checking.
135+
*/
136+
#define dev_no_printk(level, dev, fmt, ...) \
137+
({ \
138+
if (0) \
139+
_dev_printk(level, dev, fmt, ##__VA_ARGS__); \
140+
})
141+
132142
/*
133143
* #defines for all the dev_<level> macros to prefix with whatever
134144
* possible use of #define dev_fmt(fmt) ...
@@ -158,10 +168,7 @@ void _dev_info(const struct device *dev, const char *fmt, ...)
158168
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
159169
#else
160170
#define dev_dbg(dev, fmt, ...) \
161-
({ \
162-
if (0) \
163-
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
164-
})
171+
dev_no_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
165172
#endif
166173

167174
#ifdef CONFIG_PRINTK
@@ -247,20 +254,14 @@ do { \
247254
} while (0)
248255
#else
249256
#define dev_dbg_ratelimited(dev, fmt, ...) \
250-
do { \
251-
if (0) \
252-
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
253-
} while (0)
257+
dev_no_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
254258
#endif
255259

256260
#ifdef VERBOSE_DEBUG
257261
#define dev_vdbg dev_dbg
258262
#else
259263
#define dev_vdbg(dev, fmt, ...) \
260-
({ \
261-
if (0) \
262-
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
263-
})
264+
dev_no_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
264265
#endif
265266

266267
/*

0 commit comments

Comments
 (0)