Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: dra7xx: Remove the IRQ domain with the root port
@ 2026-11-28  9:42 Guangshuo Li
  2026-11-28 10:05 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-28  9:42 UTC (permalink / raw)
  To: vigneshr, lpieralisi, kwilczynski, mani, bhelgaas, jg1.han,
	kishon
  Cc: s-vadapalli, robh, linux-omap, linux-pci, linux-arm-kernel

The platform driver leaves its INTx domain and chained handler pointing
to released controller data. Create them in the host init callback and
remove them from its matching deinit callback. On driver removal, stop
the controller before releasing its PHY and runtime PM reference.

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

Fixes: 47ff3de911a7 ("PCI: dra7xx: Add TI DRA7xx PCIe driver")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/pci/controller/dwc/pci-dra7xx.c | 60 ++++++++++++++++---------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c
index 1d8eeb013769..509d0068ee3f 100644
--- a/drivers/pci/controller/dwc/pci-dra7xx.c
+++ b/drivers/pci/controller/dwc/pci-dra7xx.c
@@ -91,6 +91,7 @@ struct dra7xx_pcie {
 	struct phy		**phy;
 	struct irq_domain	*irq_domain;
 	struct clk              *clk;
+	int			main_irq;
 };
 
 struct dra7xx_pcie_of_data {
@@ -176,16 +177,6 @@ static void dra7xx_pcie_enable_interrupts(struct dra7xx_pcie *dra7xx)
 	dra7xx_pcie_enable_msi_interrupts(dra7xx);
 }
 
-static int dra7xx_pcie_host_init(struct dw_pcie_rp *pp)
-{
-	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
-	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
-
-	dra7xx_pcie_enable_interrupts(dra7xx);
-
-	return 0;
-}
-
 static int dra7xx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
 				irq_hw_number_t hwirq)
 {
@@ -342,7 +333,7 @@ static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg)
 	return IRQ_HANDLED;
 }
 
-static int dra7xx_pcie_init_irq_domain(struct dw_pcie_rp *pp)
+static int dra7xx_pcie_host_init(struct dw_pcie_rp *pp)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	struct device *dev = pci->dev;
@@ -355,8 +346,6 @@ static int dra7xx_pcie_init_irq_domain(struct dw_pcie_rp *pp)
 		return -ENODEV;
 	}
 
-	irq_set_chained_handler_and_data(pp->irq, dra7xx_pcie_msi_irq_handler,
-					 pp);
 	dra7xx->irq_domain = irq_domain_create_linear(of_fwnode_handle(pcie_intc_node),
 						      PCI_NUM_INTX, &intx_domain_ops, pp);
 	of_node_put(pcie_intc_node);
@@ -365,11 +354,25 @@ static int dra7xx_pcie_init_irq_domain(struct dw_pcie_rp *pp)
 		return -ENODEV;
 	}
 
+	irq_set_chained_handler_and_data(pp->irq, dra7xx_pcie_msi_irq_handler, pp);
+	dra7xx_pcie_enable_interrupts(dra7xx);
 	return 0;
 }
 
+static void dra7xx_pcie_host_deinit(struct dw_pcie_rp *pp)
+{
+	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(to_dw_pcie_from_pp(pp));
+	unsigned int i;
+
+	irq_set_chained_handler_and_data(pp->irq, NULL, NULL);
+	for (i = 0; i < PCI_NUM_INTX; i++)
+		irq_dispose_mapping(irq_find_mapping(dra7xx->irq_domain, i));
+	irq_domain_remove(dra7xx->irq_domain);
+}
+
 static const struct dw_pcie_host_ops dra7xx_pcie_host_ops = {
 	.init = dra7xx_pcie_host_init,
+	.deinit = dra7xx_pcie_host_deinit,
 };
 
 static int dra7xx_pcie_ep_init(struct dw_pcie_ep *ep)
@@ -490,10 +493,6 @@ static int dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
 	/* MSI IRQ is muxed */
 	pp->msi_irq[0] = -ENODEV;
 
-	ret = dra7xx_pcie_init_irq_domain(pp);
-	if (ret < 0)
-		return ret;
-
 	pci->dbi_base = devm_platform_ioremap_resource_byname(pdev, "rc_dbics");
 	if (IS_ERR(pci->dbi_base))
 		return PTR_ERR(pci->dbi_base);
@@ -671,6 +670,14 @@ static int dra7xx_pcie_configure_two_lane(struct device *dev,
 	return 0;
 }
 
