Re: [PATCH] hwmon: (max6620) Add locking to avoid TOCTOU
From: david laight
Date: Fri Nov 28 2025 - 15:06:58 EST
On Sat, 29 Nov 2025 01:59:51 +0800
Gui-Dong Han <hanguidong02@xxxxxxxxx> wrote:
...
> In our previous discussion, you also suggested adding a note to
> submitting-patches.rst about "avoiding calculations in macros" to
> explicitly explain the risk of race conditions. Is this something you
> would still like to see added? If so, I would be happy to prepare a
> patch.
The real problem with #defines evaluating their parameters more than
once is just side effects of the expansion.
Even if the current users just pass a simple variable, you never
really know what is going to happen in the future.
There is also a secondary issue of pre-processor output 'bloat'.
This happens when large #define expansions get nested.
With the current headers FIELD_PREP(GENMASK(8, 5), val) expands to
about 18kB [1] (even though it is just (val >> 5) & 15).
I think one of your #defines get passed one of those - and then expands
it several times. As well as the massive line, the compiler may well
generate the code multiple times.
(CSE will normally stop foo->bar[x] being executed multiple times).
[1] Nothing like the 30MB that triple nested min() generated for a while.
David