From: Joerg Roedel <jroedel@suse.de>
Date: Thu, 7 Jan 2016 12:16:51 +0100
Subject: iommu/vt-d: Fix up error handling in alloc_iommu
Git-commit: bc8474549e94efddb5d5791af0a015d13115b67b
Patch-mainline: v4.5-rc1
References: fate#321026

Only check for error when iommu->iommu_dev has been assigned
and only assign drhd->iommu when the function can't fail
anymore.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/dmar.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -1066,19 +1066,19 @@ static int alloc_iommu(struct dmar_drhd_
 
 	raw_spin_lock_init(&iommu->register_lock);
 
-	drhd->iommu = iommu;
-
-	if (intel_iommu_enabled)
+	if (intel_iommu_enabled) {
 		iommu->iommu_dev = iommu_device_create(NULL, iommu,
 						       intel_iommu_groups,
 						       "%s", iommu->name);
 
-	if (IS_ERR(iommu->iommu_dev)) {
-		drhd->iommu = NULL;
-		err = PTR_ERR(iommu->iommu_dev);
-		goto err_unmap;
+		if (IS_ERR(iommu->iommu_dev)) {
+			err = PTR_ERR(iommu->iommu_dev);
+			goto err_unmap;
+		}
 	}
 
+	drhd->iommu = iommu;
+
 	return 0;
 
 err_unmap:
