I recently ran a the scripts/checkpatch.pl script within the linux source tree and got this Warning:
WARNING: Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ...
printk(KERN_DEBUG "Hello World! \n");
I understand that the dynamic debugging interface offered by pr_debug and dev_dbg has obvious advantages to printk and therefore they are preferred to printk.
Even amongst dev_dbg and pr_debug, we prefer dev_dbg if we have a struct device to standardize device information output along with our debug message. It offers escape from the "edit/rebuild/reboot cycle" and also allows to maintain a neat log through dynamic_debug/control interface.
My question is: Why is netdev_dbg preferred to dev_dbg?
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.
netdev_dbg
it is not the absolutly prefered print style. It is prefered if you are working with a netdevice. If you take a look at the source code here you will see that it is required a struct netdevice
object, and you have this kind of object only if you are working in the network subsystem
Probably the message is confuse because it should suggest you to use the printing method of the subsystem where you are working on. 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With