mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shang En Sim <sim@shangen.org>
To: "Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "Shang En Sim" <sim@shangen.org>,
	"Krishna Chomal" <krishna.chomal108@gmail.com>,
	"Suryansh Singh" <technosfan14@gmail.com>,
	"Emre Cecanpunar" <emreleno@gmail.com>,
	"Kürşat Abaylı" <hello@kursatabayli.dev>,
	"Radhey Kalra" <radheykalra901@gmail.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] platform/x86: hp-wmi: Clamp PWM input before narrowing
Date: Tue, 27 Oct 2026 18:35:08 -0500	[thread overview]
Message-ID: <20261027233512.211524-1-sim@shangen.org> (raw)

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


                 reply	other threads:[~2026-10-27 23:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261027233512.211524-1-sim@shangen.org \
    --to=sim@shangen.org \
    --cc=emreleno@gmail.com \
    --cc=hansg@kernel.org \
    --cc=hello@kursatabayli.dev \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=krishna.chomal108@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=radheykalra901@gmail.com \
    --cc=technosfan14@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®