Skip to content

Commit

Permalink
iommu/vt-d: Unlink device if failed to add to group
Browse files Browse the repository at this point in the history
If the device fails to be added to the group, make sure to unlink the
reference before returning.

Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
Fixes: 39ab955 ("iommu: Add sysfs bindings for struct iommu_device")
Acked-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Jon Derrick authored and Joerg Roedel committed Jan 7, 2020
1 parent 7d4e6cc commit f78947c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/iommu/intel-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5624,8 +5624,10 @@ static int intel_iommu_add_device(struct device *dev)

group = iommu_group_get_for_dev(dev);

if (IS_ERR(group))
return PTR_ERR(group);
if (IS_ERR(group)) {
ret = PTR_ERR(group);
goto unlink;
}

iommu_group_put(group);

Expand All @@ -5651,7 +5653,8 @@ static int intel_iommu_add_device(struct device *dev)
if (!get_private_domain_for_dev(dev)) {
dev_warn(dev,
"Failed to get a private domain.\n");
return -ENOMEM;
ret = -ENOMEM;
goto unlink;
}

dev_info(dev,
Expand All @@ -5666,6 +5669,10 @@ static int intel_iommu_add_device(struct device *dev)
}

return 0;

unlink:
iommu_device_unlink(&iommu->iommu, dev);
return ret;
}

static void intel_iommu_remove_device(struct device *dev)
Expand Down

0 comments on commit f78947c

Please sign in to comment.