+static void dra7xx_pcie_deinit(struct dra7xx_pcie *dra7xx)
+{
+	if (dra7xx->pci->mode == DW_PCIE_RC_TYPE)
+		dw_pcie_host_deinit(&dra7xx->pci->pp);
+	else
+		dw_pcie_ep_deinit(&dra7xx->pci->ep);
+}
+
 static int dra7xx_pcie_probe(struct platform_device *pdev)
 {
 	u32 reg;
@@ -814,6 +821,7 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 		dev_err(dev, "INVALID device type %d\n", mode);
 	}
 	dra7xx->pci->mode = mode;
+	dra7xx->main_irq = irq;
 
 	ret = devm_request_threaded_irq(dev, irq, NULL, dra7xx_pcie_irq_handler,
 					IRQF_SHARED | IRQF_ONESHOT,
@@ -826,10 +834,7 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	return 0;
 
 err_deinit:
-	if (dra7xx->pci->mode == DW_PCIE_RC_TYPE)
-		dw_pcie_host_deinit(&dra7xx->pci->pp);
-	else
-		dw_pcie_ep_deinit(&dra7xx->pci->ep);
+	dra7xx_pcie_deinit(dra7xx);
 
 err_gpio:
 err_get_sync:
@@ -840,6 +845,18 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void dra7xx_pcie_remove(struct platform_device *pdev)
+{
+	struct dra7xx_pcie *dra7xx = platform_get_drvdata(pdev);
+	struct device *dev = &pdev->dev;
+
+	devm_free_irq(dev, dra7xx->main_irq, dra7xx);
+	dra7xx_pcie_deinit(dra7xx);
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
+	dra7xx_pcie_disable_phy(dra7xx);
+}
+
 static int dra7xx_pcie_suspend(struct device *dev)
 {
 	struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
@@ -923,6 +940,7 @@ static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
 
 static struct platform_driver dra7xx_pcie_driver = {
 	.probe = dra7xx_pcie_probe,
+	.remove = dra7xx_pcie_remove,
 	.driver = {
 		.name	= "dra7-pcie",
 		.of_match_table = of_dra7xx_pcie_match,

base-commit: 647e1e846730c6aad27e9b858df292f5d4377f63
-- 
2.43.0


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

* Re: [PATCH] PCI: dra7xx: Remove the IRQ domain with the root port
  2026-11-28  9:42 [PATCH] PCI: dra7xx: Remove the IRQ domain with the root port Guangshuo Li
@ 2026-11-28 10:05 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-28 10:05 UTC (permalink / raw)
  To: Guangshuo Li; +Cc: linux-pci

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] PCI: dra7xx: missing link stop and EPC deinit in
  dra7xx_pcie_deinit()
--

commit d00611bbb3d39d9987ab2f13aa6f0204c6621bbb
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

PCI: dra7xx: Remove the IRQ domain with the root port

This commit moves the INTx IRQ domain and chained handler setup into the
root port host init callback and removes them in a matching host deinit
callback, while also adding a platform driver remove callback.

> diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c
> index 0d56fd5a19ea0..0264cd4fbe8d4 100644
> --- a/drivers/pci/controller/dwc/pci-dra7xx.c
> +++ b/drivers/pci/controller/dwc/pci-dra7xx.c

[ ... ]

> @@ -671,6 +670,14 @@ static int dra7xx_pcie_configure_two_lane(struct device *dev,
>  	return 0;
>  }
>  
> +static void dra7xx_pcie_deinit(struct dra7xx_pcie *dra7xx)
> +{
> +	if (dra7xx->pci->mode == DW_PCIE_RC_TYPE)
> +		dw_pcie_host_deinit(&dra7xx->pci->pp);
> +	else
> +		dw_pcie_ep_deinit(&dra7xx->pci->ep);
> +}

[Severity: Medium]
In the endpoint branch, should dra7xx_pcie_deinit() also call
dw_pcie_stop_link() and pci_epc_deinit_notify() before
dw_pcie_ep_deinit()?

Unlike dw_pcie_host_deinit(), dw_pcie_ep_deinit() does not stop the link
or notify bound endpoint functions of deinitialization (to pair with
pci_epc_init_notify() in dra7xx_add_pcie_ep()).  When
dra7xx_pcie_remove() then disables runtime PM and the PHYs, LTSSM_EN can
remain active and epc->init_complete stays true, causing a later EPF
unbind to access unclocked DBI registers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-f81b700d6c-u40-0@mail.sdu.edu.cn?part=1

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

end of thread, other threads:[~2026-11-28 10:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  9:42 [PATCH] PCI: dra7xx: Remove the IRQ domain with the root port Guangshuo Li
2026-11-28 10:05 ` sashiko-bot

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