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

From: Guenter Roeck

Date: Fri Nov 21 2025 - 10:50:34 EST


On Thu, Nov 20, 2025 at 12:13:31PM +0800, Gui-Dong Han wrote:
> The macros IN_FROM_REG, TEMP_FROM_REG, and RPM_FROM_REG evaluate their
> arguments multiple times. These macros are used in lockless show functions
> involving shared driver data, leading to Time-of-Check to Time-of-Use race
> conditions.
>
> For example, RPM_FROM_REG checks if a value is 0 or 255, and then uses it
> in a division. If the value is modified by another thread to 0 after the
> check but before the division, it causes a divide-by-zero error.
>
> Convert these macros to static functions. This guarantees that arguments
> are evaluated only once (pass-by-value), fixing the race conditions.
> Adhere to the principle of minimal changes by only converting the specific
> macros involved in these 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