]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (gpd-fan) Reject EC PWM value 0 as invalid
authorPei Xiao <xiaopei01@kylinos.cn>
Thu, 11 Jun 2026 00:44:14 +0000 (08:44 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 11 Jun 2026 05:07:17 +0000 (22:07 -0700)
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>
Link: https://lore.kernel.org/r/1c2ffa0d832ae3a74f6d4ffa7cc7b7e6cced69e3.1781138459.git.xiaopei01@kylinos.cn
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/gpd-fan.c

index d1993cd645cbc3520fbf5c6bea81c71b53dff0d2..ed212615b2fe99f56a6f924ca7e528023600e4de 100644 (file)
@@ -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));
 }