drivers: dma-coherent: Fix DMA coherent size for less than page
authorGeorge G. Davis <george_davis@mentor.com>
Wed, 28 Sep 2016 07:51:56 +0000 (08:51 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2016 15:53:16 +0000 (17:53 +0200)
We fix a bug in dma_mmap_from_coherent() that appears when we map non page
aligned DMA memory. It cuts off the non aligned part (this is different to
dma_alloc_coherent() that always rounds up to full pages). So for mappings
of less than a page we get -ENXIO as dma_mmap_from_coherent() assumes we
want to map zero pages.

Signed-off-by: George G. Davis <george_davis@mentor.com>
Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
Signed-off-by: Mark Craske <Mark_Craske@mentor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/dma-coherent.c

index db122a06edc517c2e9e0a15d9364e5d921c3a00a..2789f7a95b936e601e9037819df5f70912678beb 100644 (file)
@@ -262,7 +262,7 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
                unsigned long off = vma->vm_pgoff;
                int start = (vaddr - mem->virt_base) >> PAGE_SHIFT;
                int user_count = vma_pages(vma);
-               int count = size >> PAGE_SHIFT;
+               int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
 
                *ret = -ENXIO;
                if (off < count && user_count <= count - off) {