summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/dev-tools/coccinelle.rst (renamed from Documentation/coccinelle.txt)359
-rw-r--r--Documentation/dev-tools/tools.rst1
-rw-r--r--MAINTAINERS2
3 files changed, 192 insertions, 170 deletions
diff --git a/Documentation/coccinelle.txt b/Documentation/dev-tools/coccinelle.rst
index 01fb1dae3163..4a64b4c69d3f 100644
--- a/Documentation/coccinelle.txt
+++ b/Documentation/dev-tools/coccinelle.rst
@@ -1,10 +1,18 @@
1Copyright 2010 Nicolas Palix <npalix@diku.dk> 1.. Copyright 2010 Nicolas Palix <npalix@diku.dk>
2Copyright 2010 Julia Lawall <julia@diku.dk> 2.. Copyright 2010 Julia Lawall <julia@diku.dk>
3Copyright 2010 Gilles Muller <Gilles.Muller@lip6.fr> 3.. Copyright 2010 Gilles Muller <Gilles.Muller@lip6.fr>
4 4
5.. highlight:: none
5 6
6 Getting Coccinelle 7Coccinelle
7~~~~~~~~~~~~~~~~~~~~ 8==========
9
10Coccinelle is a tool for pattern matching and text transformation that has
11many uses in kernel development, including the application of complex,
12tree-wide patches and detection of problematic programming patterns.
13
14Getting Coccinelle
15-------------------
8 16
9The semantic patches included in the kernel use features and options 17The semantic patches included in the kernel use features and options
10which are provided by Coccinelle version 1.0.0-rc11 and above. 18which are provided by Coccinelle version 1.0.0-rc11 and above.
@@ -22,24 +30,23 @@ of many distributions, e.g. :
22 - NetBSD 30 - NetBSD
23 - FreeBSD 31 - FreeBSD
24 32
25
26You can get the latest version released from the Coccinelle homepage at 33You can get the latest version released from the Coccinelle homepage at
27http://coccinelle.lip6.fr/ 34http://coccinelle.lip6.fr/
28 35
29Information and tips about Coccinelle are also provided on the wiki 36Information and tips about Coccinelle are also provided on the wiki
30pages at http://cocci.ekstranet.diku.dk/wiki/doku.php 37pages at http://cocci.ekstranet.diku.dk/wiki/doku.php
31 38
32Once you have it, run the following command: 39Once you have it, run the following command::
33 40
34 ./configure 41 ./configure
35 make 42 make
36 43
37as a regular user, and install it with 44as a regular user, and install it with::
38 45
39 sudo make install 46 sudo make install
40 47
41 Supplemental documentation 48Supplemental documentation
42~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49---------------------------
43 50
44For supplemental documentation refer to the wiki: 51For supplemental documentation refer to the wiki:
45 52
@@ -47,49 +54,52 @@ https://bottest.wiki.kernel.org/coccicheck
47 54
48The wiki documentation always refers to the linux-next version of the script. 55The wiki documentation always refers to the linux-next version of the script.
49 56
50 Using Coccinelle on the Linux kernel 57Using Coccinelle on the Linux kernel
51~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 58------------------------------------
52 59
53A Coccinelle-specific target is defined in the top level 60A Coccinelle-specific target is defined in the top level
54Makefile. This target is named 'coccicheck' and calls the 'coccicheck' 61Makefile. This target is named ``coccicheck`` and calls the ``coccicheck``
55front-end in the 'scripts' directory. 62front-end in the ``scripts`` directory.
56 63
57Four basic modes are defined: patch, report, context, and org. The mode to 64Four basic modes are defined: ``patch``, ``report``, ``context``, and
58use is specified by setting the MODE variable with 'MODE=<mode>'. 65``org``. The mode to use is specified by setting the MODE variable with
66``MODE=<mode>``.
59 67
60'patch' proposes a fix, when possible. 68- ``patch`` proposes a fix, when possible.
61 69
62'report' generates a list in the following format: 70- ``report`` generates a list in the following format:
63 file:line:column-column: message 71 file:line:column-column: message
64 72
65'context' highlights lines of interest and their context in a 73- ``context`` highlights lines of interest and their context in a
66diff-like style.Lines of interest are indicated with '-'. 74 diff-like style.Lines of interest are indicated with ``-``.
67 75
68'org' generates a report in the Org mode format of Emacs. 76- ``org`` generates a report in the Org mode format of Emacs.
69 77
70Note that not all semantic patches implement all modes. For easy use 78Note that not all semantic patches implement all modes. For easy use
71of Coccinelle, the default mode is "report". 79of Coccinelle, the default mode is "report".
72 80
73Two other modes provide some common combinations of these modes. 81Two other modes provide some common combinations of these modes.
74 82
75'chain' tries the previous modes in the order above until one succeeds. 83- ``chain`` tries the previous modes in the order above until one succeeds.
84
85- ``rep+ctxt`` runs successively the report mode and the context mode.
86 It should be used with the C option (described later)
87 which checks the code on a file basis.
76 88
77'rep+ctxt' runs successively the report mode and the context mode. 89Examples
78 It should be used with the C option (described later) 90~~~~~~~~
79 which checks the code on a file basis.
80 91
81Examples: 92To make a report for every semantic patch, run the following command::
82 To make a report for every semantic patch, run the following command:
83 93
84 make coccicheck MODE=report 94 make coccicheck MODE=report
85 95
86 To produce patches, run: 96To produce patches, run::
87 97
88 make coccicheck MODE=patch 98 make coccicheck MODE=patch
89 99
90 100
91The coccicheck target applies every semantic patch available in the 101The coccicheck target applies every semantic patch available in the
92sub-directories of 'scripts/coccinelle' to the entire Linux kernel. 102sub-directories of ``scripts/coccinelle`` to the entire Linux kernel.
93 103
94For each semantic patch, a commit message is proposed. It gives a 104For each semantic patch, a commit message is proposed. It gives a
95description of the problem being checked by the semantic patch, and 105description of the problem being checked by the semantic patch, and
@@ -99,15 +109,15 @@ As any static code analyzer, Coccinelle produces false
99positives. Thus, reports must be carefully checked, and patches 109positives. Thus, reports must be carefully checked, and patches
100reviewed. 110reviewed.
101 111
102To enable verbose messages set the V= variable, for example: 112To enable verbose messages set the V= variable, for example::
103 113
104 make coccicheck MODE=report V=1 114 make coccicheck MODE=report V=1
105 115
106 Coccinelle parallelization 116Coccinelle parallelization
107~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 117---------------------------
108 118
109By default, coccicheck tries to run as parallel as possible. To change 119By default, coccicheck tries to run as parallel as possible. To change
110the parallelism, set the J= variable. For example, to run across 4 CPUs: 120the parallelism, set the J= variable. For example, to run across 4 CPUs::
111 121
112 make coccicheck MODE=report J=4 122 make coccicheck MODE=report J=4
113 123
@@ -115,44 +125,47 @@ As of Coccinelle 1.0.2 Coccinelle uses Ocaml parmap for parallelization,
115if support for this is detected you will benefit from parmap parallelization. 125if support for this is detected you will benefit from parmap parallelization.
116 126
117When parmap is enabled coccicheck will enable dynamic load balancing by using 127When parmap is enabled coccicheck will enable dynamic load balancing by using
118'--chunksize 1' argument, this ensures we keep feeding threads with work 128``--chunksize 1`` argument, this ensures we keep feeding threads with work
119one by one, so that we avoid the situation where most work gets done by only 129one by one, so that we avoid the situation where most work gets done by only
120a few threads. With dynamic load balancing, if a thread finishes early we keep 130a few threads. With dynamic load balancing, if a thread finishes early we keep
121feeding it more work. 131feeding it more work.
122 132
123When parmap is enabled, if an error occurs in Coccinelle, this error 133When parmap is enabled, if an error occurs in Coccinelle, this error
124value is propagated back, the return value of the 'make coccicheck' 134value is propagated back, the return value of the ``make coccicheck``
125captures this return value. 135captures this return value.
126 136
127 Using Coccinelle with a single semantic patch 137Using Coccinelle with a single semantic patch
128~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 138---------------------------------------------
129 139
130The optional make variable COCCI can be used to check a single 140The optional make variable COCCI can be used to check a single
131semantic patch. In that case, the variable must be initialized with 141semantic patch. In that case, the variable must be initialized with
132the name of the semantic patch to apply. 142the name of the semantic patch to apply.
133 143
134For instance: 144For instance::
135 145
136 make coccicheck COCCI=<my_SP.cocci> MODE=patch 146 make coccicheck COCCI=<my_SP.cocci> MODE=patch
137or 147
148or::
149
138 make coccicheck COCCI=<my_SP.cocci> MODE=report 150 make coccicheck COCCI=<my_SP.cocci> MODE=report
139 151
140 152
141 Controlling Which Files are Processed by Coccinelle 153Controlling Which Files are Processed by Coccinelle
142~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 154---------------------------------------------------
155
143By default the entire kernel source tree is checked. 156By default the entire kernel source tree is checked.
144 157
145To apply Coccinelle to a specific directory, M= can be used. 158To apply Coccinelle to a specific directory, ``M=`` can be used.
146For example, to check drivers/net/wireless/ one may write: 159For example, to check drivers/net/wireless/ one may write::
147 160
148 make coccicheck M=drivers/net/wireless/ 161 make coccicheck M=drivers/net/wireless/
149 162
150To apply Coccinelle on a file basis, instead of a directory basis, the 163To apply Coccinelle on a file basis, instead of a directory basis, the
151following command may be used: 164following command may be used::
152 165
153 make C=1 CHECK="scripts/coccicheck" 166 make C=1 CHECK="scripts/coccicheck"
154 167
155To check only newly edited code, use the value 2 for the C flag, i.e. 168To check only newly edited code, use the value 2 for the C flag, i.e.::
156 169
157 make C=2 CHECK="scripts/coccicheck" 170 make C=2 CHECK="scripts/coccicheck"
158 171
@@ -166,8 +179,8 @@ semantic patch as shown in the previous section.
166The "report" mode is the default. You can select another one with the 179The "report" mode is the default. You can select another one with the
167MODE variable explained above. 180MODE variable explained above.
168 181
169 Debugging Coccinelle SmPL patches 182Debugging Coccinelle SmPL patches
170~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 183---------------------------------
171 184
172Using coccicheck is best as it provides in the spatch command line 185Using coccicheck is best as it provides in the spatch command line
173include options matching the options used when we compile the kernel. 186include options matching the options used when we compile the kernel.
@@ -177,8 +190,8 @@ manually run Coccinelle with debug options added.
177Alternatively you can debug running Coccinelle against SmPL patches 190Alternatively you can debug running Coccinelle against SmPL patches
178by asking for stderr to be redirected to stderr, by default stderr 191by asking for stderr to be redirected to stderr, by default stderr
179is redirected to /dev/null, if you'd like to capture stderr you 192is redirected to /dev/null, if you'd like to capture stderr you
180can specify the DEBUG_FILE="file.txt" option to coccicheck. For 193can specify the ``DEBUG_FILE="file.txt"`` option to coccicheck. For
181instance: 194instance::
182 195
183 rm -f cocci.err 196 rm -f cocci.err
184 make coccicheck COCCI=scripts/coccinelle/free/kfree.cocci MODE=report DEBUG_FILE=cocci.err 197 make coccicheck COCCI=scripts/coccinelle/free/kfree.cocci MODE=report DEBUG_FILE=cocci.err
@@ -186,7 +199,7 @@ instance:
186 199
187You can use SPFLAGS to add debugging flags, for instance you may want to 200You can use SPFLAGS to add debugging flags, for instance you may want to
188add both --profile --show-trying to SPFLAGS when debugging. For instance 201add both --profile --show-trying to SPFLAGS when debugging. For instance
189you may want to use: 202you may want to use::
190 203
191 rm -f err.log 204 rm -f err.log
192 export COCCI=scripts/coccinelle/misc/irqf_oneshot.cocci 205 export COCCI=scripts/coccinelle/misc/irqf_oneshot.cocci
@@ -198,24 +211,24 @@ work.
198 211
199DEBUG_FILE support is only supported when using coccinelle >= 1.2. 212DEBUG_FILE support is only supported when using coccinelle >= 1.2.
200 213
201 .cocciconfig support 214.cocciconfig support
202~~~~~~~~~~~~~~~~~~~~~~ 215--------------------
203 216
204Coccinelle supports reading .cocciconfig for default Coccinelle options that 217Coccinelle supports reading .cocciconfig for default Coccinelle options that
205should be used every time spatch is spawned, the order of precedence for 218should be used every time spatch is spawned, the order of precedence for
206variables for .cocciconfig is as follows: 219variables for .cocciconfig is as follows:
207 220
208 o Your current user's home directory is processed first 221- Your current user's home directory is processed first
209 o Your directory from which spatch is called is processed next 222- Your directory from which spatch is called is processed next
210 o The directory provided with the --dir option is processed last, if used 223- The directory provided with the --dir option is processed last, if used
211 224
212Since coccicheck runs through make, it naturally runs from the kernel 225Since coccicheck runs through make, it naturally runs from the kernel
213proper dir, as such the second rule above would be implied for picking up a 226proper dir, as such the second rule above would be implied for picking up a
214.cocciconfig when using 'make coccicheck'. 227.cocciconfig when using ``make coccicheck``.
215 228
216'make coccicheck' also supports using M= targets.If you do not supply 229``make coccicheck`` also supports using M= targets.If you do not supply
217any M= target, it is assumed you want to target the entire kernel. 230any M= target, it is assumed you want to target the entire kernel.
218The kernel coccicheck script has: 231The kernel coccicheck script has::
219 232
220 if [ "$KBUILD_EXTMOD" = "" ] ; then 233 if [ "$KBUILD_EXTMOD" = "" ] ; then
221 OPTIONS="--dir $srctree $COCCIINCLUDE" 234 OPTIONS="--dir $srctree $COCCIINCLUDE"
@@ -235,12 +248,12 @@ override any of the kernel's .coccicheck's settings using SPFLAGS.
235 248
236We help Coccinelle when used against Linux with a set of sensible defaults 249We help Coccinelle when used against Linux with a set of sensible defaults
237options for Linux with our own Linux .cocciconfig. This hints to coccinelle 250options for Linux with our own Linux .cocciconfig. This hints to coccinelle
238git can be used for 'git grep' queries over coccigrep. A timeout of 200 251git can be used for ``git grep`` queries over coccigrep. A timeout of 200
239seconds should suffice for now. 252seconds should suffice for now.
240 253
241The options picked up by coccinelle when reading a .cocciconfig do not appear 254The options picked up by coccinelle when reading a .cocciconfig do not appear
242as arguments to spatch processes running on your system, to confirm what 255as arguments to spatch processes running on your system, to confirm what
243options will be used by Coccinelle run: 256options will be used by Coccinelle run::
244 257
245 spatch --print-options-only 258 spatch --print-options-only
246 259
@@ -252,219 +265,227 @@ carries its own .cocciconfig, you will need to use SPFLAGS to use idutils if
252desired. See below section "Additional flags" for more details on how to use 265desired. See below section "Additional flags" for more details on how to use
253idutils. 266idutils.
254 267
255 Additional flags 268Additional flags
256~~~~~~~~~~~~~~~~~~ 269----------------
257 270
258Additional flags can be passed to spatch through the SPFLAGS 271Additional flags can be passed to spatch through the SPFLAGS
259variable. This works as Coccinelle respects the last flags 272variable. This works as Coccinelle respects the last flags
260given to it when options are in conflict. 273given to it when options are in conflict. ::
261 274
262 make SPFLAGS=--use-glimpse coccicheck 275 make SPFLAGS=--use-glimpse coccicheck
263 276
264Coccinelle supports idutils as well but requires coccinelle >= 1.0.6. 277Coccinelle supports idutils as well but requires coccinelle >= 1.0.6.
265When no ID file is specified coccinelle assumes your ID database file 278When no ID file is specified coccinelle assumes your ID database file
266is in the file .id-utils.index on the top level of the kernel, coccinelle 279is in the file .id-utils.index on the top level of the kernel, coccinelle
267carries a script scripts/idutils_index.sh which creates the database with 280carries a script scripts/idutils_index.sh which creates the database with::
268 281
269 mkid -i C --output .id-utils.index 282 mkid -i C --output .id-utils.index
270 283
271If you have another database filename you can also just symlink with this 284If you have another database filename you can also just symlink with this
272name. 285name. ::
273 286
274 make SPFLAGS=--use-idutils coccicheck 287 make SPFLAGS=--use-idutils coccicheck
275 288
276Alternatively you can specify the database filename explicitly, for 289Alternatively you can specify the database filename explicitly, for
277instance: 290instance::
278 291
279 make SPFLAGS="--use-idutils /full-path/to/ID" coccicheck 292 make SPFLAGS="--use-idutils /full-path/to/ID" coccicheck
280 293
281See spatch --help to learn more about spatch options. 294See ``spatch --help`` to learn more about spatch options.
282 295
283Note that the '--use-glimpse' and '--use-idutils' options 296Note that the ``--use-glimpse`` and ``--use-idutils`` options
284require external tools for indexing the code. None of them is 297require external tools for indexing the code. None of them is
285thus active by default. However, by indexing the code with 298thus active by default. However, by indexing the code with
286one of these tools, and according to the cocci file used, 299one of these tools, and according to the cocci file used,
287spatch could proceed the entire code base more quickly. 300spatch could proceed the entire code base more quickly.
288 301
289 SmPL patch specific options 302SmPL patch specific options
290~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 303---------------------------
291 304
292SmPL patches can have their own requirements for options passed 305SmPL patches can have their own requirements for options passed
293to Coccinelle. SmPL patch specific options can be provided by 306to Coccinelle. SmPL patch specific options can be provided by
294providing them at the top of the SmPL patch, for instance: 307providing them at the top of the SmPL patch, for instance::
295 308
296// Options: --no-includes --include-headers 309 // Options: --no-includes --include-headers
297 310
298 SmPL patch Coccinelle requirements 311SmPL patch Coccinelle requirements
299~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 312----------------------------------
300 313
301As Coccinelle features get added some more advanced SmPL patches 314As Coccinelle features get added some more advanced SmPL patches
302may require newer versions of Coccinelle. If an SmPL patch requires 315may require newer versions of Coccinelle. If an SmPL patch requires
303at least a version of Coccinelle, this can be specified as follows, 316at least a version of Coccinelle, this can be specified as follows,
304as an example if requiring at least Coccinelle >= 1.0.5: 317as an example if requiring at least Coccinelle >= 1.0.5::
305 318
306// Requires: 1.0.5 319 // Requires: 1.0.5
307 320
308 Proposing new semantic patches 321Proposing new semantic patches
309~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 322-------------------------------
310 323
311New semantic patches can be proposed and submitted by kernel 324New semantic patches can be proposed and submitted by kernel
312developers. For sake of clarity, they should be organized in the 325developers. For sake of clarity, they should be organized in the
313sub-directories of 'scripts/coccinelle/'. 326sub-directories of ``scripts/coccinelle/``.
314 327
315 328
316 Detailed description of the 'report' mode 329Detailed description of the ``report`` mode
317~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 330-------------------------------------------
331
332``report`` generates a list in the following format::
318 333
319'report' generates a list in the following format:
320 file:line:column-column: message 334 file:line:column-column: message
321 335
322Example: 336Example
337~~~~~~~
323 338
324Running 339Running::
325 340
326 make coccicheck MODE=report COCCI=scripts/coccinelle/api/err_cast.cocci 341 make coccicheck MODE=report COCCI=scripts/coccinelle/api/err_cast.cocci
327 342
328will execute the following part of the SmPL script. 343will execute the following part of the SmPL script::
329 344
330<smpl> 345 <smpl>
331@r depends on !context && !patch && (org || report)@ 346 @r depends on !context && !patch && (org || report)@
332expression x; 347 expression x;
333position p; 348 position p;
334@@ 349 @@
335 350
336 ERR_PTR@p(PTR_ERR(x)) 351 ERR_PTR@p(PTR_ERR(x))
337 352
338@script:python depends on report@ 353 @script:python depends on report@
339p << r.p; 354 p << r.p;
340x << r.x; 355 x << r.x;
341@@ 356 @@
342 357
343msg="ERR_CAST can be used with %s" % (x) 358 msg="ERR_CAST can be used with %s" % (x)
344coccilib.report.print_report(p[0], msg) 359 coccilib.report.print_report(p[0], msg)
345</smpl> 360 </smpl>
346 361
347This SmPL excerpt generates entries on the standard output, as 362This SmPL excerpt generates entries on the standard output, as
348illustrated below: 363illustrated below::
349 364
350/home/user/linux/crypto/ctr.c:188:9-16: ERR_CAST can be used with alg 365 /home/user/linux/crypto/ctr.c:188:9-16: ERR_CAST can be used with alg
351/home/user/linux/crypto/authenc.c:619:9-16: ERR_CAST can be used with auth 366 /home/user/linux/crypto/authenc.c:619:9-16: ERR_CAST can be used with auth
352/home/user/linux/crypto/xts.c:227:9-16: ERR_CAST can be used with alg 367 /home/user/linux/crypto/xts.c:227:9-16: ERR_CAST can be used with alg
353 368
354 369
355 Detailed description of the 'patch' mode 370Detailed description of the ``patch`` mode
356~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 371------------------------------------------
357 372
358When the 'patch' mode is available, it proposes a fix for each problem 373When the ``patch`` mode is available, it proposes a fix for each problem
359identified. 374identified.
360 375
361Example: 376Example
377~~~~~~~
378
379Running::
362 380
363Running
364 make coccicheck MODE=patch COCCI=scripts/coccinelle/api/err_cast.cocci 381 make coccicheck MODE=patch COCCI=scripts/coccinelle/api/err_cast.cocci
365 382
366will execute the following part of the SmPL script. 383will execute the following part of the SmPL script::
367 384
368<smpl> 385 <smpl>
369@ depends on !context && patch && !org && !report @ 386 @ depends on !context && patch && !org && !report @
370expression x; 387 expression x;
371@@ 388 @@
372 389
373- ERR_PTR(PTR_ERR(x)) 390 - ERR_PTR(PTR_ERR(x))
374+ ERR_CAST(x) 391 + ERR_CAST(x)
375</smpl> 392 </smpl>
376 393
377This SmPL excerpt generates patch hunks on the standard output, as 394This SmPL excerpt generates patch hunks on the standard output, as
378illustrated below: 395illustrated below::
379 396
380diff -u -p a/crypto/ctr.c b/crypto/ctr.c 397 diff -u -p a/crypto/ctr.c b/crypto/ctr.c
381--- a/crypto/ctr.c 2010-05-26 10:49:38.000000000 +0200 398 --- a/crypto/ctr.c 2010-05-26 10:49:38.000000000 +0200
382+++ b/crypto/ctr.c 2010-06-03 23:44:49.000000000 +0200 399 +++ b/crypto/ctr.c 2010-06-03 23:44:49.000000000 +0200
383@@ -185,7 +185,7 @@ static struct crypto_instance *crypto_ct 400 @@ -185,7 +185,7 @@ static struct crypto_instance *crypto_ct
384 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER, 401 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
385 CRYPTO_ALG_TYPE_MASK); 402 CRYPTO_ALG_TYPE_MASK);
386 if (IS_ERR(alg)) 403 if (IS_ERR(alg))
387- return ERR_PTR(PTR_ERR(alg)); 404 - return ERR_PTR(PTR_ERR(alg));
388+ return ERR_CAST(alg); 405 + return ERR_CAST(alg);
389 406
390 /* Block size must be >= 4 bytes. */ 407 /* Block size must be >= 4 bytes. */
391 err = -EINVAL; 408 err = -EINVAL;
392 409
393 Detailed description of the 'context' mode 410Detailed description of the ``context`` mode
394~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 411--------------------------------------------
395 412
396'context' highlights lines of interest and their context 413``context`` highlights lines of interest and their context
397in a diff-like style. 414in a diff-like style.
398 415
399NOTE: The diff-like output generated is NOT an applicable patch. The 416 **NOTE**: The diff-like output generated is NOT an applicable patch. The
400 intent of the 'context' mode is to highlight the important lines 417 intent of the ``context`` mode is to highlight the important lines
401 (annotated with minus, '-') and gives some surrounding context 418 (annotated with minus, ``-``) and gives some surrounding context
402 lines around. This output can be used with the diff mode of 419 lines around. This output can be used with the diff mode of
403 Emacs to review the code. 420 Emacs to review the code.
404 421
405Example: 422Example
423~~~~~~~
424
425Running::
406 426
407Running
408 make coccicheck MODE=context COCCI=scripts/coccinelle/api/err_cast.cocci 427 make coccicheck MODE=context COCCI=scripts/coccinelle/api/err_cast.cocci
409 428
410will execute the following part of the SmPL script. 429will execute the following part of the SmPL script::
411 430
412<smpl> 431 <smpl>
413@ depends on context && !patch && !org && !report@ 432 @ depends on context && !patch && !org && !report@
414expression x; 433 expression x;
415@@ 434 @@
416 435
417* ERR_PTR(PTR_ERR(x)) 436 * ERR_PTR(PTR_ERR(x))
418</smpl> 437 </smpl>
419 438
420This SmPL excerpt generates diff hunks on the standard output, as 439This SmPL excerpt generates diff hunks on the standard output, as
421illustrated below: 440illustrated below::
422 441
423diff -u -p /home/user/linux/crypto/ctr.c /tmp/nothing 442 diff -u -p /home/user/linux/crypto/ctr.c /tmp/nothing
424--- /home/user/linux/crypto/ctr.c 2010-05-26 10:49:38.000000000 +0200 443 --- /home/user/linux/crypto/ctr.c 2010-05-26 10:49:38.000000000 +0200
425+++ /tmp/nothing 444 +++ /tmp/nothing
426@@ -185,7 +185,6 @@ static struct crypto_instance *crypto_ct 445 @@ -185,7 +185,6 @@ static struct crypto_instance *crypto_ct
427 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER, 446 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
428 CRYPTO_ALG_TYPE_MASK); 447 CRYPTO_ALG_TYPE_MASK);
429 if (IS_ERR(alg)) 448 if (IS_ERR(alg))
430- return ERR_PTR(PTR_ERR(alg)); 449 - return ERR_PTR(PTR_ERR(alg));
431 450
432 /* Block size must be >= 4 bytes. */ 451 /* Block size must be >= 4 bytes. */
433 err = -EINVAL; 452 err = -EINVAL;
434 453
435 Detailed description of the 'org' mode 454Detailed description of the ``org`` mode
436~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 455----------------------------------------
456
457``org`` generates a report in the Org mode format of Emacs.
437 458
438'org' generates a report in the Org mode format of Emacs. 459Example
460~~~~~~~
439 461
440Example: 462Running::
441 463
442Running
443 make coccicheck MODE=org COCCI=scripts/coccinelle/api/err_cast.cocci 464 make coccicheck MODE=org COCCI=scripts/coccinelle/api/err_cast.cocci
444 465
445will execute the following part of the SmPL script. 466will execute the following part of the SmPL script::
446 467
447<smpl> 468 <smpl>
448@r depends on !context && !patch && (org || report)@ 469 @r depends on !context && !patch && (org || report)@
449expression x; 470 expression x;
450position p; 471 position p;
451@@ 472 @@
452 473
453 ERR_PTR@p(PTR_ERR(x)) 474 ERR_PTR@p(PTR_ERR(x))
454 475
455@script:python depends on org@ 476 @script:python depends on org@
456p << r.p; 477 p << r.p;
457x << r.x; 478 x << r.x;
458@@ 479 @@
459 480
460msg="ERR_CAST can be used with %s" % (x) 481 msg="ERR_CAST can be used with %s" % (x)
461msg_safe=msg.replace("[","@(").replace("]",")") 482 msg_safe=msg.replace("[","@(").replace("]",")")
462coccilib.org.print_todo(p[0], msg_safe) 483 coccilib.org.print_todo(p[0], msg_safe)
463</smpl> 484 </smpl>
464 485
465This SmPL excerpt generates Org entries on the standard output, as 486This SmPL excerpt generates Org entries on the standard output, as
466illustrated below: 487illustrated below::
467 488
468* TODO [[view:/home/user/linux/crypto/ctr.c::face=ovl-face1::linb=188::colb=9::cole=16][ERR_CAST can be used with alg]] 489 * TODO [[view:/home/user/linux/crypto/ctr.c::face=ovl-face1::linb=188::colb=9::cole=16][ERR_CAST can be used with alg]]
469* TODO [[view:/home/user/linux/crypto/authenc.c::face=ovl-face1::linb=619::colb=9::cole=16][ERR_CAST can be used with auth]] 490 * TODO [[view:/home/user/linux/crypto/authenc.c::face=ovl-face1::linb=619::colb=9::cole=16][ERR_CAST can be used with auth]]
470* TODO [[view:/home/user/linux/crypto/xts.c::face=ovl-face1::linb=227::colb=9::cole=16][ERR_CAST can be used with alg]] 491 * TODO [[view:/home/user/linux/crypto/xts.c::face=ovl-face1::linb=227::colb=9::cole=16][ERR_CAST can be used with alg]]
diff --git a/Documentation/dev-tools/tools.rst b/Documentation/dev-tools/tools.rst
index 60ddb9ea6ef9..ae0c58c784db 100644
--- a/Documentation/dev-tools/tools.rst
+++ b/Documentation/dev-tools/tools.rst
@@ -14,3 +14,4 @@ whole; patches welcome!
14.. toctree:: 14.. toctree::
15 :maxdepth: 2 15 :maxdepth: 2
16 16
17 coccinelle
diff --git a/MAINTAINERS b/MAINTAINERS
index 20bb1d00098c..1e5460cfc196 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3124,7 +3124,7 @@ L: cocci@systeme.lip6.fr (moderated for non-subscribers)
3124T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git misc 3124T: git git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild.git misc
3125W: http://coccinelle.lip6.fr/ 3125W: http://coccinelle.lip6.fr/
3126S: Supported 3126S: Supported
3127F: Documentation/coccinelle.txt 3127F: Documentation/dev-tools/coccinelle.rst
3128F: scripts/coccinelle/ 3128F: scripts/coccinelle/
3129F: scripts/coccicheck 3129F: scripts/coccicheck
3130 3130