PCI: mt7621: Release port reset controls on probe failure
Subsystems (5)
PATCH 1/1 PCI: mt7621: Release port reset controls on probe failure
mt7621_pcie_parse_port() takes an exclusive reset control for each root port and adds the port to pcie->ports. If a later port then fails to parse, for instance because its PHY or reset GPIO returns -EPROBE_DEFER, mt7621_pcie_probe() returns without putting the reset controls of the ports already on the list. A failure of mt7621_pcie_register_host() returns without putting them as well.
On the next probe attempt, of_reset_control_get_exclusive() for an earlier port finds its reset control still acquired, warns and returns -EBUSY. mt7621_pcie_parse_port() only treats -EPROBE_DEFER as fatal, so probe continues with an error pointer as that port's reset control, and the later assert and deassert calls warn and fail.
Jump to remove_resets in both cases, as the mt7621_pcie_enable_ports() failure path already does.
---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_PCIE_MT7621=y, COMPILE_TEST=y; baseline and patched pcie-mt7621.o, no new warnings. No hardware or runtime test was performed.
Hit when a later root port's PHY or reset GPIO defers (or its DT node is malformed) after an earlier port took its reset, or when pci_host_probe() fails.
Independent of Sreeraj S Kurup's "PCI: mt7621: Fix reset control leak on PHY initialization failure" (now in linux-next as db7c929526a3), which covers the mt7621_pcie_init_ports() path; this patch applies on top of it (checked against next-20261111).
drivers/pci/controller/pcie-mt7621.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-mt7621.c +6 -2
@@ -495,7 +495,7 @@ static int mt7621_pcie_probe(struct platform_device *pdev) err =mt7621_pcie_parse_dt (pcie);if (err) {dev_err (dev,"parsing DT failed\n" ); -return err; + goto remove_resets; } err =mt7621_pcie_init_ports (pcie);
@@ -510,7 +510,11 @@ static int mt7621_pcie_probe(struct platform_device *pdev) goto remove_resets; } -return mt7621_pcie_register_host (bridge); + err =mt7621_pcie_register_host (bridge); +if (err) + goto remove_resets; + +return 0 ; remove_resets:list_for_each_entry (port, &pcie->ports, list)
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 13 lines
mt7621_pcie_parse_port()takes an exclusive reset control for each root port and adds the port topcie->ports. If a later port then fails to parse, for instance because its PHY or reset GPIO returns -EPROBE_DEFER,mt7621_pcie_probe()returns without putting the reset controls of the ports already on the list. A failure ofmt7621_pcie_register_host()returns without putting them as well.On the next probe attempt,
of_reset_control_get_exclusive()for an earlier port finds its reset control still acquired, warns and returns-EBUSY.mt7621_pcie_parse_port()only treats -EPROBE_DEFER as fatal, so probe continues with an error pointer as that port's reset control, and the later assert and deassert calls warn and fail.
Quoted 6 lines
Jump to
remove_resetsin both cases, as themt7621_pcie_enable_ports()failure path already does.Fixes 2bdd5238e756 ("PCI: mt7621: Add MediaTek MT7621 PCIe host controller driver")Signed-off-by Yige Jiang <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Sergio Paracuellos
maintainerHi,
Thanks for your patch.
Quoted 36 lines · Yige Jiang
mt7621_pcie_parse_port()takes an exclusive reset control for each root port and adds the port topcie->ports. If a later port then fails to parse, for instance because its PHY or reset GPIO returns -EPROBE_DEFER,mt7621_pcie_probe()returns without putting the reset controls of the ports already on the list. A failure ofmt7621_pcie_register_host()returns without putting them as well.On the next probe attempt,
of_reset_control_get_exclusive()for an earlier port finds its reset control still acquired, warns and returns-EBUSY.mt7621_pcie_parse_port()only treats -EPROBE_DEFER as fatal, so probe continues with an error pointer as that port's reset control, and the later assert and deassert calls warn and fail.Jump to
remove_resetsin both cases, as themt7621_pcie_enable_ports()failure path already does.Fixes 2bdd5238e756 ("PCI: mt7621: Add MediaTek MT7621 PCIe host controller driver")Signed-off-by Yige Jiang <[email protected]>---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, GCC 14.2.0, W=1,CONFIG_PCIE_MT7621=y, COMPILE_TEST=y; baseline and patched pcie-mt7621.o, no new warnings. No hardware or runtime test was performed.
Hit when a later root port's PHY or reset GPIO defers (or its DT node is malformed) after an earlier port took its reset, or whenpci_host_probe()fails.Independent of Sreeraj S Kurup's "PCI: mt7621: Fix reset control leak on PHY initialization failure" (now in linux-next as
db7c929526a3), which covers themt7621_pcie_init_ports()path; this patch applies on top of it (checked against next-20261111).drivers/pci/controller/pcie-mt7621.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/pci/controller/pcie-mt7621.c +0
-0
drivers/pci/controller/pcie-mt7621.c static int mt7621_pcie_probe(struct platform_device *pdev) · line 499
Quoted 6 lines
drivers/pci/controller/pcie-mt7621.c +1
-1@@ -495,7 +495,7 @@ static int mt7621_pcie_probe(struct platform_device *pdev) err =mt7621_pcie_parse_dt (pcie);if (err) {dev_err (dev,"parsing DT failed\n" ); -return err; + goto remove_resets; }
This is unlikely to happen. However even that, reset resources are handled and removed internally on mt7621_pcie_parse_port() on this path when reset is already got. Thus, this is not needed at all.
drivers/pci/controller/pcie-mt7621.c static int mt7621_pcie_probe(struct platform_device *pdev) · line 517
Quoted 12 lines
drivers/pci/controller/pcie-mt7621.c +5
-1err =mt7621_pcie_init_ports (pcie);@@ -510,7 +510,11 @@ static int mt7621_pcie_probe(struct platform_device *pdev) goto remove_resets; } -return mt7621_pcie_register_host (bridge); + err =mt7621_pcie_register_host (bridge); +if (err) + goto remove_resets; + +return 0 ;
This is correct, though. This calls internally to pci_host_probe() and if it fails we should properly remove resets.
Can you send v2 with only this change?
Quoted 5 lines
drivers/pci/controller/pcie-mt7621.c +0
-0remove_resets:list_for_each_entry (port, &pcie->ports, list)base-commit:
630059a5a632377b9b7b487baccde92b7ae1dd47
Thanks,
Sergio Paracuellos
Thank you for pointing this out and V2 has been sent.
Best,
Yige
Quoted 80 lines · Sergio Paracuellos
Hi,
Thanks for your patch.
Quoted 36 lines · Yige Jiang
mt7621_pcie_parse_port()takes an exclusive reset control for each root port and adds the port topcie->ports. If a later port then fails to parse, for instance because its PHY or reset GPIO returns -EPROBE_DEFER,mt7621_pcie_probe()returns without putting the reset controls of the ports already on the list. A failure ofmt7621_pcie_register_host()returns without putting them as well.On the next probe attempt,
of_reset_control_get_exclusive()for an earlier port finds its reset control still acquired, warns and returns-EBUSY.mt7621_pcie_parse_port()only treats -EPROBE_DEFER as fatal, so probe continues with an error pointer as that port's reset control, and the later assert and deassert calls warn and fail.Jump to
remove_resetsin both cases, as themt7621_pcie_enable_ports()failure path already does.Fixes 2bdd5238e756 ("PCI: mt7621: Add MediaTek MT7621 PCIe host controller driver")Signed-off-by Yige Jiang <[email protected]>---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, GCC 14.2.0, W=1,CONFIG_PCIE_MT7621=y, COMPILE_TEST=y; baseline and patched pcie-mt7621.o, no new warnings. No hardware or runtime test was performed.
Hit when a later root port's PHY or reset GPIO defers (or its DT node is malformed) after an earlier port took its reset, or whenpci_host_probe()fails.Independent of Sreeraj S Kurup's "PCI: mt7621: Fix reset control leak on PHY initialization failure" (now in linux-next as
db7c929526a3), which covers themt7621_pcie_init_ports()path; this patch applies on top of it (checked against next-20261111).
drivers/pci/controller/pcie-mt7621.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)drivers/pci/controller/pcie-mt7621.c +0
-0drivers/pci/controller/pcie-mt7621.c static int mt7621_pcie_probe(struct platform_device *pdev) · line 499
Quoted 6 lines
drivers/pci/controller/pcie-mt7621.c +1
-1@@ -495,7 +495,7 @@ static int mt7621_pcie_probe(struct platform_device *pdev) err =mt7621_pcie_parse_dt (pcie);if (err) {dev_err (dev,"parsing DT failed\n" ); -return err; + goto remove_resets; }This is unlikely to happen. However even that, reset resources are handled and removed internally on
mt7621_pcie_parse_port()on this path when reset is already got. Thus, this is not needed at all.drivers/pci/controller/pcie-mt7621.c static int mt7621_pcie_probe(struct platform_device *pdev) · line 517
Quoted 12 lines
drivers/pci/controller/pcie-mt7621.c +5
-1err =mt7621_pcie_init_ports (pcie);@@ -510,7 +510,11 @@ static int mt7621_pcie_probe(struct platform_device *pdev) goto remove_resets; } -return mt7621_pcie_register_host (bridge); + err =mt7621_pcie_register_host (bridge); +if (err) + goto remove_resets; + +return 0 ;This is correct, though. This calls internally to
pci_host_probe()and if it fails we should properly remove resets.Can you send v2 with only this change?
Quoted 5 lines
remove_resets:list_for_each_entry(port, &pcie->ports, list)base-commit:
630059a5a632377b9b7b487baccde92b7ae1dd47Thanks,
Sergio Paracuellos