Code Style issue
Anand Moon
moon.linux at yahoo.com
Sat Apr 5 02:18:53 EDT 2014
Hi Habi S Ravi,
The pr_* macros (with exception of pr_debug) are simple shorthand definitions
in include/linux/printk.h for their respective printk call and should probably be used in newer drivers.
pr_devel and pr_debug are replaced with printk(KERN_DEBUG ... if the kernel was
compiled with DEBUG, otherwise replaced with an empty statement.
For drivers the pr_debug should not be used anymore (use dev_dbg instead).
if you include the following line on top of the code
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
you will be able to get the name of the module printed along with the message on the console
or in kernel logs depending on the priority. This is good coding pratice to indentify bugs.
-Anand Moon
On Saturday, April 5, 2014 10:52 AM, HABI S RAVI <habisbc at gmail.com> wrote:
Hi,
I am trying to fix a coding issue . I get the following warning when my module is checked with checkpatch.pl.
How can i remove the warning. I see a lot of drivers using printk() function.
$ perl ~/linux-stable/scripts/checkpatch.pl -f hello.c
WARNING: Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then
pr_debug(... to printk(KERN_DEBUG ...
#6: FILE: hello.c:6:
+ printk(KERN_DEBUG "Hello World!\n");
WARNING: Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then
pr_debug(... to printk(KERN_DEBUG ...
#12: FILE: hello.c:12:
+ printk(KERN_DEBUG "hello module unloaded\n");
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
More information about the Kernelnewbies
mailing list