Skip to content

Commit 091cb09

Browse files
bebarinotorvalds
authored andcommitted
lib/hexdump: make print_hex_dump_bytes() a nop on !DEBUG builds
I'm seeing a bunch of debug prints from a user of print_hex_dump_bytes() in my kernel logs, but I don't have CONFIG_DYNAMIC_DEBUG enabled nor do I have DEBUG defined in my build. The problem is that print_hex_dump_bytes() calls a wrapper function in lib/hexdump.c that calls print_hex_dump() with KERN_DEBUG level. There are three cases to consider here 1. CONFIG_DYNAMIC_DEBUG=y --> call dynamic_hex_dum() 2. CONFIG_DYNAMIC_DEBUG=n && DEBUG --> call print_hex_dump() 3. CONFIG_DYNAMIC_DEBUG=n && !DEBUG --> stub it out Right now, that last case isn't detected and we still call print_hex_dump() from the stub wrapper. Let's make print_hex_dump_bytes() only call print_hex_dump_debug() so that it works properly in all cases. Case #1, print_hex_dump_debug() calls dynamic_hex_dump() and we get same behavior. Case #2, print_hex_dump_debug() calls print_hex_dump() with KERN_DEBUG and we get the same behavior. Case #3, print_hex_dump_debug() is a nop, changing behavior to what we want, i.e. print nothing. Link: http://lkml.kernel.org/r/20190816235624.115280-1-swboyd@chromium.org Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8e72a7a commit 091cb09

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

include/linux/printk.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,6 @@ extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
488488
extern void print_hex_dump(const char *level, const char *prefix_str,
489489
int prefix_type, int rowsize, int groupsize,
490490
const void *buf, size_t len, bool ascii);
491-
#if defined(CONFIG_DYNAMIC_DEBUG)
492-
#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
493-
dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
494-
#else
495-
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
496-
const void *buf, size_t len);
497-
#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
498491
#else
499492
static inline void print_hex_dump(const char *level, const char *prefix_str,
500493
int prefix_type, int rowsize, int groupsize,
@@ -526,4 +519,19 @@ static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
526519
}
527520
#endif
528521

522+
/**
523+
* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
524+
* @prefix_str: string to prefix each line with;
525+
* caller supplies trailing spaces for alignment if desired
526+
* @prefix_type: controls whether prefix of an offset, address, or none
527+
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
528+
* @buf: data blob to dump
529+
* @len: number of bytes in the @buf
530+
*
531+
* Calls print_hex_dump(), with log level of KERN_DEBUG,
532+
* rowsize of 16, groupsize of 1, and ASCII output included.
533+
*/
534+
#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
535+
print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
536+
529537
#endif

lib/hexdump.c

-21
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,4 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
270270
}
271271
EXPORT_SYMBOL(print_hex_dump);
272272

273-
#if !defined(CONFIG_DYNAMIC_DEBUG)
274-
/**
275-
* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
276-
* @prefix_str: string to prefix each line with;
277-
* caller supplies trailing spaces for alignment if desired
278-
* @prefix_type: controls whether prefix of an offset, address, or none
279-
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
280-
* @buf: data blob to dump
281-
* @len: number of bytes in the @buf
282-
*
283-
* Calls print_hex_dump(), with log level of KERN_DEBUG,
284-
* rowsize of 16, groupsize of 1, and ASCII output included.
285-
*/
286-
void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
287-
const void *buf, size_t len)
288-
{
289-
print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
290-
buf, len, true);
291-
}
292-
EXPORT_SYMBOL(print_hex_dump_bytes);
293-
#endif /* !defined(CONFIG_DYNAMIC_DEBUG) */
294273
#endif /* defined(CONFIG_PRINTK) */

0 commit comments

Comments
 (0)