Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup
@ 2026-12-02  2:24 Haoxiang Li
  2026-12-02  2:24 ` [PATCH 1/3] PCI: cpqphp: Clear the ROM pointer after unmapping Haoxiang Li
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-12-02  2:24 UTC (permalink / raw)
  To: bhelgaas, keithmo; +Cc: linux-pci, Haoxiang Li

This series fixes resource cleanup during setup and module unload in
the Compaq PCI hotplug driver.

Patch 1 clears the ROM pointer after unmapping it on setup failure.
Patch 2 starts the event thread after ROM and SMBIOS setup.
Patch 3 frees the interrupt routing table on setup failure and module
unload.

Compile-test passed.

Haoxiang Li (3):
  PCI: cpqphp: Clear the ROM pointer after unmapping
  PCI: cpqphp: Start the event thread after ROM and SMBIOS setup
  PCI: cpqphp: Free the IRQ routing table on failure and exit

 drivers/pci/hotplug/cpqphp_core.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)


base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
-- 
2.25.1


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

* [PATCH 1/3] PCI: cpqphp: Clear the ROM pointer after unmapping
  2026-12-02  2:24 [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup Haoxiang Li
@ 2026-12-02  2:24 ` Haoxiang Li
  2026-12-02  2:24 ` [PATCH 2/3] PCI: cpqphp: Start the event thread after ROM and SMBIOS setup Haoxiang Li
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-12-02  2:24 UTC (permalink / raw)
  To: bhelgaas, keithmo; +Cc: linux-pci, Haoxiang Li

If detect_SMBIOS_pointer() or the following ioremap() returns NULL,
one_time_init() unmaps the ROM and leaves cpqhp_rom_start set. On
module exit, unload_cpqphpd() tries to unmap that address again.

Clear cpqhp_rom_start after unmapping the ROM in one_time_init().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/pci/hotplug/cpqphp_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 76e26b9a9f0d..e466263361b5 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -747,6 +747,7 @@ static int one_time_init(void)
 	iounmap(smbios_start);
 error_rom_start:
 	iounmap(cpqhp_rom_start);
+	cpqhp_rom_start = NULL;
 error:
 	return retval;
 }
-- 
2.25.1


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

* [PATCH 2/3] PCI: cpqphp: Start the event thread after ROM and SMBIOS setup
  2026-12-02  2:24 [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup Haoxiang Li
  2026-12-02  2:24 ` [PATCH 1/3] PCI: cpqphp: Clear the ROM pointer after unmapping Haoxiang Li
