From patchwork Thu Jul 23 13:56:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tuukka.O Toivonen" X-Patchwork-Id: 36970 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6NDuq0N025870 for ; Thu, 23 Jul 2009 13:56:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751532AbZGWN4w (ORCPT ); Thu, 23 Jul 2009 09:56:52 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751722AbZGWN4v (ORCPT ); Thu, 23 Jul 2009 09:56:51 -0400 Received: from smtp.nokia.com ([192.100.122.230]:33207 "EHLO mgw-mx03.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbZGWN4u (ORCPT ); Thu, 23 Jul 2009 09:56:50 -0400 Received: from vaebh106.NOE.Nokia.com (vaebh106.europe.nokia.com [10.160.244.32]) by mgw-mx03.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id n6NDuSaW010987 for ; Thu, 23 Jul 2009 16:56:43 +0300 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by vaebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 23 Jul 2009 16:56:31 +0300 Received: from mgw-sa01.ext.nokia.com ([147.243.1.47]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 23 Jul 2009 16:56:31 +0300 Received: from localhost.localdomain (ouped11921.nmp.nokia.com [172.23.119.21]) by mgw-sa01.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id n6NDuRng017142; Thu, 23 Jul 2009 16:56:29 +0300 From: tuukka.o.toivonen@nokia.com To: linux-media@vger.kernel.org Cc: sakari.ailus@maxwell.research.nokia.com, tuukka.o.toivonen@nokia.com Subject: [PATCH] v4l2: do not force buffer size to be multiple of PAGE_SIZE Date: Thu, 23 Jul 2009 16:56:25 +0300 Message-Id: <1248357387-14720-2-git-send-email-tuukka.o.toivonen@nokia.com> X-Mailer: git-send-email 1.5.4.3 In-Reply-To: <1248357387-14720-1-git-send-email-tuukka.o.toivonen@nokia.com> References: <1248357387-14720-1-git-send-email-tuukka.o.toivonen@nokia.com> X-OriginalArrivalTime: 23 Jul 2009 13:56:31.0795 (UTC) FILETIME=[6226A030:01CA0B9D] X-Nokia-AV: Clean Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Tuukka Toivonen When the image size (bytesperline*height) is not multiple of PAGE_SIZE, v4l2 rounded the required buffer size to be multiple of PAGE_SIZE. This prevented user space to store images directly into userptr buffers which were not multiple of PAGE_SIZE. This constraint is removed. The start address is still assumed to be required page-aligned, ie., when v4l2 allocates mmap buffers, the offset between different buffers is page-aligned. Signed-off-by: Tuukka Toivonen --- drivers/media/video/videobuf-core.c | 7 +++---- drivers/media/video/videobuf-dma-sg.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c index b7b0584..0b18ac2 100644 --- a/drivers/media/video/videobuf-core.c +++ b/drivers/media/video/videobuf-core.c @@ -358,7 +358,7 @@ int __videobuf_mmap_setup(struct videobuf_queue *q, q->bufs[i]->bsize = bsize; switch (memory) { case V4L2_MEMORY_MMAP: - q->bufs[i]->boff = bsize * i; + q->bufs[i]->boff = PAGE_ALIGN(bsize) * i; break; case V4L2_MEMORY_USERPTR: case V4L2_MEMORY_OVERLAY: @@ -428,9 +428,8 @@ int videobuf_reqbufs(struct videobuf_queue *q, count = VIDEO_MAX_FRAME; size = 0; q->ops->buf_setup(q, &count, &size); - size = PAGE_ALIGN(size); dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n", - count, size, (count*size)>>PAGE_SHIFT); + count, size, (count*PAGE_ALIGN(size))>>PAGE_SHIFT); retval = __videobuf_mmap_setup(q, count, size, req->memory); if (retval < 0) { @@ -1096,7 +1095,7 @@ int videobuf_cgmbuf(struct videobuf_queue *q, mbuf->size = 0; for (i = 0; i < mbuf->frames; i++) { mbuf->offsets[i] = q->bufs[i]->boff; - mbuf->size += q->bufs[i]->bsize; + mbuf->size += PAGE_ALIGN(q->bufs[i]->bsize); } return 0; diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c index 21d979f..2a8ade7 100644 --- a/drivers/media/video/videobuf-dma-sg.c +++ b/drivers/media/video/videobuf-dma-sg.c @@ -588,7 +588,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q, retval = -EBUSY; goto done; } - size += q->bufs[last]->bsize; + size += PAGE_ALIGN(q->bufs[last]->bsize); if (size == (vma->vm_end - vma->vm_start)) break; } @@ -610,7 +610,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q, continue; q->bufs[i]->map = map; q->bufs[i]->baddr = vma->vm_start + size; - size += q->bufs[i]->bsize; + size += PAGE_ALIGN(q->bufs[i]->bsize); } map->count = 1;