drm/i915/gvt: use pfn_valid for better checking
authorChuanxiao Dong <chuanxiao.dong@intel.com>
Wed, 1 Mar 2017 06:34:52 +0000 (14:34 +0800)
committerZhenyu Wang <zhenyuw@linux.intel.com>
Wed, 1 Mar 2017 07:59:36 +0000 (15:59 +0800)
Before get the page from pfn, use pfn_valid to check if pfn
is able to translate to page structure.

Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
drivers/gpu/drm/i915/gvt/kvmgt.c

index 182914c22ac5531a299fbc253f295c8291883ef6..241354890603210dc19ff8b83e4ead5caf3375cf 100644 (file)
@@ -96,10 +96,10 @@ static int gvt_dma_map_iova(struct intel_vgpu *vgpu, kvm_pfn_t pfn,
        struct device *dev = &vgpu->gvt->dev_priv->drm.pdev->dev;
        dma_addr_t daddr;
 
-       page = pfn_to_page(pfn);
-       if (is_error_page(page))
+       if (unlikely(!pfn_valid(pfn)))
                return -EFAULT;
 
+       page = pfn_to_page(pfn);
        daddr = dma_map_page(dev, page, 0, PAGE_SIZE,
                        PCI_DMA_BIDIRECTIONAL);
        if (dma_mapping_error(dev, daddr))