Skip to contentSkip to conversation

PCI: switchtec: Fix PCI device reference leak on probe failure

PATCH Applied Yige Jiang 4 participants 4 messages Nov 5

Subsystems (2)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH 1/1 PCI: switchtec: Fix PCI device reference leak on probe failure

stdev_create() takes a pci_dev reference for stdev->pdev. When a later step of switchtec_pci_probe() fails, err_put drops stdev->dev but omits the PCI device reference. stdev_release() only frees stdev, so the PCI device remains pinned after the failed probe.

Return the PCI device reference before putting stdev->dev, matching the existing cleanup in stdev_create() and switchtec_pci_remove().

Fixes df25461119d9 ("PCI: switchtec: Fix stdev_release() crash after surprise hot remove")

---
Based on linux-next next-20261102 (2637bdec0535).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_OF_DYNAMIC=y. COMPILE_TEST=y.
Baseline and patched target objects built from this exact base. No full kernel/module-link, hardware or runtime test was performed. AI assistance was used for analysis and patch preparation.

 drivers/pci/switch/switchtec.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/switch/switchtec.c +1 -0
index 5711aaa5df11..56a370ac9f27 100644
@@ -1698,6 +1698,7 @@ err_exit_pci:
 	switchtec_exit_pci(stdev);
 err_put:
 	ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt));
+	pci_dev_put(stdev->pdev);
 	put_device(&stdev->dev);
 	return rc;
 }

base-commit: 2637bdec0535a2044cd830eba9a79363651d9043

#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

stdev_create() takes a pci_dev reference for stdev->pdev. When a later step of switchtec_pci_probe() fails, err_put drops stdev->dev but omits the PCI device reference. stdev_release() only frees stdev, so the PCI device remains pinned after the failed probe.

Return the PCI device reference before putting stdev->dev, matching the existing cleanup in stdev_create() and switchtec_pci_remove().

Fixes df25461119d9 ("PCI: switchtec: Fix stdev_release() crash after surprise hot remove")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Yige Jiang
Quoted 10 lines · Yige Jiang

stdev_create() takes a pci_dev reference for stdev->pdev. When a later step of switchtec_pci_probe() fails, err_put drops stdev->dev but omits the PCI device reference. stdev_release() only frees stdev, so the PCI device remains pinned after the failed probe.

Return the PCI device reference before putting stdev->dev, matching the existing cleanup in stdev_create() and switchtec_pci_remove().

Fixes df25461119d9 ("PCI: switchtec: Fix stdev_release() crash after surprise hot remove")

Thanks! This looks correct to me.

#3 lore raw
In reply to Yige Jiang
Quoted 10 lines · Yige Jiang

stdev_create() takes a pci_dev reference for stdev->pdev. When a later step of switchtec_pci_probe() fails, err_put drops stdev->dev but omits the PCI device reference. stdev_release() only frees stdev, so the PCI device remains pinned after the failed probe.

Return the PCI device reference before putting stdev->dev, matching the existing cleanup in stdev_create() and switchtec_pci_remove().

Fixes df25461119d9 ("PCI: switchtec: Fix stdev_release() crash after surprise hot remove")

Applied to pci/switchtec for v7.5, thanks!

Quoted 25 lines

---
Based on linux-next next-20261102 (2637bdec0535).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_OF_DYNAMIC=y. COMPILE_TEST=y.
Baseline and patched target objects built from this exact base. No full kernel/module-link, hardware or runtime test was performed. AI assistance was used for analysis and patch preparation.

 drivers/pci/switch/switchtec.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/switch/switchtec.c +1 -0
index 5711aaa5df11..56a370ac9f27 100644
@@ -1698,6 +1698,7 @@ err_exit_pci:
 	switchtec_exit_pci(stdev);
 err_put:
 	ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt));
+	pci_dev_put(stdev->pdev);
 	put_device(&stdev->dev);
 	return rc;
 }

base-commit: 2637bdec0535a2044cd830eba9a79363651d9043