From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH] cpufreq: nforce2: put PCI device on driver register failure
Date: Wed, 8 Jul 2026 22:43:21 +0800 [thread overview]
Message-ID: <4ac18ed1-0807-443a-9031-c0bdb885fec6@oss.qualcomm.com> (raw)
In-Reply-To: <20260708110131.748268-1-lgs201920130244@gmail.com>
On 7/8/2026 7:01 PM, Guangshuo Li wrote:
> nforce2_detect_chipset() stores a PCI device returned by
> pci_get_subsys() in the global nforce2_dev pointer. That reference is
> kept for the lifetime of the loaded module and is released from
> nforce2_exit().
>
> However, nforce2_init() gets the PCI device reference before registering
> the cpufreq driver. If cpufreq_register_driver() fails, nforce2_init()
> returns an error and the module exit path is not run. The reference held
> in nforce2_dev is then leaked.
>
> Drop the PCI device reference before returning from the registration
> failure path. Clear the global pointer as well so the failed
> initialization leaves no stale reference behind.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/cpufreq/cpufreq-nforce2.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nforce2.c
> index 831102522ad6..5a101c69c47a 100644
> --- a/drivers/cpufreq/cpufreq-nforce2.c
> +++ b/drivers/cpufreq/cpufreq-nforce2.c
> @@ -409,6 +409,8 @@ static int nforce2_detect_chipset(void)
> */
> static int __init nforce2_init(void)
> {
> + int ret;
> +
> /* TODO: do we need to detect the processor? */
>
> /* detect chipset */
> @@ -417,7 +419,13 @@ static int __init nforce2_init(void)
> return -ENODEV;
> }
>
> - return cpufreq_register_driver(&nforce2_driver);
> + ret = cpufreq_register_driver(&nforce2_driver);
> + if (ret) {
> + pci_dev_put(nforce2_dev);
> + nforce2_dev = NULL;
nit: setting nforce2_dev to NULL looks redundant here.
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
> + }
> +
> + return ret;
> }
>
> /**
--
Thx and BRs,
Zhongqiu Han
prev parent reply other threads:[~2026-07-08 14:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 11:01 [PATCH] cpufreq: nforce2: put PCI device on driver register failure Guangshuo Li
2026-07-08 14:43 ` Zhongqiu Han [this message]
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=4ac18ed1-0807-443a-9031-c0bdb885fec6@oss.qualcomm.com \
--to=zhongqiu.han@oss.qualcomm.com \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
/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