printk: add pr_<level>_once, guard print_hex_dump
Subsystems (6)
cover printk: add pr_<level>_once, guard print_hex_dump
There are many uses of printk_once(KERN_<level>.
Add pr_<level>_once macros to avoid printk_once(KERN_<level> pr_fmt(fmt). Add an #ifdef CONFIG_PRINTK for print_hex_dump and static inline void functions for the #else cases to reduce embedded code size. Neaten and organize the rest of the code.
Joe Perches (7):
include/linux/printk.h: Move console functions and variables together include/linux/printk.h: Use space after #define include/linux/printk.h: Use and neaten no_printk include/linux/printk.h: Add pr_<level>_once macros include/linux/printk.h lib/hexdump.c: Neatening and add CONFIG_PRINTK guard include/linux/printk.h: Organize printk_ratelimited macros include/linux/printk.h: Use tab not spaces for indent
include/linux/printk.h | 247 +++++++++++++++++++++++++++++------------------- lib/hexdump.c | 2 + 2 files changed, 152 insertions(+), 97 deletions(-)
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 1/7 include/linux/printk.h: Move console functions and variables together
--- include/linux/printk.h | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
include/linux/printk.h +11 -11
@@ -29,6 +29,17 @@ extern int console_printk[];#define minimum_console_loglevel (console_printk[2])#define default_console_loglevel (console_printk[3]) +static inline void console_silent (void ) +{ + console_loglevel =0 ; +} + +static inline void console_verbose (void ) +{ +if (console_loglevel) + console_loglevel =15 ; +} +struct va_format {const char *fmt;va_list *va;
@@ -130,17 +141,6 @@ extern void printk_tick(void); extern void asmlinkage __attribute__((format(printf, 1, 2))) early_printk(const char *fmt, ...); -static inline void console_silent (void ) -{ - console_loglevel =0 ; -} - -static inline void console_verbose (void ) -{ -if (console_loglevel) - console_loglevel =15 ; -} -extern void dump_stack (void )__cold ;enum {
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 2/7 include/linux/printk.h: Use space after #define
In reply to Joe Perches--- include/linux/printk.h | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
include/linux/printk.h +9 -9
@@ -4,14 +4,14 @@extern const char linux_banner[];extern const char linux_proc_banner[]; -#define KERN_EMERG "<0>"/* system is unusable */ -#define KERN_ALERT "<1>"/* action must be taken immediately */ -#define KERN_CRIT "<2>"/* critical conditions */ -#define KERN_ERR "<3>"/* error conditions */ -#define KERN_WARNING "<4>"/* warning conditions */ -#define KERN_NOTICE "<5>"/* normal but significant condition */ -#define KERN_INFO "<6>"/* informational */ -#define KERN_DEBUG "<7>"/* debug-level messages */ +#define KERN_EMERG "<0>"/* system is unusable */ +#define KERN_ALERT "<1>"/* action must be taken immediately */ +#define KERN_CRIT "<2>"/* critical conditions */ +#define KERN_ERR "<3>"/* error conditions */ +#define KERN_WARNING "<4>"/* warning conditions */ +#define KERN_NOTICE "<5>"/* normal but significant condition */ +#define KERN_INFO "<6>"/* informational */ +#define KERN_DEBUG "<7>"/* debug-level messages */ /* Use the default kernel loglevel */ #define KERN_DEFAULT "<d>"
@@ -20,7 +20,7 @@ extern const char linux_proc_banner[];* line that had no enclosing \n). Only to be used by core/arch code * during early bootup (a continued line is not SMP-safe otherwise). */ -#define KERN_CONT "<c>" +#define KERN_CONT "<c>"extern int console_printk[];
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 3/7 include/linux/printk.h: Use and neaten no_printk
In reply to Joe PerchesMove no_printk above first CONFIG_PRINTK block so it can be used by printk_once.
Convert statement expression if (0) printk macros to no_printk. Convert printk_once(x...) to more normally used (fmt, ...) fmt, ##__VA_ARGS__. Standardize __attribute__ use.
Expand single line inline functions.
Remove space before pointer.
--- include/linux/printk.h | 75 +++++++++++++++++++++++++++-------------------- 1 files changed, 43 insertions(+), 32 deletions(-)
include/linux/printk.h +43 -32
@@ -76,11 +76,27 @@ struct va_format {*/ #define HW_ERR "[Hardware Error]: " +/* +* Dummy printk for disabled debugging statements to use whilst maintaining +* gcc's format and side-effect checking. +*/ +static inline __attribute__ ((format (printf,1 ,2 ))) +int no_printk (const char *fmt, ...) +{ +return 0 ; +} + +extern asmlinkage __attribute__ ((format (printf,1 ,2 ))) +void early_printk(const char *fmt, ...); + +extern int printk_needs_cpu (int cpu); +extern void printk_tick (void ); +#ifdef CONFIG_PRINTK -asmlinkage int vprintk(const char *fmt, va_list args) - __attribute__ ((format (printf,1 ,0 ))); -asmlinkage int printk(const char * fmt, ...) - __attribute__ ((format (printf,1 ,2 )))__cold ; +asmlinkage __attribute__ ((format (printf,1 ,0 ))) +int vprintk(const char *fmt, va_list args); +asmlinkage __attribute__ ((format (printf,1 ,2 )))__cold +int printk(const char *fmt, ...);/* * Please don't use printk_ratelimit(), because it shares ratelimiting state
@@ -109,38 +125,34 @@ extern int dmesg_restrict;void log_buf_kexec_setup (void );#else -static inline int vprintk (const char *s,va_list args) - __attribute__ ((format (printf,1 ,0 ))); -static inline int vprintk (const char *s,va_list args) {return 0 ; } -static inline int printk (const char *s, ...) - __attribute__ ((format (printf,1 ,2 ))); -static inline int __cold printk (const char *s, ...) {return 0 ; } -static inline int printk_ratelimit (void ) {return 0 ; } -static inline bool printk_timed_ratelimit (unsigned long *caller_jiffies, \ -unsigned int interval_msec) \ - {return false; } +static inline __attribute__ ((format (printf,1 ,0 ))) +int vprintk (const char *s,va_list args) +{ +return 0 ; +} +static inline __attribute__ ((format (printf,1 ,2 )))__cold +int printk (const char *s, ...) +{ +return 0 ; +} +static inline int printk_ratelimit (void ) +{ +return 0 ; +} +static inline bool printk_timed_ratelimit (unsigned long *caller_jiffies, +unsigned int interval_msec) +{ +return false; +}/* No effect, but we still get type checking even in the !PRINTK case: */ -#define printk_once(x...) printk(x) +#define printk_once (fmt, ...) no_printk(fmt, ##__VA_ARGS__)static inline void log_buf_kexec_setup (void ) { }#endif -/* -* Dummy printk for disabled debugging statements to use whilst maintaining -* gcc's format and side-effect checking. -*/ -static inline __attribute__ ((format (printf,1 ,2 ))) -int no_printk (const char *s, ...) {return 0 ; } - -extern int printk_needs_cpu (int cpu); -extern void printk_tick (void ); - -extern void asmlinkage __attribute__((format(printf, 1, 2))) - early_printk(const char *fmt, ...); -extern void dump_stack (void )__cold ;enum {
@@ -185,7 +197,7 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_devel(fmt, ...) \ - ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)#endif /* If you are writing a driver, please use dev_dbg instead */
@@ -198,7 +210,7 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, dynamic_pr_debug(fmt, ##__VA_ARGS__)#else #define pr_debug (fmt, ...) \ - ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)#endif /*
@@ -241,8 +253,7 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug_ratelimited(fmt, ...) \ - ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ - ##__VA_ARGS__); 0; }) + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)#endif #endif
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 4/7 include/linux/printk.h: Add pr_<level>_once macros
In reply to Joe PerchesMove printk_once definitions and add an #ifdef CONFIG_PRINTK Add pr_<level>_once so printks can use pr_fmt
--- include/linux/printk.h | 59 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 44 insertions(+), 15 deletions(-)
include/linux/printk.h +44 -15
@@ -111,18 +111,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,extern int printk_delay_msec;extern int dmesg_restrict; -/* -* Print a one-time message (analogous to WARN_ONCE() et al): -*/ -#define printk_once(x...) ({ \ - static bool __print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - printk(x); \ - } \ -}) -void log_buf_kexec_setup (void );#else static inline __attribute__ ((format (printf, 1, 0)))
@@ -145,9 +133,6 @@ static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,return false; } -/* No effect, but we still get type checking even in the !PRINTK case: */ -#define printk_once (fmt, ...) no_printk(fmt, ##__VA_ARGS__) -static inline void log_buf_kexec_setup (void ) { }
@@ -214,6 +199,50 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,#endif /* +* Print a one-time message (analogous to WARN_ONCE() et al): +*/ + +#ifdef CONFIG_PRINTK +#define printk_once (fmt, ...) \ +({ \ + static bool __print_once; \ + \ + if (!__print_once) { \ + __print_once = true; \ + printk(fmt, ##__VA_ARGS__); \ + } \ +}) +#else +#define printk_once (fmt, ...) \ + no_printk(fmt, ##__VA_ARGS__) +#endif + +#define pr_emerg_once (fmt, ...) \ + printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) +#define pr_alert_once (fmt, ...) \ + printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_crit_once (fmt, ...) \ + printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_err_once (fmt, ...) \ + printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) +#define pr_warn_once (fmt, ...) \ + printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) +#define pr_notice_once (fmt, ...) \ + printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info_once (fmt, ...) \ + printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) +#define pr_cont_once (fmt, ...) \ + printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +/* If you are writing a driver, please use dev_dbg instead */ +#if defined(DEBUG ) +#define pr_debug_once (fmt, ...) \ + printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#else +#define pr_debug_once (fmt, ...) \ + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#endif + +/* * ratelimited messages with local ratelimit_state, * no local ratelimit_state used in the !PRINTK case */
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 5/7 include/linux/printk.h lib/hexdump.c: Neatening and add CONFIG_PRINTK guard
In reply to Joe PerchesMove prototypes and align arguments.
Add CONFIG_PRINTK guard for print_hex functions
--- include/linux/printk.h | 42 ++++++++++++++++++++++++++++-------------- lib/hexdump.c | 2 ++ 2 files changed, 30 insertions(+), 14 deletions(-)
include/linux/printk.h +28 -14
@@ -140,20 +140,6 @@ static inline void log_buf_kexec_setup(void)extern void dump_stack (void )__cold ; -enum { -DUMP_PREFIX_NONE , -DUMP_PREFIX_ADDRESS , -DUMP_PREFIX_OFFSET -}; -extern void hex_dump_to_buffer (const void *buf,size_t len, -int rowsize,int groupsize, -char *linebuf,size_t linebuflen,bool ascii); -extern void print_hex_dump (const char *level,const char *prefix_str, -int prefix_type,int rowsize,int groupsize, -const void *buf,size_t len,bool ascii); -extern void print_hex_dump_bytes (const char *prefix_str,int prefix_type, -const void *buf,size_t len); -#ifndef pr_fmt#define pr_fmt (fmt) fmt#endif
@@ -285,4 +271,32 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)#endif + +enum { +DUMP_PREFIX_NONE , +DUMP_PREFIX_ADDRESS , +DUMP_PREFIX_OFFSET +}; +extern void hex_dump_to_buffer (const void *buf,size_t len, +int rowsize,int groupsize, +char *linebuf,size_t linebuflen,bool ascii); +#ifdef CONFIG_PRINTK +extern void print_hex_dump (const char *level,const char *prefix_str, +int prefix_type,int rowsize,int groupsize, +const void *buf,size_t len,bool ascii); +extern void print_hex_dump_bytes (const char *prefix_str,int prefix_type, +const void *buf,size_t len); +#else +static inline void print_hex_dump (const char *level,const char *prefix_str, +int prefix_type,int rowsize,int groupsize, +const void *buf,size_t len,bool ascii) +{ +} +static inline void print_hex_dump_bytes (const char *prefix_str,int prefix_type, +const void *buf,size_t len) +{ +} + +#endif +#endif
lib/hexdump.c +2 -0
@@ -154,6 +154,7 @@ nil: }EXPORT_SYMBOL (hex_dump_to_buffer); +#ifdef CONFIG_PRINTK /** * print_hex_dump - print a text hex dump to syslog for a binary blob of data * @level: kernel log level (e.g. KERN_DEBUG)
@@ -238,3 +239,4 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type, buf, len, true); }EXPORT_SYMBOL (print_hex_dump_bytes); +#endif
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 6/7 include/linux/printk.h: Organize printk_ratelimited macros
In reply to Joe PerchesUse no_printk for !CONFIG_PRINTK printk_ratelimited. Whitespace cleanup.
--- include/linux/printk.h | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-)
include/linux/printk.h +12 -13
@@ -233,7 +233,8 @@ extern void dump_stack(void) __cold;* no local ratelimit_state used in the !PRINTK case */ #ifdef CONFIG_PRINTK -#define printk_ratelimited (fmt, ...) ({ \ +#define printk_ratelimited (fmt, ...) \ +({ \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \ DEFAULT_RATELIMIT_BURST); \
@@ -242,36 +243,34 @@ extern void dump_stack(void) __cold; printk(fmt, ##__VA_ARGS__); \ })#else -/* No effect, but we still get type checking even in the !PRINTK case: */ -#define printk_ratelimited printk +#define printk_ratelimited (fmt, ...) \ + no_printk(fmt, ##__VA_ARGS__)#endif -#define pr_emerg_ratelimited (fmt, ...) \ +#define pr_emerg_ratelimited (fmt, ...) \ printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) -#define pr_alert_ratelimited (fmt, ...) \ +#define pr_alert_ratelimited (fmt, ...) \ printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) -#define pr_crit_ratelimited (fmt, ...) \ +#define pr_crit_ratelimited (fmt, ...) \ printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) -#define pr_err_ratelimited (fmt, ...) \ +#define pr_err_ratelimited (fmt, ...) \ printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) -#define pr_warning_ratelimited (fmt, ...) \ +#define pr_warn_ratelimited (fmt, ...) \ printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) -#define pr_warn_ratelimited pr_warning_ratelimited -#define pr_notice_ratelimited (fmt, ...) \ +#define pr_notice_ratelimited (fmt, ...) \ printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) -#define pr_info_ratelimited (fmt, ...) \ +#define pr_info_ratelimited (fmt, ...) \ printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)/* no pr_cont_ratelimited, don't do that... */ /* If you are writing a driver, please use dev_dbg instead */ #if defined(DEBUG ) -#define pr_debug_ratelimited (fmt, ...) \ +#define pr_debug_ratelimited (fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)#else #define pr_debug_ratelimited (fmt, ...) \ no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)#endif -enum {DUMP_PREFIX_NONE ,DUMP_PREFIX_ADDRESS ,
Signature · 1 line
1.7.3.2.245.g03276.dirty
PATCH 7/7 include/linux/printk.h: Use tab not spaces for indent
In reply to Joe Perches--- include/linux/printk.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
include/linux/printk.h +7 -7
@@ -145,20 +145,20 @@ extern void dump_stack(void) __cold;#endif #define pr_emerg (fmt, ...) \ - printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)#define pr_alert (fmt, ...) \ - printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)#define pr_crit (fmt, ...) \ - printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)#define pr_err (fmt, ...) \ - printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)#define pr_warning (fmt, ...) \ - printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)#define pr_warn pr_warning#define pr_notice (fmt, ...) \ - printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)#define pr_info (fmt, ...) \ - printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) + printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)#define pr_cont (fmt, ...) \ printk(KERN_CONT fmt, ##__VA_ARGS__)
Signature · 1 line
1.7.3.2.245.g03276.dirty
Quoted 5 lines · Joe Perches
There are many uses of printk_once(KERN_<level>.
Add pr_<level>_once macros to avoid printk_once(KERN_<level>pr_fmt(fmt). Add an #ifdefCONFIG_PRINTKforprint_hex_dumpand static inline void functions for the #else cases to reduce embedded code size. Neaten and organize the rest of the code.
Looks fine to me. I'd missed the introduction of the pr_<level> macros and I'm not sure if I like the idea, but this is a tidy and well-presented cleanup and extension.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 10 lines · Matt Mackall
Quoted 5 lines · Joe Perches
There are many uses of printk_once(KERN_<level>.
Add pr_<level>_once macros to avoid printk_once(KERN_<level>pr_fmt(fmt). Add an #ifdefCONFIG_PRINTKforprint_hex_dumpand static inline void functions for the #else cases to reduce embedded code size. Neaten and organize the rest of the code.Looks fine to me. I'd missed the introduction of the pr_<level> macros and I'm not sure if I like the idea, but this is a tidy and well-presented cleanup and extension.
Acked-by Matt Mackall <[email protected]>
The #ifdef CONFIG_PRINTK guard for print_hex_dump saves ~200 bytes in an x86 !CONFIG_PRINTK
There could be ~500 bytes more saved if hex_dump_to_buffer was compiled out.
It's a more invasive change, so I didn't want to submit it just now, but it could be something like below.
It requires the modules that use hex_dump_to_buffer, there aren't many, to Kconfig select HEX_DUMP_TO_BUFFER so it's not very pretty nor simple.
Thoughts?
---
drivers/isdn/hardware/mISDN/Kconfig | 2 +- drivers/media/video/hdpvr/Kconfig | 1 + drivers/mfd/Kconfig | 1 + drivers/net/wireless/iwlwifi/Kconfig | 1 + drivers/scsi/osd/Kconfig | 1 + include/linux/printk.h | 14 ++++++++++++++ init/Kconfig | 7 +++++++ lib/Kconfig | 4 ++++ lib/Kconfig.debug | 1 + lib/hexdump.c | 2 ++ 10 files changed, 33 insertions(+), 1 deletions(-)
drivers/isdn/hardware/mISDN/Kconfig +1 -1
@@ -90,4 +90,4 @@ config MISDN_IPAC config MISDN_ISAR tristate depends on MISDN - + select HEX_DUMP_TO_BUFFER
drivers/media/video/hdpvr/Kconfig +1 -0
@@ -2,6 +2,7 @@ config VIDEO_HDPVR tristate "Hauppauge HD PVR support" depends on VIDEO_DEV + select HEX_DUMP_TO_BUFFER ---help--- This is a video4linux driver for Hauppauge's HD PVR USB device.
drivers/mfd/Kconfig +1 -0
@@ -418,6 +418,7 @@ config MFD_WM8994 config MFD_PCF50633 tristate "Support for NXP PCF50633" depends on I2C + select HEX_DUMP_TO_BUFFER help Say yes here if you have NXP PCF50633 chip on your board. This core driver provides register access and IRQ handling
drivers/net/wireless/iwlwifi/Kconfig +1 -0
@@ -2,6 +2,7 @@ config IWLWIFI tristate "Intel Wireless Wifi" depends on PCI && MAC80211 select FW_LOADER + select HEX_DUMP_TO_BUFFER menu "Debugging Options" depends on IWLWIFI
drivers/scsi/osd/Kconfig +1 -0
@@ -18,6 +18,7 @@ config SCSI_OSD_INITIATOR tristate "OSD-Initiator library" depends on SCSI + select HEX_DUMP_TO_BUFFER help Enable the OSD-Initiator library (libosd.ko). NOTE: You must also select CRYPTO_SHA1 + CRYPTO_HMAC and their
include/linux/printk.h +14 -0
@@ -276,9 +276,23 @@ enum {DUMP_PREFIX_ADDRESS ,DUMP_PREFIX_OFFSET }; + +#ifdef CONFIG_HEX_DUMP_TO_BUFFER extern void hex_dump_to_buffer (const void *buf,size_t len,int rowsize,int groupsize,char *linebuf,size_t linebuflen,bool ascii); +#else +static inline +void hex_dump_to_buffer (const void *buf,size_t len, +int rowsize,int groupsize, +char *linebuf,size_t linebuflen,bool ascii) +{ +#ifndef CONFIG_EMBEDDED +#error "Kconfig must select CONFIG_HEX_DUMP_TO_BUFFER" +#endif +} +#endif +#ifdef CONFIG_PRINTK extern void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize,
init/Kconfig +7 -0
@@ -950,6 +950,13 @@ config PRINTK very difficult to diagnose system problems, saying N here is strongly discouraged. +config HEX_DUMP_TO_BUFFER + default y + bool "Enable support for hexdump" if EMBEDDED + help + This option enables normal hex_dump support. + Saying N here is strongly discouraged. + config BUG bool "BUG() support" if EMBEDDED default y
lib/Kconfig +4 -0
@@ -5,6 +5,10 @@ config BINARY_PRINTF def_bool n +config HEX_DUMP_TO_BUFFER + bool + default n + menu "Library routines" config RAID6_PQ
lib/Kconfig.debug +1 -0
@@ -380,6 +380,7 @@ config DEBUG_KMEMLEAK select STACKTRACE if STACKTRACE_SUPPORT select KALLSYMS select CRC32 + select HEX_DUMP_TO_BUFFER help Say Y here if you want to enable the memory leak detector. The memory allocation/freeing is traced in a way
lib/hexdump.c +2 -0
@@ -49,6 +49,7 @@ void hex2bin(u8 *dst, const char *src, size_t count) }EXPORT_SYMBOL (hex2bin); +#ifdef CONFIG_HEX_DUMP_TO_BUFFER /** * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory * @buf: data blob to dump
@@ -153,6 +154,7 @@ nil: linebuf[lx++] = '\0'; }EXPORT_SYMBOL (hex_dump_to_buffer); +#endif #ifdef CONFIG_PRINTK /**
Quoted 12 lines · Joe Perches
Quoted 10 lines · Matt Mackall
Quoted 5 lines · Joe Perches
There are many uses of printk_once(KERN_<level>.
Add pr_<level>_once macros to avoid printk_once(KERN_<level>pr_fmt(fmt). Add an #ifdefCONFIG_PRINTKforprint_hex_dumpand static inline void functions for the #else cases to reduce embedded code size. Neaten and organize the rest of the code.Looks fine to me. I'd missed the introduction of the pr_<level> macros and I'm not sure if I like the idea, but this is a tidy and well-presented cleanup and extension.
Acked-by Matt Mackall <[email protected]>
Quoted 5 lines
The #ifdef
CONFIG_PRINTKguard forprint_hex_dumpsaves ~200 bytes in an x86 !CONFIG_PRINTKThere could be ~500 bytes more saved if
hex_dump_to_bufferwas compiled out.
Can't say I'm excited by this approach. .5k is under my threshold for this level of invasiveness.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 5 lines · Matt Mackall
Quoted 2 lines · Joe Perches
There could be ~500 bytes more saved if
hex_dump_to_bufferwas compiled out.Can't say I'm excited by this approach. .5k is under my threshold for this level of invasiveness.
Mine too, but I thought I'd mention it.