A last but important point regarding the kernel printk; pretty often, to give context to your printk() output (where exactly did it occur?), you might write the code like this, taking advantage of various gcc macros (like __FILE__, __func__, and __LINE__):
pr_warning("%s:%s():%d: kmalloc failed!\n", OURMODNAME, __func__, __LINE__);
This is fine; the problem is, if there are a lot of printk's in your project, it can be fairly painful to guarantee a standard printk format (for example, first displaying the module name followed by the function name and possibly the line number, as seen here) is always followed by everyone working on the project.
Enter the pr_fmt macro; defining this macro right at the beginning of your code (it must be even before the first #include), guarantees that every single subsequent printk in your code will be prefixed with the format specified by this macro. Lets take an example (we show...