* [PATCH v4] doc/checkpatch: Add description to MACRO_ARG_REUSE
@ 2022-10-12 20:39 Martin Fernandez
2022-11-09 19:00 ` Martin Fernandez
0 siblings, 1 reply; 2+ messages in thread
From: Martin Fernandez @ 2022-10-12 20:39 UTC (permalink / raw)
To: linux-doc
Cc: dwaipayanray1, lukas.bulwahn, joe, rdunlap, bagasdotme, akiyks,
Martin Fernandez
Add a description, an example and a couple of options when it is safe
to ignore it.
Signed-off-by: Martin Fernandez <martin.fernandez@eclypsium.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] doc/checkpatch: Add description to MACRO_ARG_REUSE
2022-10-12 20:39 [PATCH v4] doc/checkpatch: Add description to MACRO_ARG_REUSE Martin Fernandez
@ 2022-11-09 19:00 ` Martin Fernandez
0 siblings, 0 replies; 2+ messages in thread
From: Martin Fernandez @ 2022-11-09 19:00 UTC (permalink / raw)
To: linux-doc; +Cc: dwaipayanray1, lukas.bulwahn, joe, rdunlap, bagasdotme, akiyks
On 10/12/22, Martin Fernandez <martin.fernandez@eclypsium.com> wrote:
> Add a description, an example and a couple of options when it is safe
> to ignore it.
>
> Signed-off-by: Martin Fernandez <martin.fernandez@eclypsium.com>
> ---
> 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
>
>
Sending it again since I've got no response
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-09 19:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 20:39 [PATCH v4] doc/checkpatch: Add description to MACRO_ARG_REUSE Martin Fernandez
2022-11-09 19:00 ` Martin Fernandez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).