Re: [PATCH] hwmon: (emc2103) Add locking to avoid TOCTOU

From: Guenter Roeck
Date: Mon Nov 24 2025 - 14:45:53 EST


On Tue, Nov 25, 2025 at 12:55:08AM +0800, Gui-Dong Han wrote:
> The functions fan1_input_show and fan1_target_show check shared data for
> zero before using it as a divisor. These accesses are currently
> lockless. If the data changes to zero between the check and the
> division, it causes a divide-by-zero error.
>
> Explicitly acquire the update lock around these checks and calculations
> to ensure the data remains stable, preventing Time-of-Check to
> Time-of-Use (TOCTOU) race conditions.
>
> 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