2022-07-11 12:33:00

by Pali Rohár

[permalink] [raw]
Subject: [PATCH 1/3] PCI: aardvark: Dispose INTx irqs prior to removing INTx domain

Documentation for irq_domain_remove() says that all mapping within the
domain must be disposed prior to domain remove.

Currently INTx irqs are not disposed in pci-aardvark.c device unbind callback
which cause that kernel crashes after unloading driver and trying to read
/sys/kernel/debug/irq/irqs/<num> or /proc/interrupts.

Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module")
Signed-off-by: Pali Rohár <[email protected]>
---
drivers/pci/controller/pci-aardvark.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index ffec82c8a523..6cb65e64859d 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -1433,6 +1433,14 @@ static int advk_pcie_init_irq_domain(struct advk_pcie *pcie)

static void advk_pcie_remove_irq_domain(struct advk_pcie *pcie)
{
+ int virq, i;
+
+ for (i = 0; i < PCI_NUM_INTX; i++) {
+ virq = irq_find_mapping(pcie->irq_domain, i);
+ if (virq > 0)
+ irq_dispose_mapping(virq);
+ }
+
irq_domain_remove(pcie->irq_domain);
}

--
2.20.1


2022-07-11 12:58:07

by Pali Rohár

[permalink] [raw]
Subject: [PATCH 3/3] PCI: aardvark: Do static allocation of irq_chip

There is no need to allocate struct irq_chip in pci-aardvark.c dynamically
at runtime. Use static allocation like for any other irq_chip usage.

Signed-off-by: Pali Rohár <[email protected]>
---
drivers/pci/controller/pci-aardvark.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index 8bea5801d50a..74511f015168 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -274,7 +274,6 @@ struct advk_pcie {
u8 wins_count;
struct irq_domain *rp_irq_domain;
struct irq_domain *irq_domain;
- struct irq_chip irq_chip;
raw_spinlock_t irq_lock;
struct irq_domain *msi_domain;
struct irq_domain *msi_inner_domain;
@@ -1328,13 +1327,19 @@ static void advk_pcie_irq_unmask(struct irq_data *d)
raw_spin_unlock_irqrestore(&pcie->irq_lock, flags);
}

+static struct irq_chip advk_irq_chip = {
+ .name = "advk-INTx",
+ .irq_mask = advk_pcie_irq_mask,
+ .irq_unmask = advk_pcie_irq_unmask,
+};
+
static int advk_pcie_irq_map(struct irq_domain *h,
unsigned int virq, irq_hw_number_t hwirq)
{
struct advk_pcie *pcie = h->host_data;

irq_set_status_flags(virq, IRQ_LEVEL);
- irq_set_chip_and_handler(virq, &pcie->irq_chip,
+ irq_set_chip_and_handler(virq, &advk_irq_chip,
handle_level_irq);
irq_set_chip_data(virq, pcie);

@@ -1394,7 +1399,6 @@ static int advk_pcie_init_irq_domain(struct advk_pcie *pcie)
struct device *dev = &pcie->pdev->dev;
struct device_node *node = dev->of_node;
struct device_node *pcie_intc_node;
- struct irq_chip *irq_chip;
int ret = 0;

raw_spin_lock_init(&pcie->irq_lock);
@@ -1405,28 +1409,14 @@ static int advk_pcie_init_irq_domain(struct advk_pcie *pcie)
return -ENODEV;
}

- irq_chip = &pcie->irq_chip;
-
- irq_chip->name = devm_kasprintf(dev, GFP_KERNEL, "%s-irq",
- dev_name(dev));
- if (!irq_chip->name) {
- ret = -ENOMEM;
- goto out_put_node;
- }
-
- irq_chip->irq_mask = advk_pcie_irq_mask;
- irq_chip->irq_unmask = advk_pcie_irq_unmask;
-
pcie->irq_domain =
irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
&advk_pcie_irq_domain_ops, pcie);
if (!pcie->irq_domain) {
dev_err(dev, "Failed to get a INTx IRQ domain\n");
ret = -ENOMEM;
- goto out_put_node;
}

-out_put_node:
of_node_put(pcie_intc_node);
return ret;
}
--
2.20.1