]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
iommu: tegra: correct device attach/detach
authorSri Krishna chowdary <schowdary@nvidia.com>
Thu, 30 Jan 2014 09:29:49 +0000 (14:59 +0530)
committerKrishna Reddy <vdumpa@nvidia.com>
Fri, 31 Jan 2014 18:32:02 +0000 (10:32 -0800)
attach/detach a device only if registered to use smmu

Bug 1446597

Change-Id: I99be7eb3ddeff8b9f8ec61dc06b09eeb66bbd1d6
Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com>
Reviewed-on: http://git-master/r/361928
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Tested-by: Krishna Reddy <vdumpa@nvidia.com>
drivers/iommu/tegra-smmu.c

index 0e103761ec552e7eead0250c2f010a43f2d7e69d..b75b455bcfba89f08f6702794a4650b8f7166b42 100644 (file)
@@ -1862,6 +1862,10 @@ static int tegra_smmu_device_notifier(struct notifier_block *nb,
        struct dma_iommu_mapping *map;
        struct device *dev = _dev;
 
+       map = tegra_smmu_get_map(dev, tegra_smmu_of_get_swgids(dev));
+       if (!map)
+               return NOTIFY_DONE;
+
        switch (event) {
        case BUS_NOTIFY_BIND_DRIVER:
                if (get_dma_ops(dev) != &arm_dma_ops)
@@ -1876,9 +1880,7 @@ static int tegra_smmu_device_notifier(struct notifier_block *nb,
                        break;
                }
 
-               map = tegra_smmu_get_map(dev, tegra_smmu_of_get_swgids(dev));
-               if (!map)
-                       break;
+               WARN_ON(to_dma_iommu_mapping(dev) == map);
 
                if (arm_iommu_attach_device(dev, map)) {
                        dev_err(dev, "Failed to attach %s\n", dev_name(dev));
@@ -1892,6 +1894,8 @@ static int tegra_smmu_device_notifier(struct notifier_block *nb,
                        break;
                /* FALLTHROUGH */
        case BUS_NOTIFY_UNBOUND_DRIVER:
+               WARN_ON(!to_dma_iommu_mapping(dev));
+
                dev_dbg(dev, "Detaching %s from map %p\n", dev_name(dev),
                        to_dma_iommu_mapping(dev));
                arm_iommu_detach_device(dev);