|
@@ -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;
|
|
|
}
|
|
|
|