From patchwork Tue Dec 8 21:36:57 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: m-karicheri2@ti.com X-Patchwork-Id: 2267 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Tue, 08 Dec 2009 21:38:45 +0000 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Tue, 08 Dec 2009 19:43:23 -0200 (BRST) Received: from vger.kernel.org ([209.132.176.167]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NI7ld-0008SW-Jg; Tue, 08 Dec 2009 21:38:45 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756334AbZLHVhA (ORCPT + 1 other); Tue, 8 Dec 2009 16:37:00 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S965711AbZLHVhA (ORCPT ); Tue, 8 Dec 2009 16:37:00 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:51933 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756297AbZLHVgy (ORCPT ); Tue, 8 Dec 2009 16:36:54 -0500 Received: from dlep34.itg.ti.com ([157.170.170.115]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id nB8LaxAV018485 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 8 Dec 2009 15:36:59 -0600 Received: from legion.dal.design.ti.com (localhost [127.0.0.1]) by dlep34.itg.ti.com (8.13.7/8.13.7) with ESMTP id nB8LaxnK002478; Tue, 8 Dec 2009 15:36:59 -0600 (CST) Received: from gt516km11.gt.design.ti.com (gt516km11.gt.design.ti.com [158.218.100.179]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id nB8LawZ12728; Tue, 8 Dec 2009 15:36:58 -0600 (CST) Received: from gt516km11.gt.design.ti.com (localhost.localdomain [127.0.0.1]) by gt516km11.gt.design.ti.com (8.13.1/8.13.1) with ESMTP id nB8Lawic022897; Tue, 8 Dec 2009 16:36:58 -0500 Received: (from a0868495@localhost) by gt516km11.gt.design.ti.com (8.13.1/8.13.1/Submit) id nB8LaviL022894; Tue, 8 Dec 2009 16:36:57 -0500 From: m-karicheri2@ti.com To: linux-media@vger.kernel.org, magnus.damm@gmail.com Cc: Muralidharan Karicheri Subject: [PATCH - v1] V4L-Fix videobuf_dma_contig_user_get() for non-aligned offsets Date: Tue, 8 Dec 2009 16:36:57 -0500 Message-Id: <1260308217-22871-1-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.6.0.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Muralidharan Karicheri If a USERPTR address that is not aligned to page boundary is passed to the videobuf_dma_contig_user_get() function, it saves a page aligned address to the dma_handle. This is not correct. This issue is observed when using USERPTR IO machism for buffer exchange. Updates from last version:- Adding offset for size calculation as per comment from Magnus Damm. This ensures the last page is also included for checking if memory is contiguous. Signed-off-by: Muralidharan Karicheri Acked-by: Magnus Damm --- drivers/media/video/videobuf-dma-contig.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c index d25f284..22c0109 100644 --- a/drivers/media/video/videobuf-dma-contig.c +++ b/drivers/media/video/videobuf-dma-contig.c @@ -141,9 +141,11 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, struct vm_area_struct *vma; unsigned long prev_pfn, this_pfn; unsigned long pages_done, user_address; + unsigned int offset; int ret; - mem->size = PAGE_ALIGN(vb->size); + offset = vb->baddr & ~PAGE_MASK; + mem->size = PAGE_ALIGN(vb->size + offset); mem->is_userptr = 0; ret = -EINVAL; @@ -166,7 +168,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, break; if (pages_done == 0) - mem->dma_handle = this_pfn << PAGE_SHIFT; + mem->dma_handle = (this_pfn << PAGE_SHIFT) + offset; else if (this_pfn != (prev_pfn + 1)) ret = -EFAULT;