checkpatch.pl is a perl script to verify that your code conforms to the Linux kernel coding style. If you are an aspiring kernel dev, you must be very careful that you follow the right coding guidelines. It’s difficult to get it right the first time because you may need to unlearn a few practices learnt over years of coding. checkpatch.pl assists you in the process. This article explores how to check the coding style (and spelling etc.) of a dummy kernel module implemented in sample_module.c.
$ chmod +c checkpatch.pl $ ./checkpatch.pl --no-tree -f sample_module.c
–no-tree : By default checkpatch must be run from the top-level dir. of a kernel tree. This option overrides the default behaviour.
-f : By default checkpatch verifies kernel patches. This option instructs it to treat the file as a regular source file.
Take a look at other available options:
$ ./checkpatch.pl --help
And finally, the sample output for our module:
$ ./checkpatch.pl --no-tree -f sample_module.c WARNING: void function return statements are not generally useful #35: FILE: coding_style.c:35: + return; +} total: 0 errors, 1 warnings, 38 lines checked coding_style.c has style problems, please review. If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.