Merge tag 'staging-4.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[sfrench/cifs-2.6.git] / drivers / iommu / iommu.c
index 72e683df0731727bd46d17c8bb21a2d53554804f..d4f527e5667936454bfb49e01db931703b180e73 100644 (file)
@@ -901,36 +901,24 @@ EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
 struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
 {
        struct iommu_domain *domain;
-       int ret;
 
        if (bus == NULL || bus->iommu_ops == NULL)
                return NULL;
 
-       domain = kzalloc(sizeof(*domain), GFP_KERNEL);
+       domain = bus->iommu_ops->domain_alloc(IOMMU_DOMAIN_UNMANAGED);
        if (!domain)
                return NULL;
 
-       domain->ops = bus->iommu_ops;
-
-       ret = domain->ops->domain_init(domain);
-       if (ret)
-               goto out_free;
+       domain->ops  = bus->iommu_ops;
+       domain->type = IOMMU_DOMAIN_UNMANAGED;
 
        return domain;
-
-out_free:
-       kfree(domain);
-
-       return NULL;
 }
 EXPORT_SYMBOL_GPL(iommu_domain_alloc);
 
 void iommu_domain_free(struct iommu_domain *domain)
 {
-       if (likely(domain->ops->domain_destroy != NULL))
-               domain->ops->domain_destroy(domain);
-
-       kfree(domain);
+       domain->ops->domain_free(domain);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_free);
 
@@ -1049,6 +1037,9 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
                     domain->ops->pgsize_bitmap == 0UL))
                return -ENODEV;
 
+       if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
+               return -EINVAL;
+
        /* find out the minimum page size supported */
        min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap);
 
@@ -1100,6 +1091,9 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
                     domain->ops->pgsize_bitmap == 0UL))
                return -ENODEV;
 
+       if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
+               return -EINVAL;
+
        /* find out the minimum page size supported */
        min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap);