Linux Power Management development
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>
Subject: [PATCH] cpufreq: nforce2: put PCI device on driver register failure
Date: Wed,  8 Jul 2026 19:01:31 +0800	[thread overview]
Message-ID: <20260708110131.748268-1-lgs201920130244@gmail.com> (raw)

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;
+	}
+
+	return ret;
 }
 
 /**
-- 
2.43.0


             reply	other threads:[~2026-07-08 11:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 11:01 Guangshuo Li [this message]
2026-07-08 14:43 ` [PATCH] cpufreq: nforce2: put PCI device on driver register failure Zhongqiu Han

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=20260708110131.748268-1-lgs201920130244@gmail.com \
    --to=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