* [PATCH] platform/x86: hp-wmi: Clamp PWM input before narrowing
@ 2026-10-27 23:35 Shang En Sim
0 siblings, 0 replies; only message in thread
From: Shang En Sim @ 2026-10-27 23:35 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen
Cc: Shang En Sim, Krishna Chomal, Suryansh Singh, Emre Cecanpunar,
Kürşat Abaylı,
Radhey Kalra, platform-driver-x86, linux-kernel
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@shangen.org>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-27 23:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27 23:35 [PATCH] platform/x86: hp-wmi: Clamp PWM input before narrowing Shang En Sim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®