ARM: dma-mapping: Set iommu_ops before attach
Hiroshi Doyu [Wed, 21 Aug 2013 04:59:44 +0000 (07:59 +0300)]
Make iommu_ops available before iommu_attach_devce()

Bug 1297607

Change-Id: I41f6f8c71e7056f67f8245bbcddd1cd6f3ecf5bf
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
Reviewed-on: http://git-master/r/264253
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>

arch/arm/mm/dma-mapping.c

index 4e93d6c..1d7d360 100644 (file)
@@ -2162,14 +2162,23 @@ int arm_iommu_attach_device(struct device *dev,
                            struct dma_iommu_mapping *mapping)
 {
        int err;
+       const struct dma_map_ops *org_ops;
+       struct dma_iommu_mapping *org_map;
+
+       org_ops = get_dma_ops(dev);
+       set_dma_ops(dev, &iommu_ops);
+
+       org_map = dev->archdata.mapping;
+       dev->archdata.mapping = mapping;
 
        err = iommu_attach_device(mapping->domain, dev);
-       if (err)
+       if (err) {
+               set_dma_ops(dev, org_ops);
+               dev->archdata.mapping = org_map;
                return err;
+       }
 
        kref_get(&mapping->kref);
-       dev->archdata.mapping = mapping;
-       set_dma_ops(dev, &iommu_ops);
 
        pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev));
        return 0;