[PATCH v2] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid

From: Pei Xiao

Date: Wed Jun 10 2026 - 20:44:35 EST


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@xxxxxxxxxx>
---
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