Hi, On Mon, Jul 4, 2022 at 7:14 PM Martin Fernandez <martin.fernandez@xxxxxxxxxxxxx> wrote: > > Add a description, an example and a possible workaround to the > MACRO_ARG_REUSE check. > > Signed-off-by: Martin Fernandez <martin.fernandez@xxxxxxxxxxxxx> > --- > Documentation/dev-tools/checkpatch.rst | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst > index b52452bc2963..f7ed2c1f9d5e 100644 > --- a/Documentation/dev-tools/checkpatch.rst > +++ b/Documentation/dev-tools/checkpatch.rst > @@ -759,6 +759,26 @@ 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)) Prefer indentation of 6 spaces here (5 given). > + > + If you call it with `min(foo(x), 0)` would expand to:: If you call it with `min(foo(x), 0)`, it would expand to:: > + > + foo(x) < 0 ? foo(x) : 0 Same indentation issue > + > + If `foo` have side-effects or it's an expensive calculation the s/have/has > + results might not be what the user intended. > + > + For a workaround the idea is to define local variables to hold the > + macro's arguments. Checkout the actual implementation of `min` in > + include/linux/minmax.h for the full implementation of the > + workaround. > + > **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 > With these changes in place: Acked-by: Dwaipayan Ray <dwaipayanray1@xxxxxxxxx> Thanks, Dwaipayan.