Passing parameters to a kernel module
A common debugging technique is to instrument your code; that is, insert prints at appropriate points such that you can follow the path the code takes. Within a kernel module, of course, we would use the versatile printk
(and friends) functions for this purpose. So, let’s say we do something like the following (pseudo-code):
#define pr_fmt(fmt) "%s:%s():%d: " fmt, KBUILD_MODNAME, __func__, __LINE__
[ ... ]
func_x() {
pr_debug("At 1\n");
[...]
while (<cond>) {
pr_debug("At 2: j=0x%x\n", j);
[...]
}
[...]
}
Okay, great. But, hey, we don’t want the debug prints to appear in a production (or release) version. That’s precisely why we’re using pr_debug()
: it emits a printk only when the DEBUG
symbol is defined! Indeed, but what if, interestingly, our customer is an engineering customer and wants to dynamically turn on or turn off these debug prints...