From 061c8d8d872be456ab53afbd3abd3ba09cad32db Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 19 Apr 2013 07:18:01 -0300 Subject: [PATCH] --- yaml --- r: 367115 b: refs/heads/master c: 7f8414594e4755234fd0ca415630cfe2dfab42ce h: refs/heads/master i: 367113: 5550f0789d83d5045efa01c2fe3cba5693082e4c 367111: c548ab23b435af02ce1c748c82297cffc4bef09e v: v3 --- [refs] | 2 +- .../drivers/media/v4l2-core/videobuf2-core.c | 21 +++++++++++++++---- .../media/v4l2-core/videobuf2-dma-contig.c | 3 --- .../media/v4l2-core/videobuf2-dma-sg.c | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/[refs] b/[refs] index 2e8c313a2e47..550b0271fbd4 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b3404a8ef567de43b74018bbdbd989b53426d422 +refs/heads/master: 7f8414594e4755234fd0ca415630cfe2dfab42ce diff --git a/trunk/drivers/media/v4l2-core/videobuf2-core.c b/trunk/drivers/media/v4l2-core/videobuf2-core.c index 58c17444d22f..7d833eefaf4e 100644 --- a/trunk/drivers/media/v4l2-core/videobuf2-core.c +++ b/trunk/drivers/media/v4l2-core/videobuf2-core.c @@ -54,10 +54,15 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) void *mem_priv; int plane; - /* Allocate memory for all planes in this buffer */ + /* + * Allocate memory for all planes in this buffer + * NOTE: mmapped areas should be page aligned + */ for (plane = 0; plane < vb->num_planes; ++plane) { + unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]); + mem_priv = call_memop(q, alloc, q->alloc_ctx[plane], - q->plane_sizes[plane], q->gfp_flags); + size, q->gfp_flags); if (IS_ERR_OR_NULL(mem_priv)) goto free; @@ -1852,6 +1857,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) struct vb2_buffer *vb; unsigned int buffer, plane; int ret; + unsigned long length; if (q->memory != V4L2_MEMORY_MMAP) { dprintk(1, "Queue is not currently set up for mmap\n"); @@ -1886,8 +1892,15 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) vb = q->bufs[buffer]; - if (vb->v4l2_planes[plane].length < (vma->vm_end - vma->vm_start)) { - dprintk(1, "Invalid length\n"); + /* + * MMAP requires page_aligned buffers. + * The buffer length was page_aligned at __vb2_buf_mem_alloc(), + * so, we need to do the same here. + */ + length = PAGE_ALIGN(vb->v4l2_planes[plane].length); + if (length < (vma->vm_end - vma->vm_start)) { + dprintk(1, + "MMAP invalid, as it would overflow buffer length\n"); return -EINVAL; } diff --git a/trunk/drivers/media/v4l2-core/videobuf2-dma-contig.c b/trunk/drivers/media/v4l2-core/videobuf2-dma-contig.c index ae35d255a430..fd56f2563201 100644 --- a/trunk/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/trunk/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -162,9 +162,6 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags) if (!buf) return ERR_PTR(-ENOMEM); - /* align image size to PAGE_SIZE */ - size = PAGE_ALIGN(size); - buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, GFP_KERNEL | gfp_flags); if (!buf->vaddr) { diff --git a/trunk/drivers/media/v4l2-core/videobuf2-dma-sg.c b/trunk/drivers/media/v4l2-core/videobuf2-dma-sg.c index 59522b2ebae1..16ae3dcc7e29 100644 --- a/trunk/drivers/media/v4l2-core/videobuf2-dma-sg.c +++ b/trunk/drivers/media/v4l2-core/videobuf2-dma-sg.c @@ -55,7 +55,8 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_fla buf->write = 0; buf->offset = 0; buf->sg_desc.size = size; - buf->sg_desc.num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; + /* size is already page aligned */ + buf->sg_desc.num_pages = size >> PAGE_SHIFT; buf->sg_desc.sglist = vzalloc(buf->sg_desc.num_pages * sizeof(*buf->sg_desc.sglist));