Commit e85bb5d4 authored by Jiang Liu's avatar Jiang Liu Committed by Joerg Roedel

iommu/vt-d: Free resources if failed to create domain for PCIe endpoint

Enhance function get_domain_for_dev() to release allocated resources
if failed to create domain for PCIe endpoint, otherwise the allocated
resources will get lost.
Signed-off-by: default avatarJiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: default avatarJoerg Roedel <joro@8bytes.org>
parent 745f2586
...@@ -2015,7 +2015,7 @@ static int dmar_insert_dev_info(int segment, int bus, int devfn, ...@@ -2015,7 +2015,7 @@ static int dmar_insert_dev_info(int segment, int bus, int devfn,
/* domain is initialized */ /* domain is initialized */
static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw) static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw)
{ {
struct dmar_domain *domain; struct dmar_domain *domain, *free = NULL;
struct intel_iommu *iommu; struct intel_iommu *iommu;
struct dmar_drhd_unit *drhd; struct dmar_drhd_unit *drhd;
struct pci_dev *dev_tmp; struct pci_dev *dev_tmp;
...@@ -2062,17 +2062,16 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw) ...@@ -2062,17 +2062,16 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw)
free_domain_mem(domain); free_domain_mem(domain);
goto error; goto error;
} }
if (domain_init(domain, gaw)) { free = domain;
domain_exit(domain); if (domain_init(domain, gaw))
goto error; goto error;
}
/* register pcie-to-pci device */ /* register pcie-to-pci device */
if (dev_tmp) { if (dev_tmp) {
if (dmar_insert_dev_info(segment, bus, devfn, NULL, &domain)) { if (dmar_insert_dev_info(segment, bus, devfn, NULL, &domain))
domain_exit(domain);
goto error; goto error;
} else
free = NULL;
} }
found_domain: found_domain:
...@@ -2080,6 +2079,8 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw) ...@@ -2080,6 +2079,8 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw)
pdev, &domain) == 0) pdev, &domain) == 0)
return domain; return domain;
error: error:
if (free)
domain_exit(free);
/* recheck it here, maybe others set it */ /* recheck it here, maybe others set it */
return find_domain(pdev); return find_domain(pdev);
} }
......
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