All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Kara <jack@suse.cz>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Fabian Frederick <fabf@skynet.be>,
	"Prabhakar Lad" <prabhakar.csengg@gmail.com>,
	Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Subject: [PATCH 2/9] [media] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns()
Date: Wed, 10 Jun 2015 06:20:45 -0300	[thread overview]
Message-ID: <0bec810973e08df0e66260e84d2dcea055a3fad7.1433927458.git.mchehab@osg.samsung.com> (raw)
In-Reply-To: <cover.1433927458.git.mchehab@osg.samsung.com>
In-Reply-To: <cover.1433927458.git.mchehab@osg.samsung.com>

From: Jan Kara <jack@suse.cz>

Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() instead of
hand made mapping of virtual address to physical address. Also the
function leaked page reference from get_user_pages() so fix that by
properly release the reference when omap_vout_buffer_release() is
called.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
[hans.verkuil@cisco.com: remove unused struct omap_vout_device *vout variable]

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
index f09c5f17a42f..7feb6394f111 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -195,46 +195,34 @@ static int omap_vout_try_format(struct v4l2_pix_format *pix)
 }
 
 /*
- * omap_vout_uservirt_to_phys: This inline function is used to convert user
- * space virtual address to physical address.
+ * omap_vout_get_userptr: Convert user space virtual address to physical
+ * address.
  */
-static unsigned long omap_vout_uservirt_to_phys(unsigned long virtp)
+static int omap_vout_get_userptr(struct videobuf_buffer *vb, u32 virtp,
+				 u32 *physp)
 {
-	unsigned long physp = 0;
-	struct vm_area_struct *vma;
-	struct mm_struct *mm = current->mm;
+	struct frame_vector *vec;
+	int ret;
 
 	/* For kernel direct-mapped memory, take the easy way */
-	if (virtp >= PAGE_OFFSET)
-		return virt_to_phys((void *) virtp);
-
-	down_read(&current->mm->mmap_sem);
-	vma = find_vma(mm, virtp);
-	if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
-		/* this will catch, kernel-allocated, mmaped-to-usermode
-		   addresses */
-		physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start);
-		up_read(&current->mm->mmap_sem);
-	} else {
-		/* otherwise, use get_user_pages() for general userland pages */
-		int res, nr_pages = 1;
-		struct page *pages;
+	if (virtp >= PAGE_OFFSET) {
+		*physp = virt_to_phys((void *)virtp);
+		return 0;
+	}
 
-		res = get_user_pages(current, current->mm, virtp, nr_pages, 1,
-				0, &pages, NULL);
-		up_read(&current->mm->mmap_sem);
+	vec = frame_vector_create(1);
+	if (!vec)
+		return -ENOMEM;
 
-		if (res == nr_pages) {
-			physp =  __pa(page_address(&pages[0]) +
-					(virtp & ~PAGE_MASK));
-		} else {
-			printk(KERN_WARNING VOUT_NAME
-					"get_user_pages failed\n");
-			return 0;
-		}
+	ret = get_vaddr_frames(virtp, 1, true, false, vec);
+	if (ret != 1) {
+		frame_vector_destroy(vec);
+		return -EINVAL;
 	}
+	*physp = __pfn_to_phys(frame_vector_pfns(vec)[0]);
+	vb->priv = vec;
 
-	return physp;
+	return 0;
 }
 
 /*
@@ -784,11 +772,15 @@ static int omap_vout_buffer_prepare(struct videobuf_queue *q,
 	 * address of the buffer
 	 */
 	if (V4L2_MEMORY_USERPTR == vb->memory) {
+		int ret;
+
 		if (0 == vb->baddr)
 			return -EINVAL;
 		/* Physical address */
-		vout->queued_buf_addr[vb->i] = (u8 *)
-			omap_vout_uservirt_to_phys(vb->baddr);
+		ret = omap_vout_get_userptr(vb, vb->baddr,
+				(u32 *)&vout->queued_buf_addr[vb->i]);
+		if (ret < 0)
+			return ret;
 	} else {
 		unsigned long addr, dma_addr;
 		unsigned long size;
@@ -834,12 +826,13 @@ static void omap_vout_buffer_queue(struct videobuf_queue *q,
 static void omap_vout_buffer_release(struct videobuf_queue *q,
 			    struct videobuf_buffer *vb)
 {
-	struct omap_vout_device *vout = q->priv_data;
-
 	vb->state = VIDEOBUF_NEEDS_INIT;
+	if (vb->memory == V4L2_MEMORY_USERPTR && vb->priv) {
+		struct frame_vector *vec = vb->priv;
 
-	if (V4L2_MEMORY_MMAP != vout->memory)
-		return;
+		put_vaddr_frames(vec);
+		frame_vector_destroy(vec);
+	}
 }
 
 /*
-- 
2.4.2


  parent reply	other threads:[~2015-06-10  9:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10  9:20 [PATCH 0/9] Helper to abstract vma handling in media layer Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 1/9] mm: Provide new get_vaddr_frames() helper Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-11  8:01   ` Sergey Senozhatsky
2015-06-11  8:01     ` Sergey Senozhatsky
2015-06-10  9:20 ` Mauro Carvalho Chehab [this message]
2015-06-11  4:21   ` [PATCH 2/9] [media] media: omap_vout: Convert omap_vout_uservirt_to_phys() to use get_vaddr_pfns() Laurent Pinchart
2015-06-11 17:23     ` Hans Verkuil
2015-06-12  9:21     ` Tomi Valkeinen
2015-06-12  9:26       ` Laurent Pinchart
2015-06-12  9:44         ` Tomi Valkeinen
2015-06-10  9:20 ` [PATCH 3/9] [media] vb2: Provide helpers for mapping virtual addresses Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 4/9] [media] media: vb2: Convert vb2_dma_sg_get_userptr() to use frame vector Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 5/9] [media] media: vb2: Convert vb2_vmalloc_get_userptr() " Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 6/9] [media] media: vb2: Convert vb2_dc_get_userptr() " Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 7/9] [media] media: vb2: Remove unused functions Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 8/9] [media] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames() Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10  9:20 ` [PATCH 9/9] [media] mm: Move get_vaddr_frames() behind a config option Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10  9:20   ` Mauro Carvalho Chehab
2015-06-10 16:37   ` Josh Triplett
2015-06-10 16:37     ` Josh Triplett
2015-06-10 16:37     ` Josh Triplett
2015-06-10 16:37     ` Josh Triplett
2015-06-18 13:44     ` Jan Kara
2015-06-18 13:44       ` Jan Kara
2015-06-18 13:44       ` Jan Kara
2015-06-18 13:44       ` Jan Kara
2015-06-11  9:08 ` [PATCH 0/9] Helper to abstract vma handling in media layer Hans Verkuil
2015-06-11 18:54   ` Andrew Morton
2015-06-11 19:51     ` Hans Verkuil
2015-06-15  7:41 ` Hans Verkuil
2015-06-22 22:04 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0bec810973e08df0e66260e84d2dcea055a3fad7.1433927458.git.mchehab@osg.samsung.com \
    --to=mchehab@osg.samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=fabf@skynet.be \
    --cc=hans.verkuil@cisco.com \
    --cc=jack@suse.cz \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=prabhakar.csengg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.