All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: uniphier: Tear down legacy interrupts on host removal
@ 2026-11-29 16:30 Guangshuo Li
  2026-11-29 16:35 ` sashiko-bot
  2026-12-01  7:12 ` Kunihiko Hayashi
  0 siblings, 2 replies; 3+ messages in thread
From: Guangshuo Li @ 2026-11-29 16:30 UTC (permalink / raw)
  To: hayashi.kunihiko, lpieralisi, kwilczynski, mani, bhelgaas,
	mhiramat, p.zabel
  Cc: robh, linux-pci, linux-arm-kernel

The host driver leaves its chained handler and INTx domain installed
when host initialization fails or the driver is removed. Detach the
handler and release the interrupt mappings in the host deinit callback.
On removal, stop the root bus before releasing the controller resources.

This issue was found by our static analysis tool under development.

Fixes: 7e6d5cd88a6f ("PCI: uniphier: Add UniPhier PCIe host controller support")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/pci/controller/dwc/pcie-uniphier.c | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/dwc/pcie-uniphier.c b/drivers/pci/controller/dwc/pcie-uniphier.c
index 1c8d7694543f..4c9e75fbd8e3 100644
--- a/drivers/pci/controller/dwc/pcie-uniphier.c
+++ b/drivers/pci/controller/dwc/pcie-uniphier.c
@@ -282,6 +282,7 @@ static int uniphier_pcie_config_intx_irq(struct dw_pcie_rp *pp)
 	pcie->intx_irq_domain = irq_domain_create_linear(of_fwnode_handle(np_intc), PCI_NUM_INTX,
 						&uniphier_intx_domain_ops, pp);
 	if (!pcie->intx_irq_domain) {
+		irq_dispose_mapping(pp->irq);
 		dev_err(pci->dev, "Failed to get INTx domain\n");
 		ret = -ENODEV;
 		goto out_put_node;
@@ -310,8 +311,23 @@ static int uniphier_pcie_host_init(struct dw_pcie_rp *pp)
 	return 0;
 }
 
+static void uniphier_pcie_host_deinit(struct dw_pcie_rp *pp)
+{
+	struct uniphier_pcie *pcie = to_uniphier_pcie(to_dw_pcie_from_pp(pp));
+	unsigned int i;
+
+	writel(0, pcie->base + PCL_RCV_INT);
+	writel(0, pcie->base + PCL_RCV_INTX);
+	irq_set_chained_handler_and_data(pp->irq, NULL, NULL);
+	for (i = 0; i < PCI_NUM_INTX; i++)
+		irq_dispose_mapping(irq_find_mapping(pcie->intx_irq_domain, i));
+	irq_domain_remove(pcie->intx_irq_domain);
+	irq_dispose_mapping(pp->irq);
+}
+
 static const struct dw_pcie_host_ops uniphier_pcie_host_ops = {
 	.init = uniphier_pcie_host_init,
+	.deinit = uniphier_pcie_host_deinit,
 };
 
 static int uniphier_pcie_host_enable(struct uniphier_pcie *pcie)
@@ -348,6 +364,13 @@ static int uniphier_pcie_host_enable(struct uniphier_pcie *pcie)
 	return ret;
 }
 
+static void uniphier_pcie_host_disable(struct uniphier_pcie *pcie)
+{
+	phy_exit(pcie->phy);
+	reset_control_assert(pcie->rst);
+	clk_disable_unprepare(pcie->clk);
+}
+
 static const struct dw_pcie_ops dw_pcie_ops = {
 	.start_link = uniphier_pcie_start_link,
 	.stop_link = uniphier_pcie_stop_link,
@@ -391,7 +414,19 @@ static int uniphier_pcie_probe(struct platform_device *pdev)
 
 	pcie->pci.pp.ops = &uniphier_pcie_host_ops;
 
-	return dw_pcie_host_init(&pcie->pci.pp);
+	ret = dw_pcie_host_init(&pcie->pci.pp);
+	if (ret)
+		uniphier_pcie_host_disable(pcie);
+
+	return ret;
+}
+
+static void uniphier_pcie_remove(struct platform_device *pdev)
+{
+	struct uniphier_pcie *pcie = platform_get_drvdata(pdev);
+
+	dw_pcie_host_deinit(&pcie->pci.pp);
+	uniphier_pcie_host_disable(pcie);
 }
 
 static const struct of_device_id uniphier_pcie_match[] = {
@@ -401,6 +436,7 @@ static const struct of_device_id uniphier_pcie_match[] = {
 
 static struct platform_driver uniphier_pcie_driver = {
 	.probe  = uniphier_pcie_probe,
+	.remove = uniphier_pcie_remove,
 	.driver = {
 		.name = "uniphier-pcie",
 		.of_match_table = uniphier_pcie_match,

base-commit: 647e1e846730c6aad27e9b858df292f5d4377f63
-- 
2.43.0



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

end of thread, other threads:[~2026-12-01  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 16:30 [PATCH] PCI: uniphier: Tear down legacy interrupts on host removal Guangshuo Li
2026-11-29 16:35 ` sashiko-bot
2026-12-01  7:12 ` Kunihiko Hayashi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.