[PATCHv9 22/25] v4l: vb2-dma-contig: fail if user ptr buffer is not correctly aligned
Tomasz Stanislawski
t.stanislaws at samsung.com
Tue Oct 2 07:27:33 PDT 2012
From: Marek Szyprowski <m.szyprowski at samsung.com>
The DMA transfer must be aligned to a specific value. If userptr is not aligned
to DMA requirements then unexpected corruptions of the memory may occur before
or after a buffer. To prevent such situations, all unligned userptr buffers
are rejected at VIDIOC_QBUF.
Signed-off-by: Marek Szyprowski <m.szyprowski at samsung.com>
---
drivers/media/video/videobuf2-dma-contig.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c
index b4d287a..55f8c80 100644
--- a/drivers/media/video/videobuf2-dma-contig.c
+++ b/drivers/media/video/videobuf2-dma-contig.c
@@ -494,6 +494,13 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr,
struct vm_area_struct *vma;
struct sg_table *sgt;
unsigned long contig_size;
+ unsigned long dma_align = dma_get_cache_alignment();
+
+ /* Only cache aligned DMA transfers are reliable */
+ if (!IS_ALIGNED(vaddr | size, dma_align)) {
+ pr_err("user data must be aligned to %lu bytes\n", dma_align);
+ return ERR_PTR(-EINVAL);
+ }
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
--
1.7.9.5
More information about the dri-devel
mailing list