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");
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@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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
The short answer: use pr_debug instead of printk. The long answer: (This is the answer I got from stackoverflow question that I had asked for similar question I was having:) Each kernel subsystem usually has its own printk format. So when you are using network subsystem, you have to use netdev_dbg; when you are using V4L you have to use v4l_dbg. It standardizes the output format within the subsystem. ... You have got the warning because you are using prink() which is the raw way to print something. Depending on what you are coding you should use a different print style: printk(): never pr_debug(): always good dev_dbg(): prefered when you have a struct device object netdev_dbg(): prefered when you have a struct netdevice object [something]_dbg(): prefered when you have a that something object For the full answer see https://stackoverflow.com/questions/22077540/order-of-preference-printk-vs-d... --- Yogesh On 5 April 2014 10:32, HABI S RAVI <habisbc@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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- DREAM IT, CODE IT
Short answer: Use pr_debug instead of printk. On 5 Apr 2014 07:06, "HABI S RAVI" <habisbc@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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (4)
-
Anand Moon -
HABI S RAVI -
Kristofer Hallin -
Yogesh Chaudhari