From patchwork Wed Oct 10 14:46:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1574541 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 09746DFB34 for ; Wed, 10 Oct 2012 15:19:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D9D2FA0A66 for ; Wed, 10 Oct 2012 08:19:43 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A8A99ED70 for ; Wed, 10 Oct 2012 08:02:02 -0700 (PDT) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO00GQCN36P590@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 11 Oct 2012 00:02:02 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-bc-50758deac66e Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id B1.DC.03860.AED85705; Thu, 11 Oct 2012 00:02:02 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MBO002YDME0EC70@mmp1.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 11 Oct 2012 00:02:02 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCHv10 22/26] v4l: vb2-dma-contig: fail if user ptr buffer is not correctly aligned Date: Wed, 10 Oct 2012 16:46:41 +0200 Message-id: <1349880405-26049-23-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> References: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCJMWRmVeSWpSXmKPExsVy+t9jAd1XvaUBBiuOiVpc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujL/9m9gKPnNV3Ds/l7mBcQpnFyMnh4SAicSCaw9ZIGwxiQv3 1rN1MXJxCAksYpQ4dGYqO4Szjkli/vwnzCBVbEAdx5Z8ZgSxRQQcJE7fncUMUsQssIZZ4sXK G2wgCWGBRIlvt36zgtgsAqoSZ589BVvBK+ApsW1aNzvEOnmJp/f7wOo5geIX5k0HWyAk4CHx f/1mpgmMvAsYGVYxiqYWJBcUJ6XnGukVJ+YWl+al6yXn525iBPv9mfQOxlUNFocYBTgYlXh4 KzJKAoRYE8uKK3MPMUpwMCuJ8Jr6lAYI8aYkVlalFuXHF5XmpBYfYpTmYFES5232SAkQEkhP LEnNTk0tSC2CyTJxcEo1ME7zmCD8zKrz4Bq7er4H289vVjf3+7fH0nkyY/mmqmLdI9vdF8ma zDa3OxC5qb2hx125S2bGLobK2cf+HFsqeu5pnY26TWHMXymJmw/P64k9130d/tVubu7iTp5N Fspf13b0bDj5ac/Of+Xm5rsLT2S6vI3vsAt8UO6t3/Ju8uVLa8OdvVtSDZRYijMSDbWYi4oT Ab1tUNT3AQAA Cc: t.stanislaws@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, mchehab@redhat.com, daniel.vetter@ffwll.ch, subashrp@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, zhangfei.gao@gmail.com, airlied@redhat.com, remi@remlab.net, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: Marek Szyprowski 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 Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 2d661fd..571a919 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -493,6 +493,18 @@ 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_debug("user data must be aligned to %lu bytes\n", dma_align); + return ERR_PTR(-EINVAL); + } + + if (!size) { + pr_debug("size is zero\n"); + return ERR_PTR(-EINVAL); + } buf = kzalloc(sizeof *buf, GFP_KERNEL); if (!buf)