Tools To Cleanup Linux Kernel

Today the count of patches I submitted to Linux kernel reached to 63. I used a lot of tools to submit patches to Linux kernel. This post will list all those tools that I used, how to use them and a bit more.

Here is the link to all my patches, that got accepted.

It is a script in the kernel tree that facilitates better kernel code, and can be used to check many coding style rules.When you git cloned the source, as explained here it comes inside the source, inside the folder scripts.Run it for the drivers present in staging directory :

perl scripts/ -f drivers/staging/rtl8712/* | less

This will gives you warnings and errors on the files of rtl8712 driver. Fix them and send a patch. Remember this script also gives false warnings. Do read git pre commit hooks here first, and run checkpatch on your patches before you send them.


Coccinelle is a program matching and transformation engine which provides the language SmPL (Semantic Patch Language) for specifying desired matches and transformations in C code.Coccinelle semantic patches are available in the “scripts” directory of Linux.Install it using:

sudo apt-get install coccinelle

Run your coccinelle script using, for all drivers in staging and all its files.

spatch --sp-file a.cocci */

You can use –in_place, -patch flags to make the change in place.


Install it using :

sudo apt-get install sparse

This is a very good link about getting started with sparse for kernel newbies.

Run it using:

make C=2 CF=-D__CHECK_ENDIAN__ drivers/staging/wlan-ng/ -Wunused-function

Here are some more flags that sparse has, use them to find more issues in the code.


Install it using:

sudo apt-get install flawfinder

Run it like :

flawfinder directory_having_the_source_code

You can store it’s output in a file

flawfinder directory_having_the_source_code  warnings.txt

# to redirect standard output to a file


Smatch is a static analysis tool for C. Most of the checks are for the linux kernel. Here is the public git repository.To install smatch :

git clone git://
cd smatch
sudo make install

If you get some error like after the make itself:

/usr/bin/ld: cannot find -lsqlite3
collect2: ld returned 1 exit status
make: *** [test-lexing] Error 1

Install this first:

sudo apt-get install libsqlite3-dev

Run it one kernel code using:

make clean
make CHECK=~/path/to/smatch/smatch -p=kernel C=1 bzImage modules | tee warns.txt
#tee command is used to store and view (both at the same time) the output of any other command.


It’s a source code beautifier, you can use it to align code for linux kernel. Here, is the configuration file for linux kernel, modify it as per your needs.

To install

sudo apt-get install uncrustify

Run it like:

uncrustify -c path/to/linux.cfg --replace foo.c

Here –replace is to replace the code in place.


A Coccinelle-specific target is defined in the top level
Makefile. This target is named ‘coccicheck’ and calls the ‘coccicheck’
front-end in the ‘scripts’ directory.

To make a report for every semantic patch, run the following command

make coccicheck MODE=report

To produce patches, run:

make coccicheck MODE=patch

More is up here.

#bugs, #coccinelle, #errors, #failure, #falwfinder, #fault, #flaws, #linux-kernel, #smatch, #sparse