[PATCH] iommu/amd_iommu_init: Handle return of iommu_device_register/iommu_device_sysfs_add

From: Arvind Yadav
Date: Thu Jun 22 2017 - 04:21:06 EST


iommu_device_register and iommu_device_sysfs_add can fail here and
we must check its return value.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@xxxxxxxxx>
---
drivers/iommu/amd_iommu_init.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 41a66ae..c420a68 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1642,10 +1642,15 @@ static int iommu_init_pci(struct amd_iommu *iommu)
amd_iommu_erratum_746_workaround(iommu);
amd_iommu_ats_write_check_workaround(iommu);

- iommu_device_sysfs_add(&iommu->iommu, &iommu->dev->dev,
+ ret = iommu_device_sysfs_add(&iommu->iommu, &iommu->dev->dev,
amd_iommu_groups, "ivhd%d", iommu->index);
+ if (ret)
+ return ret;
+
iommu_device_set_ops(&iommu->iommu, &amd_iommu_ops);
- iommu_device_register(&iommu->iommu);
+ ret = iommu_device_register(&iommu->iommu);
+ if (ret)
+ return ret;

return pci_enable_device(iommu->dev);
}
--
1.9.1