[PATCH] platform/x86: hp-wmi: Clamp PWM input before narrowing

From: Shang En Sim

Date: Tue Oct 27 2026 - 19:36:20 EST


The hwmon write callback receives the PWM value as a long, but pwm_to_rpm()
takes a u8. Out-of-range values therefore wrap before the helper can clamp
them to the supported range. For example, 256 becomes 0 and -1 becomes 255,
selecting the opposite end of the range instead of saturating the input.

Accept a long in pwm_to_rpm() so clamp_val() operates on the original value
before interpolation. Values in the valid 0..255 range are unchanged.

Fixes: 46be1453e6e6 ("platform/x86: hp-wmi: add manual fan control for Victus S models")
Signed-off-by: Shang En Sim <sim@xxxxxxxxxxx>
---
Verification: Standalone arithmetic boundary checks passed, and the
affected hp-wmi.o object built with W=1.

drivers/platform/x86/hp/hp-wmi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 52077833ac89..d66481a98c32 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -688,7 +688,7 @@ static inline u8 rpm_to_pwm(u8 rpm, struct hp_wmi_hwmon_priv *priv)
clamp_val(rpm, 0, priv->max_rpm));
}

-static inline u8 pwm_to_rpm(u8 pwm, struct hp_wmi_hwmon_priv *priv)
+static inline u8 pwm_to_rpm(long pwm, struct hp_wmi_hwmon_priv *priv)
{
return fixp_linear_interpolate(0, 0, U8_MAX, priv->max_rpm,
clamp_val(pwm, 0, U8_MAX));
--
2.56.0