18

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?

Yogesh
  • 740
  • 2
  • 7
  • 15

1 Answers1

22

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

Federico
  • 3,782
  • 32
  • 46
  • In that case I have 2 questions: 1. What exactly does netdev_dbg offer "in addition" to dev_dbg. 2. Also, is there a reason to use netdev_dbg() in this warning message(s) and not *subsystem*_dbg(). (I ask this because this message comes from checkpatch.pl - which is a generic script used in linux to check for "all" patches. Why does it particularly say netdev_dbg and not someething else?) – Yogesh Mar 01 '14 at 13:46
  • 1
    take a look at the source code and the git histry **(1)** this is what netdev_*() print out http://lxr.free-electrons.com/source/net/core/dev.c#L6717 **(2.1)** _8f26b8376faad26372a579606ecbd77b20e99dd8_ is the patch that introduce the warning message **(3)** I'm supposing that you are warking on a netdevice, so why netdev_dbg() should not be prefered?. **(4)** if you are not working on netdevice, maybe we have a problem. – Federico Mar 01 '14 at 14:35
  • Thanks for that. I did see 1 and 2.1. I am just not sure why netdev_dbg is preferred to other subsystems *_dbg calls (with respect to this message). As for (3) and (4), I am _NOT_ working on netdevice. In-fact, you can write the simplest "hello world" module(not even a device driver) and check it with checkpatch.pl. This warning message will pop up. – Yogesh Mar 01 '14 at 14:44
  • 1
    I improved my answer, take a look – Federico Mar 01 '14 at 15:35