forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 151fecfb72a0d602dfe79790602ef64b4e241574
kernel/Documentation/dev-tools/coccinelle.rst
....@@ -4,6 +4,8 @@
44
55 .. highlight:: none
66
7
+.. _devtools_coccinelle:
8
+
79 Coccinelle
810 ==========
911
....@@ -12,7 +14,7 @@
1214 tree-wide patches and detection of problematic programming patterns.
1315
1416 Getting Coccinelle
15
--------------------
17
+------------------
1618
1719 The semantic patches included in the kernel use features and options
1820 which are provided by Coccinelle version 1.0.0-rc11 and above.
....@@ -30,26 +32,41 @@
3032 - NetBSD
3133 - FreeBSD
3234
33
-You can get the latest version released from the Coccinelle homepage at
35
+Some distribution packages are obsolete and it is recommended
36
+to use the latest version released from the Coccinelle homepage at
3437 http://coccinelle.lip6.fr/
3538
36
-Once you have it, run the following command::
39
+Or from Github at:
3740
38
- ./configure
41
+https://github.com/coccinelle/coccinelle
42
+
43
+Once you have it, run the following commands::
44
+
45
+ ./autogen
46
+ ./configure
3947 make
4048
4149 as a regular user, and install it with::
4250
4351 sudo make install
4452
53
+More detailed installation instructions to build from source can be
54
+found at:
55
+
56
+https://github.com/coccinelle/coccinelle/blob/master/install.txt
57
+
4558 Supplemental documentation
46
----------------------------
59
+--------------------------
4760
4861 For supplemental documentation refer to the wiki:
4962
5063 https://bottest.wiki.kernel.org/coccicheck
5164
5265 The wiki documentation always refers to the linux-next version of the script.
66
+
67
+For Semantic Patch Language(SmPL) grammar documentation refer to:
68
+
69
+http://coccinelle.lip6.fr/documentation.php
5370
5471 Using Coccinelle on the Linux kernel
5572 ------------------------------------
....@@ -68,7 +85,7 @@
6885 file:line:column-column: message
6986
7087 - ``context`` highlights lines of interest and their context in a
71
- diff-like style.Lines of interest are indicated with ``-``.
88
+ diff-like style. Lines of interest are indicated with ``-``.
7289
7390 - ``org`` generates a report in the Org mode format of Emacs.
7491
....@@ -102,7 +119,7 @@
102119 description of the problem being checked by the semantic patch, and
103120 includes a reference to Coccinelle.
104121
105
-As any static code analyzer, Coccinelle produces false
122
+As with any static code analyzer, Coccinelle produces false
106123 positives. Thus, reports must be carefully checked, and patches
107124 reviewed.
108125
....@@ -111,25 +128,25 @@
111128 make coccicheck MODE=report V=1
112129
113130 Coccinelle parallelization
114
----------------------------
131
+--------------------------
115132
116133 By default, coccicheck tries to run as parallel as possible. To change
117134 the parallelism, set the J= variable. For example, to run across 4 CPUs::
118135
119136 make coccicheck MODE=report J=4
120137
121
-As of Coccinelle 1.0.2 Coccinelle uses Ocaml parmap for parallelization,
138
+As of Coccinelle 1.0.2 Coccinelle uses Ocaml parmap for parallelization;
122139 if support for this is detected you will benefit from parmap parallelization.
123140
124141 When parmap is enabled coccicheck will enable dynamic load balancing by using
125
-``--chunksize 1`` argument, this ensures we keep feeding threads with work
142
+``--chunksize 1`` argument. This ensures we keep feeding threads with work
126143 one by one, so that we avoid the situation where most work gets done by only
127144 a few threads. With dynamic load balancing, if a thread finishes early we keep
128145 feeding it more work.
129146
130147 When parmap is enabled, if an error occurs in Coccinelle, this error
131
-value is propagated back, the return value of the ``make coccicheck``
132
-captures this return value.
148
+value is propagated back, and the return value of the ``make coccicheck``
149
+command captures this return value.
133150
134151 Using Coccinelle with a single semantic patch
135152 ---------------------------------------------
....@@ -158,15 +175,22 @@
158175 make coccicheck M=drivers/net/wireless/
159176
160177 To apply Coccinelle on a file basis, instead of a directory basis, the
161
-following command may be used::
178
+C variable is used by the makefile to select which files to work with.
179
+This variable can be used to run scripts for the entire kernel, a
180
+specific directory, or for a single file.
162181
163
- make C=1 CHECK="scripts/coccicheck"
182
+For example, to check drivers/bluetooth/bfusb.c, the value 1 is
183
+passed to the C variable to check files that make considers
184
+need to be compiled.::
164185
165
-To check only newly edited code, use the value 2 for the C flag, i.e.::
186
+ make C=1 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
166187
167
- make C=2 CHECK="scripts/coccicheck"
188
+The value 2 is passed to the C variable to check files regardless of
189
+whether they need to be compiled or not.::
168190
169
-In these modes, which works on a file basis, there is no information
191
+ make C=2 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
192
+
193
+In these modes, which work on a file basis, there is no information
170194 about semantic patches displayed, and no commit message proposed.
171195
172196 This runs every semantic patch in scripts/coccinelle by default. The
....@@ -181,12 +205,12 @@
181205
182206 Using coccicheck is best as it provides in the spatch command line
183207 include options matching the options used when we compile the kernel.
184
-You can learn what these options are by using V=1, you could then
208
+You can learn what these options are by using V=1; you could then
185209 manually run Coccinelle with debug options added.
186210
187211 Alternatively you can debug running Coccinelle against SmPL patches
188
-by asking for stderr to be redirected to stderr, by default stderr
189
-is redirected to /dev/null, if you'd like to capture stderr you
212
+by asking for stderr to be redirected to stderr. By default stderr
213
+is redirected to /dev/null; if you'd like to capture stderr you
190214 can specify the ``DEBUG_FILE="file.txt"`` option to coccicheck. For
191215 instance::
192216
....@@ -194,8 +218,8 @@
194218 make coccicheck COCCI=scripts/coccinelle/free/kfree.cocci MODE=report DEBUG_FILE=cocci.err
195219 cat cocci.err
196220
197
-You can use SPFLAGS to add debugging flags, for instance you may want to
198
-add both --profile --show-trying to SPFLAGS when debugging. For instance
221
+You can use SPFLAGS to add debugging flags; for instance you may want to
222
+add both --profile --show-trying to SPFLAGS when debugging. For example
199223 you may want to use::
200224
201225 rm -f err.log
....@@ -212,7 +236,7 @@
212236 --------------------
213237
214238 Coccinelle supports reading .cocciconfig for default Coccinelle options that
215
-should be used every time spatch is spawned, the order of precedence for
239
+should be used every time spatch is spawned. The order of precedence for
216240 variables for .cocciconfig is as follows:
217241
218242 - Your current user's home directory is processed first
....@@ -220,10 +244,10 @@
220244 - The directory provided with the --dir option is processed last, if used
221245
222246 Since coccicheck runs through make, it naturally runs from the kernel
223
-proper dir, as such the second rule above would be implied for picking up a
247
+proper dir; as such the second rule above would be implied for picking up a
224248 .cocciconfig when using ``make coccicheck``.
225249
226
-``make coccicheck`` also supports using M= targets.If you do not supply
250
+``make coccicheck`` also supports using M= targets. If you do not supply
227251 any M= target, it is assumed you want to target the entire kernel.
228252 The kernel coccicheck script has::
229253
....@@ -243,13 +267,13 @@
243267 order logic of .cocciconfig reading. If using the kernel's coccicheck target,
244268 override any of the kernel's .coccicheck's settings using SPFLAGS.
245269
246
-We help Coccinelle when used against Linux with a set of sensible defaults
270
+We help Coccinelle when used against Linux with a set of sensible default
247271 options for Linux with our own Linux .cocciconfig. This hints to coccinelle
248
-git can be used for ``git grep`` queries over coccigrep. A timeout of 200
272
+that git can be used for ``git grep`` queries over coccigrep. A timeout of 200
249273 seconds should suffice for now.
250274
251275 The options picked up by coccinelle when reading a .cocciconfig do not appear
252
-as arguments to spatch processes running on your system, to confirm what
276
+as arguments to spatch processes running on your system. To confirm what
253277 options will be used by Coccinelle run::
254278
255279 spatch --print-options-only
....@@ -273,7 +297,7 @@
273297
274298 Coccinelle supports idutils as well but requires coccinelle >= 1.0.6.
275299 When no ID file is specified coccinelle assumes your ID database file
276
-is in the file .id-utils.index on the top level of the kernel, coccinelle
300
+is in the file .id-utils.index on the top level of the kernel. Coccinelle
277301 carries a script scripts/idutils_index.sh which creates the database with::
278302
279303 mkid -i C --output .id-utils.index
....@@ -300,7 +324,7 @@
300324 ---------------------------
301325
302326 SmPL patches can have their own requirements for options passed
303
-to Coccinelle. SmPL patch specific options can be provided by
327
+to Coccinelle. SmPL patch-specific options can be provided by
304328 providing them at the top of the SmPL patch, for instance::
305329
306330 // Options: --no-includes --include-headers
....@@ -310,13 +334,13 @@
310334
311335 As Coccinelle features get added some more advanced SmPL patches
312336 may require newer versions of Coccinelle. If an SmPL patch requires
313
-at least a version of Coccinelle, this can be specified as follows,
337
+a minimum version of Coccinelle, this can be specified as follows,
314338 as an example if requiring at least Coccinelle >= 1.0.5::
315339
316340 // Requires: 1.0.5
317341
318342 Proposing new semantic patches
319
--------------------------------
343
+------------------------------
320344
321345 New semantic patches can be proposed and submitted by kernel
322346 developers. For sake of clarity, they should be organized in the