* [PATCH 3/3] compiler.h: add __chkp_no_side_effects() empty hint/assertion macro
[not found] <20251025211519.1616439-1-jim.cromie@gmail.com>
@ 2025-10-25 21:15 ` Jim Cromie
2025-10-26 0:09 ` Linus Torvalds
0 siblings, 1 reply; 2+ messages in thread
From: Jim Cromie @ 2025-10-25 21:15 UTC (permalink / raw)
To: linux-kernel
Cc: akpm, Jim Cromie, Luc Van Oostenryck, open list:SPARSE CHECKER
cpp has no intrinsic protection against macro arg side-effects, so to
compensate, checkpatch is paranoid:
CHECK: Macro argument reuse '_var' - possible side-effects?
Allow an author to suppress these warnings on _var by adding
'__chkp_no_side_effects(_var)' to the body of macros which trigger
that warning. This may reduce blowouts in CI pipelines.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/compiler.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 64ff73c533e5..96f6bfbd4088 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -379,6 +379,18 @@ static inline void *offset_to_ptr(const int *off)
*/
#define prevent_tail_call_optimization() mb()
+/*
+ * tell checkpatch --strict that you know the named args (a subset of
+ * the containing macro's args) are safe for multiple expansions.
+ *
+ * Prefer ({ typeof ..}) or do{}while(0) when they work. They would
+ * not work on module_param_named(name, value, type, perm), or on a
+ * locally useful "for_simplicity()" macro.
+ *
+ * NB: use at top of macro body, omit trailing semicolon.
+ */
+#define __chkp_no_side_effects(...) /* checkpatch "annotation" helper */
+
#include <asm/rwonce.h>
#endif /* __LINUX_COMPILER_H */
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/3] compiler.h: add __chkp_no_side_effects() empty hint/assertion macro
2025-10-25 21:15 ` [PATCH 3/3] compiler.h: add __chkp_no_side_effects() empty hint/assertion macro Jim Cromie
@ 2025-10-26 0:09 ` Linus Torvalds
0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2025-10-26 0:09 UTC (permalink / raw)
To: Jim Cromie
Cc: linux-kernel, akpm, Luc Van Oostenryck, open list:SPARSE CHECKER
On Sat, 25 Oct 2025 at 14:15, Jim Cromie <jim.cromie@gmail.com> wrote:
>
> Allow an author to suppress these warnings on _var by adding
> '__chkp_no_side_effects(_var)' to the body of macros which trigger
> that warning. This may reduce blowouts in CI pipelines.
How about just not doing that checkpatch thing at all if it causes problems?
Seriously, I think checkpatch often causes more problems than it
fixes. If it then causes us to write even uglier macros - and it's not
like our macros are pretty in general - it really is just causing
pain.
I think we should cut down checkpatch to things that are obvious and
real issues. Not things that then cause people to make code worse.
Linus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-26 0:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20251025211519.1616439-1-jim.cromie@gmail.com>
2025-10-25 21:15 ` [PATCH 3/3] compiler.h: add __chkp_no_side_effects() empty hint/assertion macro Jim Cromie
2025-10-26 0:09 ` Linus Torvalds
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox