From: Pei Xiao <xiaopei01@kylinos.cn>
To: linux@roeck-us.net, linux-hwmon@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: cryolitia@uniontech.com, Pei Xiao <xiaopei01@kylinos.cn>
Subject: [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid
Date: Thu, 11 Jun 2026 08:44:14 +0800 [thread overview]
Message-ID: <1c2ffa0d832ae3a74f6d4ffa7cc7b7e6cced69e3.1781138459.git.xiaopei01@kylinos.cn> (raw)
The EC firmware is expected to return values in [1, pwm_max]. A read of 0
is illegal and would cause underflow in the conversion formula. Explicitly
check for 0 and return -EIO.
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
changlogs in v2
1.Use the same comment format as the original driver.
---
drivers/hwmon/gpd-fan.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hwmon/gpd-fan.c b/drivers/hwmon/gpd-fan.c
index d1993cd645cb..ed212615b2fe 100644
--- a/drivers/hwmon/gpd-fan.c
+++ b/drivers/hwmon/gpd-fan.c
@@ -341,6 +341,10 @@ static int gpd_wm2_read_pwm(struct gpd_fan_data *data)
gpd_ecram_read(drvdata, drvdata->pwm_write, &var);
+ // EC PWM register valid range is 1 ~ pwm_max; 0 is an invalid state
+ if (unlikely(!var))
+ return -EIO;
+
// Match gpd_generic_write_pwm(u8) below
return DIV_ROUND_CLOSEST((var - 1) * 255, (drvdata->pwm_max - 1));
}
--
2.25.1
next reply other threads:[~2026-06-11 0:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 0:44 Pei Xiao [this message]
2026-06-11 5:07 ` Guenter Roeck
2026-06-11 5:08 ` Guenter Roeck
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=1c2ffa0d832ae3a74f6d4ffa7cc7b7e6cced69e3.1781138459.git.xiaopei01@kylinos.cn \
--to=xiaopei01@kylinos.cn \
--cc=cryolitia@uniontech.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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®