]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
hwmon: (max16065) Use READ/WRITE_ONCE to avoid compiler optimization induced race
authorGui-Dong Han <hanguidong02@gmail.com>
Tue, 3 Feb 2026 12:14:43 +0000 (20:14 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Sat, 7 Feb 2026 17:33:00 +0000 (09:33 -0800)
commit007be4327e443d79c9dd9e56dc16c36f6395d208
tree728a7032300eeca7b9fc35454713ff7be18e24f2
parentddb2325ed1e1219316bff8f8126be297aedba6b6
hwmon: (max16065) Use READ/WRITE_ONCE to avoid compiler optimization induced race

Simply copying shared data to a local variable cannot prevent data
races. The compiler is allowed to optimize away the local copy and
re-read the shared memory, causing a Time-of-Check Time-of-Use (TOCTOU)
issue if the data changes between the check and the usage.

To enforce the use of the local variable, use READ_ONCE() when reading
the shared data and WRITE_ONCE() when updating it. Apply these macros to
the three identified locations (curr_sense, adc, and fault) where local
variables are used for error validation, ensuring the value remains
consistent.

Reported-by: Ben Hutchings <ben@decadent.org.uk>
Closes: https://lore.kernel.org/all/6fe17868327207e8b850cf9f88b7dc58b2021f73.camel@decadent.org.uk/
Fixes: f5bae2642e3d ("hwmon: Driver for MAX16065 System Manager and compatibles")
Fixes: b8d5acdcf525 ("hwmon: (max16065) Use local variable to avoid TOCTOU")
Cc: stable@vger.kernel.org
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Link: https://lore.kernel.org/r/20260203121443.5482-1-hanguidong02@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/max16065.c