All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: xiaopeitux@foxmail.com
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v3 2/4] hwmon: (gpd-fan): Initialize EC before registering hwmon device
Date: Mon, 08 Jun 2026 01:53:07 +0000	[thread overview]
Message-ID: <20260608015308.166CF1F00893@smtp.kernel.org> (raw)
In-Reply-To: <tencent_BEAA4E485EAFA713FF395F57AC083EEE3507@qq.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Reading a PWM value of 0 from the EC results in an integer underflow, causing sysfs reads to return a spurious error code.
- [High] The driver statically and exclusively requests standard Super I/O ports, preventing dynamic resource sharing and risking I/O collisions.
--

commit 56dbaa61ebc060459a8d3ef1f7c952d1f935af40
Author: Pei Xiao <xiaopei01@kylinos.cn>
Subject: hwmon: (gpd-fan): Initialize EC before registering hwmon device

This patch moves the EC initialization before the hardware monitoring
device registration. This prevents a race condition where sysfs reads
could return invalid values before the EC is properly initialized.

> Some buggy firmware won't initialize EC properly on boot. Before its
> initialization, reading RPM will always return 0, and writing PWM will have
> no effect. So move gpd_init_ec to before hwmon device register.

[Severity: High]
This is a pre-existing issue, but does the driver handle a valid PWM read
of 0 correctly?

Looking at gpd_wm2_read_pwm(), the raw PWM value 'var' is an unsigned 8-bit
integer. If the EC returns 0 (e.g., when the fan is stopped), the expression
'(var - 1)' mathematically underflows and promotes to a signed integer (-1).
Multiplying by 255 and passing it to DIV_ROUND_CLOSEST yields a negative value:

gpd_wm2_read_pwm() {
    ...
    return DIV_ROUND_CLOSEST((var - 1) * 255, (drvdata->pwm_max - 1));
}

This negative return value propagates up to gpd_fan_hwmon_read(), which
interprets it as an error code (-1 mapping to -EPERM), causing the sysfs read
for pwm1 to fail. Can this be updated to safely handle a PWM value of 0?

> diff --git a/drivers/hwmon/gpd-fan.c b/drivers/hwmon/gpd-fan.c
> index 7284babd4f5c9..745b3fb9e3a49 100644
> --- a/drivers/hwmon/gpd-fan.c
> +++ b/drivers/hwmon/gpd-fan.c
> @@ -643,6 +643,7 @@ static int gpd_fan_probe(struct platform_device *pdev)
>  
>  	dev_set_drvdata(dev, data);
>  
> +	gpd_init_ec(data);
>  	hwdev = devm_hwmon_device_register_with_info(dev,
>  						     DRIVER_NAME,

[Severity: High]
This isn't a bug introduced by this patch, but does this probe function
exclusively claim globally shared Super I/O ports?

Looking earlier in gpd_fan_probe(), the driver statically requests standard
Super I/O address and data ports exclusively for the lifetime of the module:

gpd_fan_probe() {
    ...
    region = devm_request_region(dev, res->start,
                                 resource_size(res), DRIVER_NAME);
    ...
}

Because Super I/O ports are globally shared, permanently claiming them prevents
other drivers (like watchdogs or RTCs) from probing. Should this use
request_muxed_region() to dynamically lock the ports around each I/O sequence
instead?

>  						     data,
> @@ -651,9 +652,6 @@ static int gpd_fan_probe(struct platform_device *pdev)
>  	if (IS_ERR(hwdev))
>  		return dev_err_probe(dev, PTR_ERR(hwdev),
>  				     "Failed to register hwmon device\n");
> -
> -	gpd_init_ec(data);
> -
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1780880972.git.xiaopei01@kylinos.cn?part=2

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

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1780880972.git.xiaopei01@kylinos.cn>
2026-06-08  1:40 ` [PATCH v3 1/4] hwmon: (gpd-fan): drop global driver data and use per-device allocation xiaopeitux
2026-06-08  1:52   ` sashiko-bot
2026-06-08  1:40 ` [PATCH v3 2/4] hwmon: (gpd-fan): Initialize EC before registering hwmon device xiaopeitux
2026-06-08  1:53   ` sashiko-bot [this message]
2026-06-08 13:01     ` Guenter Roeck
2026-06-08  1:40 ` [PATCH v3 3/4] hwmon: (gpd-fan): upgrade log level from warn to err for platform device creation failure xiaopeitux
2026-06-08  1:48   ` sashiko-bot
2026-06-08  1:40 ` [PATCH v3 4/4] hwmon: (gpd-fan): fix race condition between device removal and sysfs access xiaopeitux
2026-06-08  1:47   ` sashiko-bot

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=20260608015308.166CF1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xiaopeitux@foxmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.