Commit a17ae147 authored by Souptick Joarder's avatar Souptick Joarder Committed by Linus Torvalds

videobuf2/videobuf2-dma-sg.c: convert to use vm_map_pages()

Convert to use vm_map_pages() to map range of kernel memory to user vma.

vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer, not as a
in-buffer offset by design and it always want to mmap a whole buffer from
its beginning.

Link: http://lkml.kernel.org/r/a953fe6b3056de1cc6eab654effdd4a22f125375.1552921225.git.jrdr.linux@gmail.comSigned-off-by: default avatarSouptick Joarder <jrdr.linux@gmail.com>
Suggested-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Cc: Pawel Osciak <pawel@osciak.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b0d0084f
...@@ -2201,6 +2201,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) ...@@ -2201,6 +2201,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
goto unlock; goto unlock;
} }
/*
* vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer,
* not as a in-buffer offset. We always want to mmap a whole buffer
* from its beginning.
*/
vma->vm_pgoff = 0;
ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma); ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
unlock: unlock:
......
...@@ -186,12 +186,6 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) ...@@ -186,12 +186,6 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma)
return -EINVAL; return -EINVAL;
} }
/*
* dma_mmap_* uses vm_pgoff as in-buffer offset, but we want to
* map whole buffer
*/
vma->vm_pgoff = 0;
ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, ret = dma_mmap_attrs(buf->dev, vma, buf->cookie,
buf->dma_addr, buf->size, buf->attrs); buf->dma_addr, buf->size, buf->attrs);
......
...@@ -328,29 +328,19 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv) ...@@ -328,29 +328,19 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv)
static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma) static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma)
{ {
struct vb2_dma_sg_buf *buf = buf_priv; struct vb2_dma_sg_buf *buf = buf_priv;
unsigned long uaddr = vma->vm_start; int err;
unsigned long usize = vma->vm_end - vma->vm_start;
int i = 0;
if (!buf) { if (!buf) {
printk(KERN_ERR "No memory to map\n"); printk(KERN_ERR "No memory to map\n");
return -EINVAL; return -EINVAL;
} }
do { err = vm_map_pages(vma, buf->pages, buf->num_pages);
int ret; if (err) {
printk(KERN_ERR "Remapping memory, error: %d\n", err);
ret = vm_insert_page(vma, uaddr, buf->pages[i++]); return err;
if (ret) {
printk(KERN_ERR "Remapping memory, error: %d\n", ret);
return ret;
} }
uaddr += PAGE_SIZE;
usize -= PAGE_SIZE;
} while (usize > 0);
/* /*
* Use common vm_area operations to track buffer refcount. * Use common vm_area operations to track buffer refcount.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment