Skip to content

Commit a17ae14

Browse files
Souptick Joardertorvalds
authored andcommitted
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.com Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com> Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Marek 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b0d0084 commit a17ae14

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

‎drivers/media/common/videobuf2/videobuf2-core.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
22012201
goto unlock;
22022202
}
22032203

2204+
/*
2205+
* vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer,
2206+
* not as a in-buffer offset. We always want to mmap a whole buffer
2207+
* from its beginning.
2208+
*/
2209+
vma->vm_pgoff = 0;
2210+
22042211
ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
22052212

22062213
unlock:

‎drivers/media/common/videobuf2/videobuf2-dma-contig.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma)
186186
return -EINVAL;
187187
}
188188

189-
/*
190-
* dma_mmap_* uses vm_pgoff as in-buffer offset, but we want to
191-
* map whole buffer
192-
*/
193-
vma->vm_pgoff = 0;
194-
195189
ret = dma_mmap_attrs(buf->dev, vma, buf->cookie,
196190
buf->dma_addr, buf->size, buf->attrs);
197191

‎drivers/media/common/videobuf2/videobuf2-dma-sg.c‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,28 +328,18 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv)
328328
static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma)
329329
{
330330
struct vb2_dma_sg_buf *buf = buf_priv;
331-
unsigned long uaddr = vma->vm_start;
332-
unsigned long usize = vma->vm_end - vma->vm_start;
333-
int i = 0;
331+
int err;
334332

335333
if (!buf) {
336334
printk(KERN_ERR "No memory to map\n");
337335
return -EINVAL;
338336
}
339337

340-
do {
341-
int ret;
342-
343-
ret = vm_insert_page(vma, uaddr, buf->pages[i++]);
344-
if (ret) {
345-
printk(KERN_ERR "Remapping memory, error: %d\n", ret);
346-
return ret;
347-
}
348-
349-
uaddr += PAGE_SIZE;
350-
usize -= PAGE_SIZE;
351-
} while (usize > 0);
352-
338+
err = vm_map_pages(vma, buf->pages, buf->num_pages);
339+
if (err) {
340+
printk(KERN_ERR "Remapping memory, error: %d\n", err);
341+
return err;
342+
}
353343

354344
/*
355345
* Use common vm_area operations to track buffer refcount.

0 commit comments

Comments
 (0)