= WHAT IS SPARSE = Sparse is a tool for static code analysis that helps kernel developers to detect coding errors. Kernel code that is prone to mistakes is annotated by kernel developers using __attribute__ specifiers. Sparse tool uses these specifiers to pinpoint coding mistakes. = HOW TO INSTALL SPARSE = The best way to install sparse is using the package manager of your linux distro. That way, in case you want later to uninstall sparse, you won't need to cleanup executable files manually. For instance, if you have Ubuntu, to install sparse do: {{{ $ sudo apt-get install sparse}}} And, to remove it, do: {{{ $ sudo apt-get remove sparse}}} If your distro does not provide a precompiled package for sparse, either you can create one or proceed with a manual installation. For example, if you use Arch linux, you can download the package from AUR: https://aur.archlinux.org/packages/sparse/ There, you will find a link from where you can download the sparse source code: http://www.kernel.org/pub/software/devel/sparse/dist/sparse-0.4.4.tar.gz To decompress the sparse-0.4.4.tar.gz file, do: $ tar -xzvf sparse-0.4.4.tar.gz Then, enter sparse-0.4.4 directory: $ cd sparse-0.4.4/ Now, you need to create a file, called PKGBUILD, and copy the contents of the PKGBUILD file found in AUR. To create the package, do: $ makepkg -s To install it, do: $ sudo pacman -U .pkg.tar.gz To unistall it, do: $ sudo pacman -R sparse To install sparse manually follow the steps below. You can download sparse from the following git repository: git://git.kernel.org/pub/scm/devel/sparse/sparse.git By doing: $ git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git This will create in your current directory a subdirectory, called 'sparse', which contains the sparse source code. Enter sparse directory: $ cd sparse To see the available releases, do: $ git tag Choose the last stable release (v0.4.4) and update the files of the current sparse git tree to match this release: $ git checkout -b stable v0.4.4 The above command creates a new branch, named 'stable', which refers to the tagged commit 'v0.4.4' and then updates the tree to refer to this branch. To build sparse, do: $ make To install it, set in the Makefile the desirable destination directoty for the installation by changing the line PREFIX=$(HOME). For instance, you can change it into PREFIX=$(HOME)/sparse or PREFIX=/usr and then, to install it do: $ make install If you have installed sparse, in a directory out of your executable search path, you need to setup the environmental variable PATH to include the directory in which sparse executable has been placed. For instance, if you had set PREFIX=$(HOME)/sparse, do: $ export PATH=$PATH:$HOME/sparse/bin To setup permanently the path, do: $ echo 'export PATH=$PATH:$HOME/sparse/bin' >> ~/.bashrc To see if sparse can be successfully located, do: $ which sparse = HOW TO USE SPARSE = Choose a subdirectory in the kernel tree that you want to check for sparse warnings and errors, for instance drivers/staging/wlan-ng, and do: $ make C=2 drivers/staging/wlan-ng/ You can use the variable CF to pass more checkflags to sparse. For example, you can enable endian checks doing: $ make C=2 CF="-D__CHECK_ENDIAN__" drivers/staging/wlan-ng/ You can observe what are the default checkflags set in the Makefile. You will see something close to the following: CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void $(CF) More documentation on sparse can be found in Documentation/sparse.txt and the links below: http://kernel.org/pub/software/devel/sparse/dist/sparse-0.4.tar.gz https://sparse.wiki.kernel.org/index.php/Main_Page http://en.wikipedia.org/wiki/Sparse