2009-09-30 20:36:15

by Joe Perches

[permalink] [raw]
Subject: [PATCH] dynamic_debug.h/kernel.h: Remove KBUILD_MODNAME from dynamic_pr_debug

If CONFIG_DYNAMIC_DEBUG is enabled and a source file has:

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>

dynamic_debug.h will duplicate KBUILD_MODNAME
in the output string.

Remove the use of KBUILD_MODNAME from the
output format string generated by dynamic_debug.h

If CONFIG_DYNAMIC_DEBUG is not enabled, no compile-time
check is done to printk/dev_printk arguments.

Add it.

Signed-off-by: Joe Perches <[email protected]>

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index a0d9422..5677260 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -57,8 +57,7 @@ extern int ddebug_remove_module(char *mod_name);
{ KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
if (__dynamic_dbg_enabled(descriptor)) \
- printk(KERN_DEBUG KBUILD_MODNAME ":" pr_fmt(fmt), \
- ##__VA_ARGS__); \
+ printk(KERN_DEBUG fmt, ##__VA_ARGS__); \
} while (0)


@@ -70,8 +69,7 @@ extern int ddebug_remove_module(char *mod_name);
DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
if (__dynamic_dbg_enabled(descriptor)) \
dev_printk(KERN_DEBUG, dev, \
- KBUILD_MODNAME ": " fmt, \
- ##__VA_ARGS__); \
+ fmt, ##__VA_ARGS__); \
} while (0)

#else
@@ -81,8 +79,10 @@ static inline int ddebug_remove_module(char *mod)
return 0;
}

-#define dynamic_pr_debug(fmt, ...) do { } while (0)
-#define dynamic_dev_dbg(dev, format, ...) do { } while (0)
+#define dynamic_pr_debug(fmt, ...) \
+ do { if (0) printk(KERN_DEBUG fmt, ##__VA_ARGS__); } while (0)
+#define dynamic_dev_dbg(dev, format, ...) \
+ do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
#endif

#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d3cd23f..cd370f5 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -397,10 +397,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
#define pr_debug(fmt, ...) \
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#elif defined(CONFIG_DYNAMIC_DEBUG)
-/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
-#define pr_debug(fmt, ...) do { \
- dynamic_pr_debug(fmt, ##__VA_ARGS__); \
- } while (0)
+#define pr_debug(fmt, ...) \
+ dynamic_pr_debug(pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) \
({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })


2009-10-01 21:09:30

by Jason Baron

[permalink] [raw]
Subject: Re: [PATCH] dynamic_debug.h/kernel.h: Remove KBUILD_MODNAME from dynamic_pr_debug

On Wed, Sep 30, 2009 at 01:36:17PM -0700, Joe Perches wrote:
> If CONFIG_DYNAMIC_DEBUG is enabled and a source file has:
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> #include <linux/kernel.h>
>
> dynamic_debug.h will duplicate KBUILD_MODNAME
> in the output string.
>
> Remove the use of KBUILD_MODNAME from the
> output format string generated by dynamic_debug.h
>
> If CONFIG_DYNAMIC_DEBUG is not enabled, no compile-time
> check is done to printk/dev_printk arguments.
>
> Add it.
>

looks good. thanks for updating this.

Acked-by: Jason Baron <[email protected]>

2009-10-01 21:57:42

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] dynamic_debug.h/kernel.h: Remove KBUILD_MODNAME from dynamic_pr_debug

On Wed, 30 Sep 2009 13:36:17 -0700
Joe Perches <[email protected]> wrote:

> If CONFIG_DYNAMIC_DEBUG is enabled and a source file has:
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> #include <linux/kernel.h>
>
> dynamic_debug.h will duplicate KBUILD_MODNAME
> in the output string.
>
> Remove the use of KBUILD_MODNAME from the
> output format string generated by dynamic_debug.h
>
> If CONFIG_DYNAMIC_DEBUG is not enabled, no compile-time
> check is done to printk/dev_printk arguments.
>
> Add it.


x86_64 allmodconfig:

crypto/zlib.c: In function 'zlib_compress_update':
crypto/zlib.c:148: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:148: error: initializer element is not computable at load time
crypto/zlib.c:148: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:148: warning: excess elements in struct initializer
crypto/zlib.c:148: warning: (near initialization for 'descriptor')
crypto/zlib.c:160: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:160: error: initializer element is not computable at load time
crypto/zlib.c:160: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:160: warning: excess elements in struct initializer
crypto/zlib.c:160: warning: (near initialization for 'descriptor')
crypto/zlib.c:164: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:164: error: initializer element is not computable at load time
crypto/zlib.c:164: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:164: warning: excess elements in struct initializer
crypto/zlib.c:164: warning: (near initialization for 'descriptor')
crypto/zlib.c:169: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:169: error: initializer element is not computable at load time
crypto/zlib.c:169: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:169: warning: excess elements in struct initializer
crypto/zlib.c:169: warning: (near initialization for 'descriptor')
crypto/zlib.c: In function 'zlib_compress_final':
crypto/zlib.c:186: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:186: error: initializer element is not computable at load time
crypto/zlib.c:186: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:186: warning: excess elements in struct initializer
crypto/zlib.c:186: warning: (near initialization for 'descriptor')
crypto/zlib.c:194: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:194: error: initializer element is not computable at load time
crypto/zlib.c:194: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:194: warning: excess elements in struct initializer
crypto/zlib.c:194: warning: (near initialization for 'descriptor')
crypto/zlib.c:199: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:199: error: initializer element is not computable at load time
crypto/zlib.c:199: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:199: warning: excess elements in struct initializer
crypto/zlib.c:199: warning: (near initialization for 'descriptor')
crypto/zlib.c: In function 'zlib_decompress_update':
crypto/zlib.c:262: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:262: error: initializer element is not computable at load time
crypto/zlib.c:262: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:262: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:262: warning: excess elements in struct initializer
crypto/zlib.c:262: warning: (near initialization for 'descriptor')
crypto/zlib.c:275: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:275: error: initializer element is not computable at load time
crypto/zlib.c:275: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:275: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:275: warning: excess elements in struct initializer
crypto/zlib.c:275: warning: (near initialization for 'descriptor')
crypto/zlib.c:279: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:279: error: initializer element is not computable at load time
crypto/zlib.c:279: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:279: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:279: warning: excess elements in struct initializer
crypto/zlib.c:279: warning: (near initialization for 'descriptor')
crypto/zlib.c:284: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:284: error: initializer element is not computable at load time
crypto/zlib.c:284: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:284: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:284: warning: excess elements in struct initializer
crypto/zlib.c:284: warning: (near initialization for 'descriptor')
crypto/zlib.c: In function 'zlib_decompress_final':
crypto/zlib.c:301: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:301: error: initializer element is not computable at load time
crypto/zlib.c:301: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:301: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:301: warning: excess elements in struct initializer
crypto/zlib.c:301: warning: (near initialization for 'descriptor')
crypto/zlib.c:327: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:327: error: initializer element is not computable at load time
crypto/zlib.c:327: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:327: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:327: warning: excess elements in struct initializer
crypto/zlib.c:327: warning: (near initialization for 'descriptor')
crypto/zlib.c:332: warning: initialization makes integer from pointer without a cast
crypto/zlib.c:332: error: initializer element is not computable at load time
crypto/zlib.c:332: error: (near initialization for 'descriptor.primary_hash')
crypto/zlib.c:332: warning: large integer implicitly truncated to unsigned type
crypto/zlib.c:332: warning: excess elements in struct initializer
crypto/zlib.c:332: warning: (near initialization for 'descriptor')
make[1]: *** [crypto/zlib.o] Error 1
make: *** [crypto/zlib.o] Error 2

2009-10-01 22:58:06

by Joe Perches

[permalink] [raw]
Subject: [PATCH v2] dynamic_debug.h/kernel.h: Remove KBUILD_MODNAME from dynamic_pr_debug

On Thu, 2009-10-01 at 14:57 -0700, Andrew Morton wrote:
> x86_64 allmodconfig:
> crypto/zlib.c: In function 'zlib_compress_update':
> crypto/zlib.c:148: warning: initialization makes integer from pointer without a cast

Sigh... compiling just allyesconfig is not enough testing.

Defective patch fixed by moving the expansion of pr_fmt(fmt)
to the actual printk

Compiled crypto/zlib.o allyesconfig, allnoconfig, allmodconfig

---

If CONFIG_DYNAMIC_DEBUG is enabled and a source file has:

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>

dynamic_debug.h will duplicate KBUILD_MODNAME
in the output string.

Remove the use of KBUILD_MODNAME from the
output format string generated by dynamic_debug.h

If CONFIG_DYNAMIC_DEBUG is not enabled, no compile-time
check is done to printk/dev_printk arguments.

Add it.

Signed-off-by: Joe Perches <[email protected]>

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index a0d9422..f8c2e17 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -57,8 +57,7 @@ extern int ddebug_remove_module(char *mod_name);
{ KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
if (__dynamic_dbg_enabled(descriptor)) \
- printk(KERN_DEBUG KBUILD_MODNAME ":" pr_fmt(fmt), \
- ##__VA_ARGS__); \
+ printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
} while (0)


@@ -69,9 +68,7 @@ extern int ddebug_remove_module(char *mod_name);
{ KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
if (__dynamic_dbg_enabled(descriptor)) \
- dev_printk(KERN_DEBUG, dev, \
- KBUILD_MODNAME ": " fmt, \
- ##__VA_ARGS__); \
+ dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
} while (0)

#else
@@ -81,8 +78,10 @@ static inline int ddebug_remove_module(char *mod)
return 0;
}

-#define dynamic_pr_debug(fmt, ...) do { } while (0)
-#define dynamic_dev_dbg(dev, format, ...) do { } while (0)
+#define dynamic_pr_debug(fmt, ...) \
+ do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
+#define dynamic_dev_dbg(dev, format, ...) \
+ do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
#endif

#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d3cd23f..b0affed 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -398,9 +398,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#elif defined(CONFIG_DYNAMIC_DEBUG)
/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
-#define pr_debug(fmt, ...) do { \
- dynamic_pr_debug(fmt, ##__VA_ARGS__); \
- } while (0)
+#define pr_debug(fmt, ...) \
+ dynamic_pr_debug(fmt, ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) \
({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })