* [PATCH] PCI: apple: Release port IRQs and domains on driver detach
@ 2026-11-26 8:28 Guangshuo Li
2026-11-26 8:42 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-26 8:28 UTC (permalink / raw)
To: maz, lpieralisi, kwilczynski, mani, bhelgaas; +Cc: robh, linux-pci
The port handlers and interrupt domains remain registered after their
controller storage is freed on probe failure or module unload. Make the
link IRQ requests and domain teardown device-managed, and stop the PCI
bus before releasing the ports and their shared MSI parent.
This issue was found by our static analysis tool under development.
Fixes: d8fcbe52d7d3 ("PCI: apple: Add INTx and per-port interrupt support")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/pci/controller/pcie-apple.c | 50 ++++++++++++++++++++++-------
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index dfd0e345bc56..79dac3fb9a05 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -199,6 +199,7 @@ struct apple_pcie_port {
void __iomem *base;
void __iomem *phy;
struct irq_domain *domain;
+ unsigned int irq;
struct list_head entry;
unsigned long *sid_map;
int sid_map_sz;
@@ -396,6 +397,22 @@ static void apple_port_irq_handler(struct irq_desc *desc)
chained_irq_exit(chip, desc);
}
+static void apple_pcie_port_remove_irq(void *data)
+{
+ struct apple_pcie_port *port = data;
+ unsigned int i;
+
+ writel_relaxed(~0, port->base + PORT_INTMSK);
+ writel_relaxed(0, port->base + PORT_MSICFG);
+ irq_set_chained_handler_and_data(port->irq, NULL, NULL);
+ for (i = 0; i < 32; i++)
+ irq_dispose_mapping(irq_find_mapping(port->domain, i));
+ irq_domain_remove(port->domain);
+ irq_dispose_mapping(port->irq);
+ list_del(&port->entry);
+ of_node_put(port->np);
+}
+
static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
{
struct fwnode_handle *fwnode = &port->np->fwnode;
@@ -412,8 +429,11 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
port->domain = irq_domain_create_linear(fwnode, 32,
&apple_port_irq_domain_ops,
port);
- if (!port->domain)
+ if (!port->domain) {
+ irq_dispose_mapping(irq);
return -ENOMEM;
+ }
+ port->irq = irq;
/* Disable all interrupts */
writel_relaxed(~0, port->base + PORT_INTMSK);
@@ -441,7 +461,8 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
}
writel_relaxed(val | PORT_MSICFG_EN, port->base + PORT_MSICFG);
- return 0;
+ of_node_get(port->np);
+ return devm_add_action_or_reset(pcie->dev, apple_pcie_port_remove_irq, port);
}
static irqreturn_t apple_pcie_port_irq(int irq, void *data)
@@ -485,16 +506,15 @@ static int apple_pcie_port_register_irqs(struct apple_pcie_port *port)
[0] = port_irqs[i].hwirq,
},
};
- unsigned int irq;
- int ret;
+ int irq, ret;
irq = irq_domain_alloc_irqs(port->domain, 1, NUMA_NO_NODE,
&fwspec);
- if (WARN_ON(!irq))
+ if (WARN_ON(irq <= 0))
continue;
- ret = request_irq(irq, apple_pcie_port_irq, 0,
- port_irqs[i].name, port);
+ ret = devm_request_irq(port->pcie->dev, irq, apple_pcie_port_irq, 0,
+ port_irqs[i].name, port);
WARN_ON(ret);
}
@@ -582,6 +602,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
port->idx = idx >> 11;
port->pcie = pcie;
port->np = np;
+ INIT_LIST_HEAD(&port->entry);
raw_spin_lock_init(&port->lock);
@@ -652,9 +673,6 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
list_add_tail(&port->entry, &pcie->ports);
init_completion(&pcie->event);
- /* In the success path, we keep a reference to np around */
- of_node_get(np);
-
ret = apple_pcie_port_register_irqs(port);
WARN_ON(ret);
@@ -678,6 +696,11 @@ static const struct msi_parent_ops apple_msi_parent_ops = {
.init_dev_msi_info = msi_lib_init_dev_msi_info,
};
+static void apple_msi_remove(void *data)
+{
+ irq_domain_remove(data);
+}
+
static int apple_msi_init(struct apple_pcie *pcie)
{
struct fwnode_handle *fwnode = dev_fwnode(pcie->dev);
@@ -688,6 +711,7 @@ static int apple_msi_init(struct apple_pcie *pcie)
.host_data = pcie,
};
struct of_phandle_args args = {};
+ struct irq_domain *domain;
int ret;
ret = of_parse_phandle_with_args(to_of_node(fwnode), "msi-ranges",
@@ -713,11 +737,12 @@ static int apple_msi_init(struct apple_pcie *pcie)
return -ENXIO;
}
- if (!msi_create_parent_irq_domain(&info, &apple_msi_parent_ops)) {
+ domain = msi_create_parent_irq_domain(&info, &apple_msi_parent_ops);
+ if (!domain) {
dev_err(pcie->dev, "failed to create IRQ domain\n");
return -ENOMEM;
}
- return 0;
+ return devm_add_action_or_reset(pcie->dev, apple_msi_remove, domain);
}
static struct apple_pcie *apple_pcie_lookup(struct device *dev)
@@ -886,6 +911,7 @@ MODULE_DEVICE_TABLE(of, apple_pcie_of_match);
static struct platform_driver apple_pcie_driver = {
.probe = apple_pcie_probe,
+ .remove = pci_host_common_remove,
.driver = {
.name = "pcie-apple",
.of_match_table = apple_pcie_of_match,
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: apple: Release port IRQs and domains on driver detach
2026-11-26 8:28 [PATCH] PCI: apple: Release port IRQs and domains on driver detach Guangshuo Li
@ 2026-11-26 8:42 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 8:42 UTC (permalink / raw)
To: Guangshuo Li; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] PCI: apple: missing IS_ERR() check for port->phy in
apple_pcie_setup_port() [1]
--
commit 102d3679b8d5966284cf3435e5c387deb0e77c02
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
PCI: apple: Release port IRQs and domains on driver detach
This commit registers device-managed cleanup actions for the per-port
interrupt domains, link IRQs, and the MSI parent domain, and wires up
pci_host_common_remove() on driver detach.
> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
> index dfd0e345bc567..79dac3fb9a05c 100644
> --- a/drivers/pci/controller/pcie-apple.c
> +++ b/drivers/pci/controller/pcie-apple.c
[ ... ]
> @@ -582,6 +602,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
> port->idx = idx >> 11;
> port->pcie = pcie;
> port->np = np;
> + INIT_LIST_HEAD(&port->entry);
>
> raw_spin_lock_init(&port->lock);
[Severity: High]
This problem wasn't introduced by this patch, but can
apple_pcie_setup_port() [1] dereference an error pointer in
port->phy when devm_ioremap_resource() fails?
Later in apple_pcie_setup_port(), port->phy is mapped without an IS_ERR()
check and then passed to apple_pcie_setup_refclk() for MMIO access:
drivers/pci/controller/pcie-apple.c:apple_pcie_setup_port() {
...
snprintf(name, sizeof(name), "phy%d", port->idx);
res = platform_get_resource_byname(platform, IORESOURCE_MEM, name);
if (res)
port->phy = devm_ioremap_resource(&platform->dev, res);
else
port->phy = pcie->base + CORE_PHY_DEFAULT_BASE(port->idx);
rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
/* Assert PERST# before setting up the clock */
gpiod_set_value_cansleep(reset, 1);
ret = apple_pcie_setup_refclk(pcie, port);
...
}
If mapping the named PHY resource fails, rmw_set() in
apple_pcie_setup_refclk() will dereference the ERR_PTR() value in
port->phy and crash during probe.
[1] https://sashiko.dev/#/bug/linux-7340dc46-b98f-4a1f-909a-9ae73ed0ddc9
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-a35bb25eb5-u39-0@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 8:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 8:28 [PATCH] PCI: apple: Release port IRQs and domains on driver detach Guangshuo Li
2026-11-26 8:42 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox