Skip to content

Commit

Permalink
iommu/vt-d: Free resources if failed to create domain for PCIe endpoint
Browse files Browse the repository at this point in the history
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: Jiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: Joerg Roedel <joro@8bytes.org>
  • Loading branch information
Jiang Liu authored and Joerg Roedel committed Mar 4, 2014
1 parent 745f258 commit e85bb5d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions drivers/iommu/intel-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ static int dmar_insert_dev_info(int segment, int bus, int devfn,
/* domain is initialized */
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 dmar_drhd_unit *drhd;
struct pci_dev *dev_tmp;
Expand Down Expand Up @@ -2062,24 +2062,25 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw)
free_domain_mem(domain);
goto error;
}
if (domain_init(domain, gaw)) {
domain_exit(domain);
free = domain;
if (domain_init(domain, gaw))
goto error;
}

/* register pcie-to-pci device */
if (dev_tmp) {
if (dmar_insert_dev_info(segment, bus, devfn, NULL, &domain)) {
domain_exit(domain);
if (dmar_insert_dev_info(segment, bus, devfn, NULL, &domain))
goto error;
}
else
free = NULL;
}

found_domain:
if (dmar_insert_dev_info(segment, pdev->bus->number, pdev->devfn,
pdev, &domain) == 0)
return domain;
error:
if (free)
domain_exit(free);
/* recheck it here, maybe others set it */
return find_domain(pdev);
}
Expand Down

0 comments on commit e85bb5d

Please sign in to comment.