Skip to contentSkip to conversation

practical auto-QA de-noiser or -E_TOO_UGLY ?

RFC PATCH NAK Jim Cromie 2 participants 4 messages Oct 15, 2025 – Oct 16, 2025

Subsystems (2)
lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

cover practical auto-QA de-noiser or -E_TOO_UGLY ?

Can I haz (in compiler.h)

  #define __no_side_effects(...)    /* checkpatch hint only */

module_param_named() if submitted now, would draw several warnings from checkpatch --strict, on name, value (but not type).

CHECK: Macro argument reuse '_var' - possible side-effects?

This macro allows an author to suppress that complaint, clearly and declaratively, and strongly suggests that they used --strict, saw the complaint, and silenced it. So they know not to pass i++.

Do the possible QA/CI benefits suffice for the mild "hackish" flavor ?

Jim Cromie (2):
checkpatch: add __no_side_effects() hint/assertion macro
checkpatch: cosmetic-style tweak

 include/linux/compiler.h | 12 +++++++++
 scripts/checkpatch.pl    | 54 ++++++++++++++++++++++++++++++++++------
 2 files changed, 59 insertions(+), 7 deletions(-)
Signature · 1 line
2.51.0
author
#1 lore raw

RFC PATCH 1/2 checkpatch: add __no_side_effects() hint/assertion macro

Depending upon your macros, checkpatch --strict may issue many warnings like:

CHECK: Macro argument reuse '_var' - possible side-effects?

In (at least) 2 cases, the usual advice to use ({ typeof .. }) or do{}while(0) does not apply:

