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

2010-12-05 Thread Joe Perches
Signed-off-by: Joe Perches 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2010-12-05 Thread Joe Perches
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 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2010-12-05 Thread Joe Perches
Move prototypes and align arguments.
Add CONFIG_PRINTK guard for print_hex functions

Signed-off-by: Joe Perches 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2010-12-05 Thread Joe Perches
Signed-off-by: Joe Perches 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2010-12-05 Thread Joe Perches
Use no_printk for !CONFIG_PRINTK printk_ratelimited.
Whitespace cleanup.

Signed-off-by: Joe Perches 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/7] include/linux/printk.h: Add pr__once macros

2010-12-05 Thread Joe Perches
Move printk_once definitions and add an #ifdef CONFIG_PRINTK
Add pr__once so printks can use pr_fmt

Signed-off-by: Joe Perches 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2010-12-05 Thread Joe Perches
Signed-off-by: Joe Perches 
---
 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[];
 
-#defineKERN_EMERG  "<0>"   /* system is unusable   
*/
-#defineKERN_ALERT  "<1>"   /* action must be taken immediately 
*/
-#defineKERN_CRIT   "<2>"   /* critical conditions  
*/
-#defineKERN_ERR"<3>"   /* error conditions 
*/
-#defineKERN_WARNING"<4>"   /* warning conditions   
*/
-#defineKERN_NOTICE "<5>"   /* normal but significant condition 
*/
-#defineKERN_INFO   "<6>"   /* informational
*/
-#defineKERN_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   ""
@@ -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).
  */
-#defineKERN_CONT   ""
+#define KERN_CONT  ""
 
 extern int console_printk[];
 
-- 
1.7.3.2.245.g03276.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/7] printk: add pr__once, guard print_hex_dump

2010-12-05 Thread Joe Perches
There are many uses of printk_once(KERN_.
Add pr__once macros to avoid printk_once(KERN_ 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__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

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html