powerpc/iommu: Avoid derefence before pointer check
authorBreno Leitao <leitao@debian.org>
Tue, 21 Aug 2018 18:44:48 +0000 (15:44 -0300)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 19 Sep 2018 11:58:09 +0000 (21:58 +1000)
The tbl pointer is being derefenced by IOMMU_PAGE_SIZE prior the check
if it is not NULL.

Just moving the dereference code to after the check, where there will
be guarantee that 'tbl' will not be NULL.

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/iommu.c

index af7a20dc6e0934e0945c95e21c7b1eb07e11fdd1..80b6caaa9b92e66b8629fe197ba7124290332657 100644 (file)
@@ -785,9 +785,9 @@ dma_addr_t iommu_map_page(struct device *dev, struct iommu_table *tbl,
 
        vaddr = page_address(page) + offset;
        uaddr = (unsigned long)vaddr;
-       npages = iommu_num_pages(uaddr, size, IOMMU_PAGE_SIZE(tbl));
 
        if (tbl) {
+               npages = iommu_num_pages(uaddr, size, IOMMU_PAGE_SIZE(tbl));
                align = 0;
                if (tbl->it_page_shift < PAGE_SHIFT && size >= PAGE_SIZE &&
                    ((unsigned long)vaddr & ~PAGE_MASK) == 0)