@ 2026-12-02  2:24 ` Haoxiang Li
  2026-12-02  2:24 ` [PATCH 3/3] PCI: cpqphp: Free the IRQ routing table on failure and exit Haoxiang Li
  2026-12-02  2:33 ` [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-12-02  2:24 UTC (permalink / raw)
  To: bhelgaas, keithmo; +Cc: linux-pci, Haoxiang Li

one_time_init() starts the event thread before mapping the ROM.
If ioremap() or detect_SMBIOS_pointer() fails, the thread is not
stopped. A later probe can start a second thread.

Move cpqhp_event_start_thread() after both ioremap() calls succeed.
If cpqhp_event_start_thread() returns an error, unmap the SMBIOS
region, clear smbios_start, and fall through to the ROM cleanup.

Fixes: 4002307d2b56 ("[PATCH] cpqphp: fix oops during unload without probe")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/pci/hotplug/cpqphp_core.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index e466263361b5..60cbbf8bcaf1 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -695,12 +695,6 @@ static int one_time_init(void)
 	if (cpqhp_debug)
 		pci_print_IRQ_route();
 
-	dbg("Initialize + Start the notification mechanism\n");
-
-	retval = cpqhp_event_start_thread();
-	if (retval)
-		goto error;
-
 	dbg("Initialize slot lists\n");
 	for (loop = 0; loop < 256; loop++)
 		cpqhp_slot_list[loop] = NULL;
@@ -736,15 +730,22 @@ static int one_time_init(void)
 	if (!smbios_start) {
 		err("Could not ioremap memory region taken from SMBIOS values\n");
 		retval = -EIO;
-		goto error_smbios_start;
+		goto error_rom_start;
 	}
 
+	dbg("Initialize + Start the notification mechanism\n");
+
+	retval = cpqhp_event_start_thread();
+	if (retval)
+		goto error_smbios_start;
+
 	initialized = 1;
 
 	return retval;
 
 error_smbios_start:
 	iounmap(smbios_start);
+	smbios_start = NULL;
 error_rom_start:
 	iounmap(cpqhp_rom_start);
 	cpqhp_rom_start = NULL;
-- 
2.25.1


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

* [PATCH 3/3] PCI: cpqphp: Free the IRQ routing table on failure and exit
  2026-12-02  2:24 [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup Haoxiang Li
  2026-12-02  2:24 ` [PATCH 1/3] PCI: cpqphp: Clear the ROM pointer after unmapping Haoxiang Li
  2026-12-02  2:24 ` [PATCH 2/3] PCI: cpqphp: Start the event thread after ROM and SMBIOS setup Haoxiang Li
@ 2026-12-02  2:24 ` Haoxiang Li
  2026-12-02  2:33 ` [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-12-02  2:24 UTC (permalink / raw)
  To: bhelgaas, keithmo; +Cc: linux-pci, Haoxiang Li

If one_time_init() fails after init_cpqhp_routing_table() succeeds,
the routing table stays allocated. A retry can overwrite the pointer
and leak the old table. cpqhpc_cleanup() also leaks the table on
module exit.

Free the table and clear its pointer on these error paths. Run
one_time_init() under a mutex so a failing probe cannot free a table
that another probe is using. Free the table in cpqhpc_cleanup()
after pci_unregister_driver().

Fixes: b019ee679afd ("PCI Hotplug: cpqphp: clean up accesses to pcibios_get_irq_routing_table()")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/pci/hotplug/cpqphp_core.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 60cbbf8bcaf1..5ae164322a38 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -18,6 +18,7 @@
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <linux/mutex.h>
 #include <linux/proc_fs.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
@@ -46,6 +47,7 @@ static void __iomem *cpqhp_rom_start;
 static bool power_mode;
 static bool debug;
 static int initialized;
+static DEFINE_MUTEX(cpqhp_init_lock);
 
 #define DRIVER_VERSION	"0.9.8"
 #define DRIVER_AUTHOR	"Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
@@ -690,7 +692,7 @@ static int one_time_init(void)
 
 	retval = init_cpqhp_routing_table();
 	if (retval)
-		goto error;
+		return retval;
 
 	if (cpqhp_debug)
 		pci_print_IRQ_route();
@@ -708,7 +710,7 @@ static int one_time_init(void)
 	if (!cpqhp_rom_start) {
 		err("Could not ioremap memory region for ROM\n");
 		retval = -EIO;
-		goto error;
+		goto error_free_routing_table;
 	}
 
 	/* Now, map the int15 entry point if we are on compaq specific
@@ -749,7 +751,9 @@ static int one_time_init(void)
 error_rom_start:
 	iounmap(cpqhp_rom_start);
 	cpqhp_rom_start = NULL;
-error:
+error_free_routing_table:
+	kfree(cpqhp_routing_table);
+	cpqhp_routing_table = NULL;
 	return retval;
 }
 
@@ -1036,8 +1040,9 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	mutex_init(&ctrl->crit_sect);
 	init_waitqueue_head(&ctrl->queue);
 
-	/* initialize our threads if they haven't already been started up */
+	mutex_lock(&cpqhp_init_lock);
 	rc = one_time_init();
+	mutex_unlock(&cpqhp_init_lock);
 	if (rc)
 		goto err_free_bus;
 
@@ -1403,6 +1408,8 @@ static void __exit cpqhpc_cleanup(void)
 	dbg("pci_unregister_driver\n");
 	pci_unregister_driver(&cpqhpc_driver);
 	cpqhp_shutdown_debugfs();
+
+	kfree(cpqhp_routing_table);
 }
 
 module_init(cpqhpc_init);
-- 
2.25.1


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

* Re: [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup
  2026-12-02  2:24 [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup Haoxiang Li
                   ` (2 preceding siblings ...)
  2026-12-02  2:24 ` [PATCH 3/3] PCI: cpqphp: Free the IRQ routing table on failure and exit Haoxiang Li
@ 2026-12-02  2:33 ` sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-02  2:33 UTC (permalink / raw)
  To: Haoxiang Li; +Cc: linux-pci

Sashiko has reviewed this 3-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202022452.3910006-1-haoxiang_li2024@163.com

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

end of thread, other threads:[~2026-12-02  2:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  2:24 [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup Haoxiang Li
2026-12-02  2:24 ` [PATCH 1/3] PCI: cpqphp: Clear the ROM pointer after unmapping Haoxiang Li
2026-12-02  2:24 ` [PATCH 2/3] PCI: cpqphp: Start the event thread after ROM and SMBIOS setup Haoxiang Li
2026-12-02  2:24 ` [PATCH 3/3] PCI: cpqphp: Free the IRQ routing table on failure and exit Haoxiang Li
2026-12-02  2:33 ` [PATCH 0/3] PCI: cpqphp: Fix one-time setup and module cleanup sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox