kchecker - check your kernel code

kchecker is a Static source code check tools. It can find some buggy kmalloc usage and 

You can get this tool under http://repo.or.cz/w/smatch.git

git clone git://repo.or.cz/smatch.git

cd smatch
make -j4
sudo make install

After then, you can find kchecker under ./smatch_scripts/kchecker.
Lets try it.

x@x-desktop:$kchecker  --spammy  fs/ubifs/journal.c
  CHK     include/linux/version.h
make[1]: “include/asm-arm/mach-types.h” is latest
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-arm
  CALL    scripts/checksyscalls.sh
  CHECK   fs/ubifs/journal.c
fs/ubifs/journal.c +233 reserve_space(118) warn: inconsistent returns mutex:&wbuf->io_mutex: locked (136,202,215) unlocked (169,184,219,233)
  CC      fs/ubifs/journal.o

This script find some wrong usage of mutex. Lets have another try:

x@x-desktop$ kchecker --spammy drivers/video/mxc/mxc_ipuv3_fb.c

  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-arm
  CALL    scripts/checksyscalls.sh
  CHECK   drivers/video/mxc/mxc_ipuv3_fb.c
drivers/video/mxc/mxc_ipuv3_fb.c +875 mxcfb_ioctl(181) warn: possible memory leak of 'mem'
drivers/video/mxc/mxc_ipuv3_fb.c +992 mxcfb_ioctl(298) warn: 'sem:&mxc_fbi->alpha_flip_sem' is sometimes locked here and sometimes unlocked.
drivers/video/mxc/mxc_ipuv3_fb.c +1541 mxcfb_remove(5) warn: variable dereferenced before check 'fbi'
  CC      drivers/video/mxc/mxc_ipuv3_fb.o

This time, it found some possible memory leak. And some buggy lock usage.

Have fun with this tool...

BTW, This link http://smatch.sourceforge.net/ shows how to check at compile all kernel code.