From: Jon Derrick jonathan.derrick@intel.com
mainline inclusion from mainline-v5.5-rc6 commit f78947c409204138a4bc0609f98e07ef9d01ac0a category: bugfix bugzilla: 96934 CVE: NA
-------------------------------------------------
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: 39ab9555c2411 ("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
Conflict: drivers/iommu/intel-iommu.c Signed-off-by: Nanyong Sun sunnanyong@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/iommu/intel-iommu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 249e81685fb54..754e667380cd7 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -5248,6 +5248,7 @@ static int intel_iommu_add_device(struct device *dev) struct intel_iommu *iommu; struct iommu_group *group; u8 bus, devfn; + int ret;
iommu = device_to_iommu(dev, &bus, &devfn); if (!iommu) @@ -5257,11 +5258,17 @@ 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); return 0; + +unlink: + iommu_device_unlink(&iommu->iommu, dev); + return ret; }
static void intel_iommu_remove_device(struct device *dev)