Linux-Kernel-Internals - Linux Kernel Internals: https://ankitkdev.com/blog/ - Char Driver: https://ankitkdev.com/blog/linux-kernel/device-driver/char-driver/ - Ioctl Interface: https://ankitkdev.com/blog/linux-kernel/device-driver/ioctl/ - Proc-Interface: https://ankitkdev.com/blog/linux-kernel/device-driver/proc/ - Completion-Variable: https://ankitkdev.com/blog/linux-kernel/concurrency/completion-variable/ - container_of(): https://ankitkdev.com/blog/linux-kernel/macros/container_of/ - Module Parameters: https://ankitkdev.com/blog/linux-kernel/macros/kernel-module/ - pr_fmt(): https://ankitkdev.com/blog/linux-kernel/macros/pr-family/ - Stringification: https://ankitkdev.com/blog/linux-kernel/macros/string/ - Debugging Macros: https://ankitkdev.com/blog/linux-kernel/macros/debug/ - Error Handling with Pointers: https://ankitkdev.com/blog/kernal-internals/error-handling/ - Kbuild Makefile: https://ankitkdev.com/blog/kernal-internals/kbuild/ - SLUB debug: https://ankitkdev.com/blog/kernel-debugging/debug-slub-memory/ - unsigned :\ 0 Bit-Fields in c: https://ankitkdev.com/blog/c/zero-width-bit-field/ - do { ... } while (0): https://ankitkdev.com/blog/c/do-while-loop/ - Error Handling: https://ankitkdev.com/blog/c/error-handling/ - C Memory Layout: https://ankitkdev.com/blog/c/c-memory-layout/ - Forward Declarations: https://ankitkdev.com/blog/c/forward-declaration-in-c/ - Return value by Macro: https://ankitkdev.com/blog/c/return-by-macro/ - Variadic Macro: https://ankitkdev.com/blog/c/variadic-macro/ - programming concepts: https://ankitkdev.com/blog/theory/ - Build & Install Linux Kernel for BBB: https://ankitkdev.com/blog/misc/build-linux-kernel-BBB/ - Configure U-boot for BBB: https://ankitkdev.com/blog/misc/configure-uboot-bbb/ - Install Ubuntu Server on Qemu: https://ankitkdev.com/blog/misc/install-ubuntu-server-on-qemu/ - Linux Kernel Mentorship Program: https://ankitkdev.com/blog/misc/linux-kernel-mentorship-program/ ## `pr_fmt()` ### Prefixing the `pr_*()` calls `pr_fmt()` is a macro that rewrites the format string of every `pr_*()` call (`pr_info`, `pr_warn`, `pr_err`, ...) in the file. It has to be defined **before** any header that pulls in ``, so it always sits at the very top, above your includes. ```c #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ #include #include static int func(void) { pr_warn("hello-world\n"); return -1; } ``` `pr_fmt()` line auto-adjusts to whichever function it's expanded in. Expands to roughly: ```c printk(KERN_WARNING "hello-world\n"); ``` Without `pr_fmt()`, every `pr_*()` line falls back to the default `"%s"`, no module or function context, so you're stuck grepping `dmesg` blind. With it, every log line self-identifies: ``` [ 12.482103] module_name:func: hello-world ``` > Default fallback is `#define pr_fmt(fmt) fmt`, just the format string, untouched, if you never define your own. > and only affects the `pr_*()` family, not raw `printk(KERN_WARNING ...)` calls.