2010-12-06 05:44:25

by Joe Perches

[permalink] [raw]
Subject: [PATCH 0/7] 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(-)

--
1.7.3.2.245.g03276.dirty


2010-12-06 05:44:30

by Joe Perches

[permalink] [raw]
Subject: [PATCH 4/7] include/linux/printk.h: Add pr_<level>_once macros

Move printk_once definitions and add an #ifdef CONFIG_PRINTK
Add pr_<level>_once so printks can use pr_fmt

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 59 +++++++++++++++++++++++++++++++++++------------
1 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index e3858f2..8a9a2ee 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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
*/
--
1.7.3.2.245.g03276.dirty

2010-12-06 05:44:27

by Joe Perches

[permalink] [raw]
Subject: [PATCH 2/7] include/linux/printk.h: Use space after #define

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 0b4513b..b6218d3 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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[];

--
1.7.3.2.245.g03276.dirty

2010-12-06 05:44:32

by Joe Perches

[permalink] [raw]
Subject: [PATCH 6/7] include/linux/printk.h: Organize printk_ratelimited macros

Use no_printk for !CONFIG_PRINTK printk_ratelimited.
Whitespace cleanup.

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 25 ++++++++++++-------------
1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index a705a91..b4be1b1 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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,
--
1.7.3.2.245.g03276.dirty

2010-12-06 05:44:44

by Joe Perches

[permalink] [raw]
Subject: [PATCH 7/7] include/linux/printk.h: Use tab not spaces for indent

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index b4be1b1..41388e3 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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__)

--
1.7.3.2.245.g03276.dirty

2010-12-06 05:44:57

by Joe Perches

[permalink] [raw]
Subject: [PATCH 5/7] include/linux/printk.h lib/hexdump.c: Neatening and add CONFIG_PRINTK guard

Move prototypes and align arguments.
Add CONFIG_PRINTK guard for print_hex functions

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 42 ++++++++++++++++++++++++++++--------------
lib/hexdump.c | 2 ++
2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 8a9a2ee..a705a91 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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
diff --git a/lib/hexdump.c b/lib/hexdump.c
index b66b2bd..f5fe6ba 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -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
--
1.7.3.2.245.g03276.dirty

2010-12-06 05:45:41

by Joe Perches

[permalink] [raw]
Subject: [PATCH 3/7] include/linux/printk.h: Use and neaten no_printk

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

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 75 +++++++++++++++++++++++++++--------------------
1 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index b6218d3..e3858f2 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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
--
1.7.3.2.245.g03276.dirty

2010-12-06 05:45:59

by Joe Perches

[permalink] [raw]
Subject: [PATCH 1/7] include/linux/printk.h: Move console functions and variables together

Signed-off-by: Joe Perches <[email protected]>
---
include/linux/printk.h | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index b772ca5..0b4513b 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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 {
--
1.7.3.2.245.g03276.dirty

2010-12-06 15:37:53

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 0/7] printk: add pr_<level>_once, guard print_hex_dump

On Sun, 2010-12-05 at 21:44 -0800, Joe Perches wrote:
> 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.

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

--
Mathematics is the supreme nostalgia of our time.

2010-12-06 18:12:06

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 0/7] printk: add pr_<level>_once, guard print_hex_dump

On Mon, 2010-12-06 at 09:37 -0600, Matt Mackall wrote:
> On Sun, 2010-12-05 at 21:44 -0800, Joe Perches wrote:
> > 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.
> 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(-)

diff --git a/drivers/isdn/hardware/mISDN/Kconfig b/drivers/isdn/hardware/mISDN/Kconfig
index eadc1cd..243eadf 100644
--- a/drivers/isdn/hardware/mISDN/Kconfig
+++ b/drivers/isdn/hardware/mISDN/Kconfig
@@ -90,4 +90,4 @@ config MISDN_IPAC
config MISDN_ISAR
tristate
depends on MISDN
-
+ select HEX_DUMP_TO_BUFFER
diff --git a/drivers/media/video/hdpvr/Kconfig b/drivers/media/video/hdpvr/Kconfig
index de247f3..851a45f 100644
--- a/drivers/media/video/hdpvr/Kconfig
+++ b/drivers/media/video/hdpvr/Kconfig
@@ -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.

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3a7b891..982b27a 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -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
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index ed42457..4074fa0 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -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
diff --git a/drivers/scsi/osd/Kconfig b/drivers/scsi/osd/Kconfig
index 861b5ce..c43df39 100644
--- a/drivers/scsi/osd/Kconfig
+++ b/drivers/scsi/osd/Kconfig
@@ -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
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 41388e3..38d918d 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -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,
diff --git a/init/Kconfig b/init/Kconfig
index 3eb22ad..5ab5ad8 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -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
diff --git a/lib/Kconfig b/lib/Kconfig
index 3d498b2..2c95d1c 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -5,6 +5,10 @@
config BINARY_PRINTF
def_bool n

+config HEX_DUMP_TO_BUFFER
+ bool
+ default n
+
menu "Library routines"

config RAID6_PQ
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 968d183..e3b0238 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -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
diff --git a/lib/hexdump.c b/lib/hexdump.c
index f5fe6ba..88d70f4 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -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
/**

2010-12-06 18:16:25

by Matt Mackall

[permalink] [raw]
Subject: Re: [PATCH 0/7] printk: add pr_<level>_once, guard print_hex_dump

On Mon, 2010-12-06 at 10:12 -0800, Joe Perches wrote:
> On Mon, 2010-12-06 at 09:37 -0600, Matt Mackall wrote:
> > On Sun, 2010-12-05 at 21:44 -0800, Joe Perches wrote:
> > > 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.
> > 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.

Can't say I'm excited by this approach. .5k is under my threshold for
this level of invasiveness.

--
Mathematics is the supreme nostalgia of our time.

2010-12-06 18:51:39

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 0/7] printk: add pr_<level>_once, guard print_hex_dump

On Mon, 2010-12-06 at 12:16 -0600, Matt Mackall wrote:
> On Mon, 2010-12-06 at 10:12 -0800, Joe Perches wrote:
> > There could be ~500 bytes more saved if hex_dump_to_buffer
> > was 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.