iommu/tegra-smmu: Fix iova_to_phys() method
authorRussell King <rmk+kernel@arm.linux.org.uk>
Mon, 27 Jul 2015 12:29:00 +0000 (13:29 +0100)
committerThierry Reding <treding@nvidia.com>
Thu, 13 Aug 2015 14:06:36 +0000 (16:06 +0200)
iova_to_phys() has several problems:
(a) iova_to_phys() is supposed to return 0 if there is no entry present
    for the iova.
(b) if as_get_pte() fails, we oops the kernel by dereferencing a NULL
    pointer.  Really, we should not even be trying to allocate a page
    table at all, but should only be returning the presence of the 2nd
    level page table.  This will be fixed in a subsequent patch.

Treat both of these conditions as "no mapping" conditions.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/iommu/tegra-smmu.c

index c1f2e52..0833549 100644 (file)
@@ -592,6 +592,9 @@ static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,
        u32 *pte;
 
        pte = as_get_pte(as, iova, &page);
+       if (!pte || !*pte)
+               return 0;
+
        pfn = *pte & as->smmu->pfn_mask;
 
        return PFN_PHYS(pfn);