]> 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)
committerMatthew Pedro <mapedro@nvidia.com>
Thu, 6 Mar 2014 23:42:03 +0000 (15:42 -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
(cherry picked from commit 25e4750235628bc03dca21c0cbf30fe267761a93)
Reviewed-on: http://git-master/r/375599
Reviewed-by: Bryan Wu <pengw@nvidia.com>
Tested-by: Bryan Wu <pengw@nvidia.com>
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>
drivers/iommu/tegra-smmu.c

index 0495d4411d048b59647ed72fbf23babd4b7253a3..c3114a71b27e553c48a8e293d1b9aa4cf18ee9a8 100644 (file)
@@ -1917,6 +1917,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)
@@ -1931,9 +1935,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));
@@ -1947,6 +1949,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);