* [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid
@ 2026-06-11 0:44 Pei Xiao
2026-06-11 5:07 ` Guenter Roeck
2026-06-11 5:08 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Pei Xiao @ 2026-06-11 0:44 UTC (permalink / raw)
To: linux, linux-hwmon, linux-kernel; +Cc: cryolitia, Pei Xiao
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid
2026-06-11 0:44 [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid Pei Xiao
@ 2026-06-11 5:07 ` Guenter Roeck
2026-06-11 5:08 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-06-11 5:07 UTC (permalink / raw)
To: Pei Xiao; +Cc: linux-hwmon, linux-kernel, cryolitia
On Thu, Jun 11, 2026 at 08:44:14AM +0800, Pei Xiao wrote:
> 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>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid
2026-06-11 0:44 [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid Pei Xiao
2026-06-11 5:07 ` Guenter Roeck
@ 2026-06-11 5:08 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-06-11 5:08 UTC (permalink / raw)
To: Pei Xiao; +Cc: linux-hwmon, linux-kernel, cryolitia
On Thu, Jun 11, 2026 at 08:44:14AM +0800, Pei Xiao wrote:
> 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>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-11 5:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-11 0:44 [PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid Pei Xiao
2026-06-11 5:07 ` Guenter Roeck
2026-06-11 5:08 ` Guenter Roeck
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®