Add a description to the MACRO_ARG_REUSE check. I feel like this is also a good place to put a workaround although I'm not sure if there is a cannonical way to solve those kinds of issues. Signed-off-by: Martin Fernandez <martin.fernandez@xxxxxxxxxxxxx> --- Documentation/dev-tools/checkpatch.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst index b52452bc2963..43fa99f188f5 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -759,6 +759,21 @@ Indentation and Line Breaks Macros, Attributes and Symbols ------------------------------ + **ARG_REUSE** + Using the same argument multiple times in the macro definition + would 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)` would expand to:: + + foo(x) < 0 ? foo(x) : 0 + + If `foo` have side-effects or it's an expensive calculation the + results might not be what the user inteded. + **ARRAY_SIZE** The ARRAY_SIZE(foo) macro should be preferred over sizeof(foo)/sizeof(foo[0]) for finding number of elements in an -- 2.30.2