Re: [PATCH] hwmon: (minisforum-um780xtx) Avoid overflow when rounding threshold input

From: Guenter Roeck

Date: Sun Oct 18 2026 - 12:17:46 EST


On Thu, Oct 15, 2026 at 12:38:41AM -0300, Sebastián Peyrott wrote:
> The SYS fan threshold store path rounds the user-supplied millidegree value
> with DIV_ROUND_CLOSEST() before clamping it. DIV_ROUND_CLOSEST() adds or
> subtracts half the divisor first, so inputs within 500 of LONG_MAX or
> LONG_MIN overflow and change sign. Writing LONG_MAX then selects the lower
> limit instead of the upper one, and LONG_MIN the upper limit instead of the
> lower one.
>
> Clamp the input to the representable 0..255000 range before rounding. The
> result is unchanged for all other inputs, because the subsequent clamp
> already limits the threshold to 0..254 degrees.
>
> Fixes: 9d980da93bbc ("hwmon: Add Minisforum UM780 XTX EC monitoring and fan control")
> Reported-by: Sashiko AI review <sashiko-bot@xxxxxxxxxx>
> Closes: https://lore.kernel.org/r/sashiko-outbox-171941@xxxxxxxxxx
> Assisted-by: LLM
> Signed-off-by: Sebastián Peyrott <speyrott@xxxxxxxxx>

Applied.

Thanks,
Guenter