iommu: Don't overwrite domain pointer when there is no default_domain
authorJoerg Roedel <jroedel@suse.de>
Mon, 4 Apr 2016 13:47:48 +0000 (15:47 +0200)
committerJoerg Roedel <jroedel@suse.de>
Thu, 7 Apr 2016 12:33:03 +0000 (14:33 +0200)
IOMMU drivers that do not support default domains, but make
use of the the group->domain pointer can get that pointer
overwritten with NULL on device add/remove.

Make sure this can't happen by only overwriting the domain
pointer when it is NULL.

Cc: stable@vger.kernel.org # v4.4+
Fixes: 1228236de5f9 ('iommu: Move default domain allocation to iommu_group_get_for_dev()')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c

index bfd4f7c3b1d8a9da9ce6cd2bce3decd8e27e0fca..b9df1411c8942c18b266b11e1cf572ecf9bcad15 100644 (file)
@@ -848,7 +848,8 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
        if (!group->default_domain) {
                group->default_domain = __iommu_domain_alloc(dev->bus,
                                                             IOMMU_DOMAIN_DMA);
-               group->domain = group->default_domain;
+               if (!group->domain)
+                       group->domain = group->default_domain;
        }
 
        ret = iommu_group_add_device(group, dev);