Re: [PATCH 1/3] CodingStyle updates

From: Randy Dunlap
Date: Sat Sep 29 2007 - 14:05:30 EST

On Fri, 28 Sep 2007 17:32:00 -0400 Erez Zadok wrote:

> 1. Updates chapter 13 (printing kernel messages) to expand on the use of
> pr_debug()/pr_info(), what to avoid, and how to hook your debug code with
> kernel.h.
> Signed-off-by: Erez Zadok <ezk@xxxxxxxxxxxxx>
> ---
> Documentation/CodingStyle | 88 +++++++++++++++++++++++++++++++++++++++++++-
> 1 files changed, 86 insertions(+), 2 deletions(-)
> diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
> index 7f1730f..00b29e4 100644
> --- a/Documentation/CodingStyle
> +++ b/Documentation/CodingStyle
> @@ -643,8 +643,26 @@ Printing numbers in parentheses (%d) adds no value and should be avoided.
> There are a number of driver model diagnostic macros in <linux/device.h>
> which you should use to make sure messages are matched to the right device
> and driver, and are tagged with the right level: dev_err(), dev_warn(),
> -dev_info(), and so forth. For messages that aren't associated with a
> -particular device, <linux/kernel.h> defines pr_debug() and pr_info().
> +dev_info(), and so forth.
> +
> +A number of people often like to define their own debugging printf's,
> +wrapping printk's in #ifdef's that get turned on only when subsystem
> +debugging is compiled in (e.g., dprintk, Dprintk, DPRINTK, etc.). Please
> +don't reinvent the wheel but use existing mechanisms. For messages that
> +aren't associated with a particular device, <linux/kernel.h> defines
> +pr_debug() and pr_info(); the latter two translate to printk(KERN_DEBUG) and
> +printk(KERN_INFO), respectively. However, to get pr_debug() to actually
> +emit the message, you'll need to turn on DEBUG in your code, which can be
> +done as follows in your subsystem Makefile:
> +
> +endif

Alternatively, that can be done in your source file, but doing this
in the Makefile makes good sense if you have more than one source file.
At any rate, it is done in some source files, and when it's done in
source files, #define-ing DEBUG should be done before #include
<linux/kernel.h> so that the macros are defined as expected.

> +In this way, you can create a Kconfig parameter to turn on debugging at
> +compile time, which will also turn on DEBUG, to enable pr_debug() to emit
> +actual messages; conversely, when CONFIG_WHATEVER_DEBUG is off, DEBUG is
> +off, and pr_debug() will display nothing.
> Coming up with good debugging messages can be quite a challenge; and once
> you have them, they can be a huge help for remote troubleshooting. Such

Phaedrus says that Quality is about caring.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at