GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / Documentation / coccinelle.txt
blobcd2b0283706683423afe9a95a7827e79afe020a0
1 Copyright 2010 Nicolas Palix <npalix@diku.dk>
2 Copyright 2010 Julia Lawall <julia@diku.dk>
3 Copyright 2010 Gilles Muller <Gilles.Muller@lip6.fr>
6  Getting Coccinelle
7 ~~~~~~~~~~~~~~~~~~~~
9 The semantic patches included in the kernel use the 'virtual rule'
10 feature which was introduced in Coccinelle version 0.1.11.
12 Coccinelle (>=0.2.0) is available through the package manager
13 of many distributions, e.g. :
15  - Debian (>=squeeze)
16  - Fedora (>=13)
17  - Ubuntu (>=10.04 Lucid Lynx)
18  - OpenSUSE
19  - Arch Linux
20  - NetBSD
21  - FreeBSD
24 You can get the latest version released from the Coccinelle homepage at
25 http://coccinelle.lip6.fr/
27 Once you have it, run the following command:
29         ./configure
30         make
32 as a regular user, and install it with
34         sudo make install
37  Using Coccinelle on the Linux kernel
38 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40 A Coccinelle-specific target is defined in the top level
41 Makefile. This target is named 'coccicheck' and calls the 'coccicheck'
42 front-end in the 'scripts' directory.
44 Four modes are defined: report, patch, context, and org. The mode to
45 use is specified by setting the MODE variable with 'MODE=<mode>'.
47 'report' generates a list in the following format:
48   file:line:column-column: message
50 'patch' proposes a fix, when possible.
52 'context' highlights lines of interest and their context in a
53 diff-like style.Lines of interest are indicated with '-'.
55 'org' generates a report in the Org mode format of Emacs.
57 Note that not all semantic patches implement all modes.
59 To make a report for every semantic patch, run the following command:
61         make coccicheck MODE=report
63 NB: The 'report' mode is the default one.
65 To produce patches, run:
67         make coccicheck MODE=patch
70 The coccicheck target applies every semantic patch available in the
71 subdirectories of 'scripts/coccinelle' to the entire Linux kernel.
73 For each semantic patch, a changelog message is proposed.  It gives a
74 description of the problem being checked by the semantic patch, and
75 includes a reference to Coccinelle.
77 As any static code analyzer, Coccinelle produces false
78 positives. Thus, reports must be carefully checked, and patches
79 reviewed.
82  Using Coccinelle with a single semantic patch
83 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 The optional make variable COCCI can be used to check a single
86 semantic patch. In that case, the variable must be initialized with
87 the name of the semantic patch to apply.
89 For instance:
91         make coccicheck COCCI=<my_SP.cocci> MODE=patch
93         make coccicheck COCCI=<my_SP.cocci> MODE=report
96  Proposing new semantic patches
97 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99 New semantic patches can be proposed and submitted by kernel
100 developers. For sake of clarity, they should be organized in the
101 subdirectories of 'scripts/coccinelle/'.
104  Detailed description of the 'report' mode
105 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 'report' generates a list in the following format:
108   file:line:column-column: message
110 Example:
112 Running
114         make coccicheck MODE=report COCCI=scripts/coccinelle/err_cast.cocci
116 will execute the following part of the SmPL script.
118 <smpl>
119 @r depends on !context && !patch && (org || report)@
120 expression x;
121 position p;
124  ERR_PTR@p(PTR_ERR(x))
126 @script:python depends on report@
127 p << r.p;
128 x << r.x;
131 msg="ERR_CAST can be used with %s" % (x)
132 coccilib.report.print_report(p[0], msg)
133 </smpl>
135 This SmPL excerpt generates entries on the standard output, as
136 illustrated below:
138 /home/user/linux/crypto/ctr.c:188:9-16: ERR_CAST can be used with alg
139 /home/user/linux/crypto/authenc.c:619:9-16: ERR_CAST can be used with auth
140 /home/user/linux/crypto/xts.c:227:9-16: ERR_CAST can be used with alg
143  Detailed description of the 'patch' mode
144 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 When the 'patch' mode is available, it proposes a fix for each problem
147 identified.
149 Example:
151 Running
152         make coccicheck MODE=patch COCCI=scripts/coccinelle/err_cast.cocci
154 will execute the following part of the SmPL script.
156 <smpl>
157 @ depends on !context && patch && !org && !report @
158 expression x;
161 - ERR_PTR(PTR_ERR(x))
162 + ERR_CAST(x)
163 </smpl>
165 This SmPL excerpt generates patch hunks on the standard output, as
166 illustrated below:
168 diff -u -p a/crypto/ctr.c b/crypto/ctr.c
169 --- a/crypto/ctr.c 2010-05-26 10:49:38.000000000 +0200
170 +++ b/crypto/ctr.c 2010-06-03 23:44:49.000000000 +0200
171 @@ -185,7 +185,7 @@ static struct crypto_instance *crypto_ct
172         alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
173                                   CRYPTO_ALG_TYPE_MASK);
174         if (IS_ERR(alg))
175 -               return ERR_PTR(PTR_ERR(alg));
176 +               return ERR_CAST(alg);
178         /* Block size must be >= 4 bytes. */
179         err = -EINVAL;
181  Detailed description of the 'context' mode
182 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184 'context' highlights lines of interest and their context
185 in a diff-like style.
187 NOTE: The diff-like output generated is NOT an applicable patch. The
188       intent of the 'context' mode is to highlight the important lines
189       (annotated with minus, '-') and gives some surrounding context
190       lines around. This output can be used with the diff mode of
191       Emacs to review the code.
193 Example:
195 Running
196         make coccicheck MODE=context COCCI=scripts/coccinelle/err_cast.cocci
198 will execute the following part of the SmPL script.
200 <smpl>
201 @ depends on context && !patch && !org && !report@
202 expression x;
205 * ERR_PTR(PTR_ERR(x))
206 </smpl>
208 This SmPL excerpt generates diff hunks on the standard output, as
209 illustrated below:
211 diff -u -p /home/user/linux/crypto/ctr.c /tmp/nothing
212 --- /home/user/linux/crypto/ctr.c       2010-05-26 10:49:38.000000000 +0200
213 +++ /tmp/nothing
214 @@ -185,7 +185,6 @@ static struct crypto_instance *crypto_ct
215         alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
216                                   CRYPTO_ALG_TYPE_MASK);
217         if (IS_ERR(alg))
218 -               return ERR_PTR(PTR_ERR(alg));
220         /* Block size must be >= 4 bytes. */
221         err = -EINVAL;
223  Detailed description of the 'org' mode
224 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226 'org' generates a report in the Org mode format of Emacs.
228 Example:
230 Running
231         make coccicheck MODE=org COCCI=scripts/coccinelle/err_cast.cocci
233 will execute the following part of the SmPL script.
235 <smpl>
236 @r depends on !context && !patch && (org || report)@
237 expression x;
238 position p;
241  ERR_PTR@p(PTR_ERR(x))
243 @script:python depends on org@
244 p << r.p;
245 x << r.x;
248 msg="ERR_CAST can be used with %s" % (x)
249 msg_safe=msg.replace("[","@(").replace("]",")")
250 coccilib.org.print_todo(p[0], msg_safe)
251 </smpl>
253 This SmPL excerpt generates Org entries on the standard output, as
254 illustrated below:
256 * TODO [[view:/home/user/linux/crypto/ctr.c::face=ovl-face1::linb=188::colb=9::cole=16][ERR_CAST can be used with alg]]
257 * TODO [[view:/home/user/linux/crypto/authenc.c::face=ovl-face1::linb=619::colb=9::cole=16][ERR_CAST can be used with auth]]
258 * TODO [[view:/home/user/linux/crypto/xts.c::face=ovl-face1::linb=227::colb=9::cole=16][ERR_CAST can be used with alg]]