Linux Kernel – Tools/Scripts

Here are few tools/scripts which are useful for static analysis of code: Checkpatch # ./script/checkpath.pl <patch_file(s)> # ./script/checkpatch.pl –file <file_name(s)> cppcheck # sudo apt-get install cppcheck # cppcheck <source-dir> Sparse # make C=1 /* Run Sparse on files being compiled */ # make C=2 /* Run Sparse on files all files */ read https://www.kernel.org/doc/Documentation/sparse.txt for […]

How to check Memory Leak in linux kernel

Compile kernel with CONFIG_DEBUG_KMEMLEAK=y #CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=4096 Mount debugfs (if it is not mounted) mount -t debugfs nodev /sys/kernel/debug/ Check memory leaks # echo scan > /sys/kernel/debug/kmemleak # cat /sys/kernel/debug/kmemleak Example Trace: unreferenced object 0xffff88021481d600 (size 16): comm “swapper/0”, pid 1, jiffies 4294667622 (age 9531.310s) hex dump (first 16 bytes): 70 6e 70 20 30 30 […]