Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] cpufreq: nforce2: put PCI device on driver register failure
@ 2026-07-08 11:01 Guangshuo Li
  2026-07-08 14:43 ` Zhongqiu Han
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-07-08 11:01 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar, linux-pm, linux-kernel; +Cc: Guangshuo Li

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-08 14:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox