Re: [PATCH] hwmon: (adm1026) Convert macros to functions to avoid TOCTOU

From: Guenter Roeck

Date: Wed Nov 26 2025 - 10:50:27 EST


On Wed, Nov 26, 2025 at 07:38:28PM +0800, Gui-Dong Han wrote:
> The macro FAN_FROM_REG evaluates its arguments multiple times. When used
> in lockless contexts involving shared driver data, this causes
> Time-of-Check to Time-of-Use (TOCTOU) race conditions.
>
> Convert the macro to a static function. This guarantees that arguments
> are evaluated only once (pass-by-value), preventing the race
> conditions.
>
> Adhere to the principle of minimal changes by only converting macros
> that evaluate arguments multiple times and are used in lockless
> contexts.
>
> Link: https://lore.kernel.org/all/CALbr=LYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=o1xxMJ8=5z8B-g@xxxxxxxxxxxxxx/
> Signed-off-by: Gui-Dong Han <hanguidong02@xxxxxxxxx>

Applied.

Thanks,
Guenter