mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pei Xiao <xiaopei01@kylinos.cn>
To: Cryolitia PukNgae <cryolitia@uniontech.com>,
	linux@roeck-us.net, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: (gpd-fan) Reject EC PWM value 0 as invalid
Date: Wed, 10 Jun 2026 09:10:38 +0800	[thread overview]
Message-ID: <e8bb6993-e533-406e-a389-5bf5d670a93e@kylinos.cn> (raw)
In-Reply-To: <305E2395B7027B5B+e851d97c-2af5-4752-8c1c-7f92884fe874@uniontech.com>



在 2026/6/9 23:41, Cryolitia PukNgae 写道:
>
> On 6/9/26 07:41, 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>
>> ---
>>   drivers/hwmon/gpd-fan.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwmon/gpd-fan.c b/drivers/hwmon/gpd-fan.c
>> index d1993cd645cb..decb61936b95 100644
>> --- a/drivers/hwmon/gpd-fan.c
>> +++ b/drivers/hwmon/gpd-fan.c
>> @@ -341,7 +341,11 @@ static int gpd_wm2_read_pwm(struct gpd_fan_data *data)
>>         gpd_ecram_read(drvdata, drvdata->pwm_write, &var);
>>   -    // Match gpd_generic_write_pwm(u8) below
>> +    /* EC PWM register valid range is 1 ~ pwm_max; 0 is an invalid
>> state */
>> +    if (unlikely(!var))
>> +        return -EIO;
>> +
>> +    /* Match gpd_generic_write_pwm() below */
>>       return DIV_ROUND_CLOSEST((var - 1) * 255, (drvdata->pwm_max - 1));
>>   }
>>   
>
> Have you ever tested the behavior on a real device? When it returns 0,
> what state is the device in? 
>
Hi Cryolitia,

Thanks for your  messages!
Yes, this is not an issue, but this problem was reported during the Sashiko
AI review.
 The maintainer suggested I take a look. After checking, I think it might
be better to add a check: 
if it's 0, just return directly. In case some EC returns 0 someday, causing
an underflow, 
returning an error code would be more intuitive than returning an incorrect
value.

https://sashiko.dev/#/patchset/cover.1780880972.git.xiaopei01@kylinos.cn?part=1

Pei.
>
> thanks,
>
> Cryolitia PukNgae


  reply	other threads:[~2026-06-10  1:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09  7:41 Pei Xiao
2026-06-09 15:41 ` Cryolitia PukNgae
2026-06-10  1:10   ` Pei Xiao [this message]
2026-06-10  3:58     ` Guenter Roeck
2026-06-10 13:27 ` 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=e8bb6993-e533-406e-a389-5bf5d670a93e@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®