Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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