From mboxrd@z Thu Jan 1 00:00:00 1970 From: greg@kroah.com (Greg KH) Date: Sun, 30 Jan 2011 13:35:29 -0800 Subject: motivation behind pr_xxx macros In-Reply-To: References: Message-ID: <20110130213529.GA25128@kroah.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Sun, Jan 30, 2011 at 08:41:14PM +0530, Himanshu Aggarwal wrote: > While writing some code on 2.6.32, I have come across some of these > macros that in turn call printk: > > pr_emerg > pr_alert > ... > pr_debug > > Is there any case when should these macros be preferred over explicit > printk statements? Yes, for almost all usages, use them instead of printk(). > What is the motivation behind providing these > macros when this task can already be accomplished by using printk > statements explicitly with priority levels? It forces you to actually specify a level (which people sometimes forget) and it ties you into the dynamic debugging logic (with the pr_debug() call) and it provides a common prefix specifying your exact module that is creating the output. But even better, please use the dev_* functions instead, whereever you have access to a struct device * as that uniquely identifies both your module, and your device, in a standard way that userspace can understand, and it ties into the dynamic debugging infrastructure as well. But for those few places where you don't have a struct device *, use the pr_* functions instead please and not "raw" printk() calls. Hope this helps, greg k-h