Coccinelle is a regular expression matching tool for text pattern conversion.
Get Coccinelle
Most Linux forks have this tool.
- Debian
- Fedora
- Ubuntu
- OpenSUSE
- Arch Linux
- NetBSD
- FreeBSD
You can also download the latest version from http://coccinelle.lip6.fr/ and execute:
./configure make
If you are a normal user, installation requires:
sudo make install
Using Coccinelle in the Linux Kernel
A Coccinelle-specific target is defined in the top-level makefile, the target is named coccicheck, and coccicheck is called backwards in the scripts directory.
4 modes are supported:
- patch: If possible, provide a fix suggestion.
- report: generate a list of reports with file:line:column-column:message
- context: Highlight the lines of interest, and mark the lines of interest with -.
- org: Generate reports in Emacs' Org mode format.
For simplicity of use, the default mode is report. There are also two other modes that are hybrid modes:
- chain: Attempts to execute in the above order until one succeeds.
- rep+ctxt: Execute the report and context modes in turn, and add a C option, so that the code can be checked based on the file.
Coccinelle Parallelization
By default coccicheck runs as best-effort parallelism as possible. To change the parallelization behavior, use the J variable. For example, running on 4 CPUs
make coccicheck MODE=report J=4
Control which files Coccinelle processes
By default, the entire kernel source tree needs to be checked. M= can be used to specify the directory to process. For example, only check driver/net/wireless/
make coccicheck M=drivers/net/wireless/
If the specified file can be
make C=1 CHECK="scripts/coccicheck"
If checking only newly edited code, you can use the value 2 or the C flag.
make C=2 CHECK="scripts/coccicheck"