platform/x86: hp-wmi: Clamp PWM input before narrowing
PATCH 1/1 platform/x86: hp-wmi: Clamp PWM input before narrowing
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 <[email protected]>
---
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(-)
drivers/platform/x86/hp/hp-wmi.c +1 -1
@@ -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 ));
Signature · 1 line
2.56.0