* [PATCH] PCI: switchtec: Fix PCI device reference leak on probe failure
@ 2026-11-05 7:55 Yige Jiang
2026-11-05 17:37 ` Logan Gunthorpe
2026-11-05 19:14 ` Bjorn Helgaas
0 siblings, 2 replies; 3+ messages in thread
From: Yige Jiang @ 2026-11-05 7:55 UTC (permalink / raw)
To: linux-pci
Cc: Yige Jiang, Kurt Schwemmer, Logan Gunthorpe, Bjorn Helgaas,
linux-kernel, Daniel Stodden
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")
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
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(+)
diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 5711aaa5df11..56a370ac9f27 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: switchtec: Fix PCI device reference leak on probe failure
2026-11-05 7:55 [PATCH] PCI: switchtec: Fix PCI device reference leak on probe failure Yige Jiang
@ 2026-11-05 17:37 ` Logan Gunthorpe
2026-11-05 19:14 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Logan Gunthorpe @ 2026-11-05 17:37 UTC (permalink / raw)
To: Yige Jiang, linux-pci
Cc: Kurt Schwemmer, Bjorn Helgaas, linux-kernel, Daniel Stodden
On 2026-11-05 1:55 a.m., Yige Jiang wrote:
> 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")
> Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
Thanks! This looks correct to me.
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: switchtec: Fix PCI device reference leak on probe failure
2026-11-05 7:55 [PATCH] PCI: switchtec: Fix PCI device reference leak on probe failure Yige Jiang
2026-11-05 17:37 ` Logan Gunthorpe
@ 2026-11-05 19:14 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2026-11-05 19:14 UTC (permalink / raw)
To: Yige Jiang
Cc: linux-pci, Kurt Schwemmer, Logan Gunthorpe, Bjorn Helgaas,
linux-kernel, Daniel Stodden
On Thu, Nov 05, 2026 at 03:55:01PM +0800, Yige Jiang wrote:
> 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")
> Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
Applied to pci/switchtec for v7.5, thanks!
> ---
> 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(+)
>
> diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
> index 5711aaa5df11..56a370ac9f27 100644
> --- a/drivers/pci/switch/switchtec.c
> +++ b/drivers/pci/switch/switchtec.c
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-05 19:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 7:55 [PATCH] PCI: switchtec: Fix PCI device reference leak on probe failure Yige Jiang
2026-11-05 17:37 ` Logan Gunthorpe
2026-11-05 19:14 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®