1. top-of-scope (inc file-scope) declarative macros:

   #define module_param_named(name, value, type, perm)                        \
        param_check_##type(name, &(value));                                \
        module_param_cb(name, &param_ops_##type, &value, perm);            \
        __MODULE_PARM_TYPE(name, #type)

Given this macro-defn, checkpatch would carp about name and value. Note that it wouldn't complain about type, even though type is expanded 3 times, because it knew to strip # and ## constructs before counting args.

2. #define for_simplicity(_i, _lim, ...) \
for( _i = 0, _i < _lim; _i++ ) /* your loop body here */

Though not a compelling example, it should'nt be impossible. ({}) fails because () detaches the expansion from the following { block }. And the do-while adds a ';'.

So allow a macro author to assert that (_i) is safe to expand 2+ times:

   #define for_simplicity(_i, _lim, ...) \
   	   __no_side_effects(_i)	 \
   	   for( _i = 0, _i < _lim; _i++ )

This should help reduce auto-QA/pre-review noise, even though its a homely little macro.

It has 2 parts:

1. compiler.h: #define __no_side_effects(...) /* nothing */ so no functional change from its use.
authors add it to "noisy" macros
readily reviewable, and marked for it by name.

2. checkpatch: suppress the CHECK reporting:
a. find the hint in macro body, capture the safe-args (_i, _j) b. strip the hint, reflecting the /* nothing */ above c. before issuing CHK() on arg-use-count > 1, skip if /safe-args/

3. --drx option, which enables a new sub drx_print("reason");

a. used like: s/$pattern/drx_print("why")/e;
b. calls it on 3 existing cases.

Here it is in action, on a patch that prompted this one:

drx_print: strip 'arg ##' catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <_var##>

drx_print: strip 'arg ##' catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <_var##>

drx_print: strip 'arg ##' catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <_var##>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <__builtin_constant_p(cls>
Capture 1 ($1): <__builtin_constant_p>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <##_model>
Capture 1 ($1): <##>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <##_model>
Capture 1 ($1): <##>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <##_model>
Capture 1 ($1): <##>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <##_model>
Capture 1 ($1): <##>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <##_model>
Capture 1 ($1): <##>

drx_print: dunno

Quoted 2 lines
Quoted 2 lines

Matched ($&): <##_model>
Capture 1 ($1): <##>

drx_print: strip '#|## arg catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <#_flags>

drx_print: strip 'arg ##' catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <_flags##>

drx_print: strip 'arg ##' catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <_flags##>

drx_print: strip 'arg ##' catenations

Quoted 1 line
Quoted 1 line

Matched ($&): <_flags##>

total: 0 errors, 0 warnings, 712 lines checked

This should be useful for hacking at checkpatch if/when the behavior of an existing s/// or s///g is sufficiently mysterious that a few s//drx_print("wtf")/ge modifications seem appropriate. Some of them will be worth keeping, since the "reason" can be inspected, improved, verified by using --drx as needed.

NOTES:

This adds to the stack of heuristics: cpp doesn't mind expanding i++, so checkpatch is paranoid; this quiets that paranoia clearly.

The macro call must *exclude* the trailing semi-colon.

practicality vs aesthetics. Is less QA-noise worth the ugly ?

TODO: The "dunno" case shouldn't really catch the <##_model>, since there's a subsequent rule for that. I could have hidden this blemish by moving the other rules up, but that also hides a maybe over-broad stripping regex, and is -E_TOO_MANY_CHANGES.

fix

---
 include/linux/compiler.h | 12 +++++++++++
 scripts/checkpatch.pl    | 46 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 54 insertions(+), 4 deletions(-)
include/linux/compiler.h +12 -0
index 64ff73c533e5..a348b45eacc0 100644
@@ -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 __no_side_effects(...)  /* checkpatch "annotation" helper */
+
 #include <asm/rwonce.h>
 
 #endif /* __LINUX_COMPILER_H */
scripts/checkpatch.pl +42 -4

65 lines not on this page · raw message

Signature · 1 line
2.51.0
author
#2 lore raw

RFC PATCH 2/2 checkpatch: cosmetic-style tweak

In reply to Jim Cromie

no functional change, slightly narrower on-screen, maybe clearer ?

---
 scripts/checkpatch.pl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +5 -3
index 27299f326804..4449e809ef6f 100755
@@ -4019,11 +4019,13 @@ sub process {
 				if ($newindent ne $goodtabindent &&
 				    $newindent ne $goodspaceindent) {
 
-					if (CHK("PARENTHESIS_ALIGNMENT",
-						"Alignment should match open parenthesis\n" . $hereprev) &&
-					    $fix && $line =~ /^\+/) {
+					CHK("PARENTHESIS_ALIGNMENT",
+					    "Alignment should match open parenthesis\n" . $hereprev)
+					and do {
+					    if ($fix && $line =~ /^\+/) {
 						$fixed[$fixlinenr] =~
 						    s/^\+[ \t]*/\+$goodtabindent/;
+					    }
 					}
 				}
 			}
Signature · 1 line
2.51.0
maintainer NAK
#3 lore raw

Re: [RFC PATCH 2/2] checkpatch: cosmetic-style tweak

Quoted 1 line · Jim Cromie

no functional change, slightly narrower on-screen, maybe clearer ?

[]

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 4 lines
scripts/checkpatch.pl +0 -0
@@ -4019,11 +4019,13 @@ sub process {
 				if ($newindent ne $goodtabindent &&
 				    $newindent ne $goodspaceindent) {
 

scripts/checkpatch.pl sub process { · line 4028

Quoted 10 lines
scripts/checkpatch.pl +5 -3
-					if (CHK("PARENTHESIS_ALIGNMENT",
-						"Alignment should match open parenthesis\n" . $hereprev) &&
-					    $fix && $line =~ /^\+/) {
+					CHK("PARENTHESIS_ALIGNMENT",
+					    "Alignment should match open parenthesis\n" . $hereprev)
+					and do {
+					    if ($fix && $line =~ /^\+/) {
 						$fixed[$fixlinenr] =~
 						    s/^\+[ \t]*/\+$goodtabindent/;
+					    }

nack.

"and do" is not used anywhere by checkpatch
and I don't want to introduce it.