[PATCH] PCI: dra7xx: Remove the IRQ domain with the root port
Guangshuo Li
liguangshuo at mail.sdu.edu.cn
Sat Nov 28 01:42:52 PST 2026
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 at 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
More information about the linux-arm-kernel
mailing list