Commit f78947c4 authored by Jon Derrick's avatar Jon Derrick Committed by Joerg Roedel
Browse files

iommu/vt-d: Unlink device if failed to add to group



If the device fails to be added to the group, make sure to unlink the
reference before returning.

Signed-off-by: default avatarJon Derrick <jonathan.derrick@intel.com>
Fixes: 39ab9555 ("iommu: Add sysfs bindings for struct iommu_device")
Acked-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 7d4e6ccd
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -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);

@@ -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,
@@ -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)