[PATCH v4] doc/checkpatch: Add description to MACRO_ARG_REUSE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a description, an example and a couple of options when it is safe
to ignore it.

Signed-off-by: Martin Fernandez <martin.fernandez@xxxxxxxxxxxxx>
---
 Documentation/dev-tools/checkpatch.rst | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index c3389c6f3838..678c1956468b 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -854,6 +854,32 @@ Macros, Attributes and Symbols
               ...
       }

+  **MACRO_ARG_REUSE**
+    Using the same argument multiple times in the macro definition
+    may lead to unwanted side effects.
+
+    For example, given a min() macro defined like::
+
+      #define min(x, y)  ((x) < (y) ? (x) : (y))
+
+    If you call it with ``min(foo(x), 0)``, it would expand to::
+
+      foo(x) < 0 ? foo(x) : 0
+
+    If foo has side effects or it's an expensive calculation the
+    results might not be what the user intended.
+
+    When it's safe to ignore:
+
+    - If the macro arguments of all uses of this macro are free of
+      unintended side effects. Passing a constant value is usually
+      fine, as the compiler will use constant propagation and further
+      optimizations to produce acceptable code.
+
+    - If you defined local variables that will hold the value of each
+      argument in the macro's definition. See the min() macro in
+      include/linux/minmax.h for example.
+
   **MISPLACED_INIT**
     It is possible to use section markers on variables in a way
     which gcc doesn't understand (or at least not the way the
--
2.30.2




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux