]> Gentwo Git Trees - linux/.git/commit
hwmon: (vt8231) Convert macros to functions to avoid TOCTOU
authorGui-Dong Han <hanguidong02@gmail.com>
Mon, 24 Nov 2025 16:59:00 +0000 (00:59 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 24 Nov 2025 19:47:45 +0000 (11:47 -0800)
commitfe598ab37e472514e769d3eeb0456cddb3b8ba9f
tree06a9c5adbff0a5a029b5e29381fe89faa8014ee3
parent4faaa77d6b32347ea6af74d5fd2f34c3922aeee6
hwmon: (vt8231) Convert macros to functions to avoid TOCTOU

The macro FAN_FROM_REG evaluates its arguments multiple times. When used
with shared driver data, this leads to Time-of-Check to Time-of-Use
(TOCTOU) race conditions, potentially causing divide-by-zero errors.

Convert the macro to a static function to ensure arguments are evaluated
only once.

Additionally, in fan_div_store, move the reading of the old register
value and the calculation of the minimum limit inside the update lock.
This ensures that the read-modify-write sequence operates on consistent
data, preventing race conditions during fan divider updates.

Link: https://lore.kernel.org/all/CALbr=LYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=o1xxMJ8=5z8B-g@mail.gmail.com/
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Link: https://lore.kernel.org/r/20251124165900.4713-1-hanguidong02@gmail.com
[groeck: Dropped unnecessary line split]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/vt8231.c