]> git.itanic.dy.fi Git - linux-stable/commitdiff
iommu/dma: Fix for dereferencing before null checking
authorYunsheng Lin <linyunsheng@huawei.com>
Sat, 24 Aug 2019 01:47:12 +0000 (09:47 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 30 Aug 2019 14:23:19 +0000 (16:23 +0200)
The cookie is dereferenced before null checking in the function
iommu_dma_init_domain.

This patch moves the dereferencing after the null checking.

Fixes: fdbe574eb693 ("iommu/dma: Allow MSI-only cookies")
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/dma-iommu.c

index 80beb1f5994afd9372e723f9d9aadec96ad65ffc..8ce9db9c2cf6ee92eaf369e8eab1179aa174efb4 100644 (file)
@@ -303,13 +303,15 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
                u64 size, struct device *dev)
 {
        struct iommu_dma_cookie *cookie = domain->iova_cookie;
-       struct iova_domain *iovad = &cookie->iovad;
        unsigned long order, base_pfn;
+       struct iova_domain *iovad;
        int attr;
 
        if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE)
                return -EINVAL;
 
+       iovad = &cookie->iovad;
+
        /* Use the smallest supported page size for IOVA granularity */
        order = __ffs(domain->pgsize_bitmap);
        base_pfn = max_t(unsigned long, 1, base >> order);