Commit e3beca48 authored by Thomas Gleixner's avatar Thomas Gleixner

irqdomain/treewide: Keep firmware node unconditionally allocated

Quite some non OF/ACPI users of irqdomains allocate firmware nodes of type
IRQCHIP_FWNODE_NAMED or IRQCHIP_FWNODE_NAMED_ID and free them right after
creating the irqdomain. The only purpose of these FW nodes is to convey
name information. When this was introduced the core code did not store the
pointer to the node in the irqdomain. A recent change stored the firmware
node pointer in irqdomain for other reasons and missed to notice that the
usage sites which do the alloc_fwnode/create_domain/free_fwnode sequence
are broken by this. Storing a dangling pointer is dangerous itself, but in
case that the domain is destroyed later on this leads to a double free.

Remove the freeing of the firmware node after creating the irqdomain from
all affected call sites to cure this.

Fixes: 711419e5 ("irqdomain: Add the missing assignment of domain->fwnode for named fwnode")
Reported-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarMarc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/873661qakd.fsf@nanos.tec.linutronix.de
parent dcb7fd82
...@@ -627,9 +627,10 @@ static int bridge_probe(struct platform_device *pdev) ...@@ -627,9 +627,10 @@ static int bridge_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
domain = irq_domain_create_hierarchy(parent, 0, 8, fn, domain = irq_domain_create_hierarchy(parent, 0, 8, fn,
&bridge_domain_ops, NULL); &bridge_domain_ops, NULL);
if (!domain) {
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
if (!domain)
return -ENOMEM; return -ENOMEM;
}
pci_set_flags(PCI_PROBE_ONLY); pci_set_flags(PCI_PROBE_ONLY);
......
...@@ -2316,12 +2316,12 @@ static int mp_irqdomain_create(int ioapic) ...@@ -2316,12 +2316,12 @@ static int mp_irqdomain_create(int ioapic)
ip->irqdomain = irq_domain_create_linear(fn, hwirqs, cfg->ops, ip->irqdomain = irq_domain_create_linear(fn, hwirqs, cfg->ops,
(void *)(long)ioapic); (void *)(long)ioapic);
if (!ip->irqdomain) {
/* Release fw handle if it was allocated above */ /* Release fw handle if it was allocated above */
if (!cfg->dev) if (!cfg->dev)
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
if (!ip->irqdomain)
return -ENOMEM; return -ENOMEM;
}
ip->irqdomain->parent = parent; ip->irqdomain->parent = parent;
......
...@@ -263,12 +263,13 @@ void __init arch_init_msi_domain(struct irq_domain *parent) ...@@ -263,12 +263,13 @@ void __init arch_init_msi_domain(struct irq_domain *parent)
msi_default_domain = msi_default_domain =
pci_msi_create_irq_domain(fn, &pci_msi_domain_info, pci_msi_create_irq_domain(fn, &pci_msi_domain_info,
parent); parent);
irq_domain_free_fwnode(fn);
} }
if (!msi_default_domain) if (!msi_default_domain) {
irq_domain_free_fwnode(fn);
pr_warn("failed to initialize irqdomain for MSI/MSI-x.\n"); pr_warn("failed to initialize irqdomain for MSI/MSI-x.\n");
else } else {
msi_default_domain->flags |= IRQ_DOMAIN_MSI_NOMASK_QUIRK; msi_default_domain->flags |= IRQ_DOMAIN_MSI_NOMASK_QUIRK;
}
} }
#ifdef CONFIG_IRQ_REMAP #ifdef CONFIG_IRQ_REMAP
...@@ -301,6 +302,7 @@ struct irq_domain *arch_create_remap_msi_irq_domain(struct irq_domain *parent, ...@@ -301,6 +302,7 @@ struct irq_domain *arch_create_remap_msi_irq_domain(struct irq_domain *parent,
if (!fn) if (!fn)
return NULL; return NULL;
d = pci_msi_create_irq_domain(fn, &pci_msi_ir_domain_info, parent); d = pci_msi_create_irq_domain(fn, &pci_msi_ir_domain_info, parent);
if (!d)
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
return d; return d;
} }
...@@ -364,6 +366,7 @@ static struct irq_domain *dmar_get_irq_domain(void) ...@@ -364,6 +366,7 @@ static struct irq_domain *dmar_get_irq_domain(void)
if (fn) { if (fn) {
dmar_domain = msi_create_irq_domain(fn, &dmar_msi_domain_info, dmar_domain = msi_create_irq_domain(fn, &dmar_msi_domain_info,
x86_vector_domain); x86_vector_domain);
if (!dmar_domain)
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
} }
out: out:
...@@ -489,7 +492,10 @@ struct irq_domain *hpet_create_irq_domain(int hpet_id) ...@@ -489,7 +492,10 @@ struct irq_domain *hpet_create_irq_domain(int hpet_id)
} }
d = msi_create_irq_domain(fn, domain_info, parent); d = msi_create_irq_domain(fn, domain_info, parent);
if (!d) {
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
kfree(domain_info);
}
return d; return d;
} }
......
...@@ -709,7 +709,6 @@ int __init arch_early_irq_init(void) ...@@ -709,7 +709,6 @@ int __init arch_early_irq_init(void)
x86_vector_domain = irq_domain_create_tree(fn, &x86_vector_domain_ops, x86_vector_domain = irq_domain_create_tree(fn, &x86_vector_domain_ops,
NULL); NULL);
BUG_ON(x86_vector_domain == NULL); BUG_ON(x86_vector_domain == NULL);
irq_domain_free_fwnode(fn);
irq_set_default_host(x86_vector_domain); irq_set_default_host(x86_vector_domain);
arch_init_msi_domain(x86_vector_domain); arch_init_msi_domain(x86_vector_domain);
......
...@@ -167,9 +167,10 @@ static struct irq_domain *uv_get_irq_domain(void) ...@@ -167,9 +167,10 @@ static struct irq_domain *uv_get_irq_domain(void)
goto out; goto out;
uv_domain = irq_domain_create_tree(fn, &uv_domain_ops, NULL); uv_domain = irq_domain_create_tree(fn, &uv_domain_ops, NULL);
irq_domain_free_fwnode(fn);
if (uv_domain) if (uv_domain)
uv_domain->parent = x86_vector_domain; uv_domain->parent = x86_vector_domain;
else
irq_domain_free_fwnode(fn);
out: out:
mutex_unlock(&uv_lock); mutex_unlock(&uv_lock);
......
...@@ -3985,9 +3985,10 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu) ...@@ -3985,9 +3985,10 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu)
if (!fn) if (!fn)
return -ENOMEM; return -ENOMEM;
iommu->ir_domain = irq_domain_create_tree(fn, &amd_ir_domain_ops, iommu); iommu->ir_domain = irq_domain_create_tree(fn, &amd_ir_domain_ops, iommu);
if (!iommu->ir_domain) {
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
if (!iommu->ir_domain)
return -ENOMEM; return -ENOMEM;
}
iommu->ir_domain->parent = arch_get_ir_parent_domain(); iommu->ir_domain->parent = arch_get_ir_parent_domain();
iommu->msi_domain = arch_create_remap_msi_irq_domain(iommu->ir_domain, iommu->msi_domain = arch_create_remap_msi_irq_domain(iommu->ir_domain,
......
...@@ -155,7 +155,10 @@ static int __init hyperv_prepare_irq_remapping(void) ...@@ -155,7 +155,10 @@ static int __init hyperv_prepare_irq_remapping(void)
0, IOAPIC_REMAPPING_ENTRY, fn, 0, IOAPIC_REMAPPING_ENTRY, fn,
&hyperv_ir_domain_ops, NULL); &hyperv_ir_domain_ops, NULL);
if (!ioapic_ir_domain) {
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
return -ENOMEM;
}
/* /*
* Hyper-V doesn't provide irq remapping function for * Hyper-V doesn't provide irq remapping function for
......
...@@ -563,8 +563,8 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) ...@@ -563,8 +563,8 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
0, INTR_REMAP_TABLE_ENTRIES, 0, INTR_REMAP_TABLE_ENTRIES,
fn, &intel_ir_domain_ops, fn, &intel_ir_domain_ops,
iommu); iommu);
irq_domain_free_fwnode(fn);
if (!iommu->ir_domain) { if (!iommu->ir_domain) {
irq_domain_free_fwnode(fn);
pr_err("IR%d: failed to allocate irqdomain\n", iommu->seq_id); pr_err("IR%d: failed to allocate irqdomain\n", iommu->seq_id);
goto out_free_bitmap; goto out_free_bitmap;
} }
......
...@@ -142,10 +142,11 @@ static int ioc3_irq_domain_setup(struct ioc3_priv_data *ipd, int irq) ...@@ -142,10 +142,11 @@ static int ioc3_irq_domain_setup(struct ioc3_priv_data *ipd, int irq)
goto err; goto err;
domain = irq_domain_create_linear(fn, 24, &ioc3_irq_domain_ops, ipd); domain = irq_domain_create_linear(fn, 24, &ioc3_irq_domain_ops, ipd);
if (!domain) if (!domain) {
irq_domain_free_fwnode(fn);
goto err; goto err;
}
irq_domain_free_fwnode(fn);
ipd->domain = domain; ipd->domain = domain;
irq_set_chained_handler_and_data(irq, ioc3_irq_handler, domain); irq_set_chained_handler_and_data(irq, ioc3_irq_handler, domain);
......
...@@ -546,9 +546,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) ...@@ -546,9 +546,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)
vmd->irq_domain = pci_msi_create_irq_domain(fn, &vmd_msi_domain_info, vmd->irq_domain = pci_msi_create_irq_domain(fn, &vmd_msi_domain_info,
x86_vector_domain); x86_vector_domain);
if (!vmd->irq_domain) {
irq_domain_free_fwnode(fn); irq_domain_free_fwnode(fn);
if (!vmd->irq_domain)
return -ENODEV; return -ENODEV;
}
pci_add_resource(&resources, &vmd->resources[0]); pci_add_resource(&resources, &vmd->resources[0]);
pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]); pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment