linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
To: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com
Cc: Icenowy Zheng <icenowy@aosc.xyz>,
	Florent Revest <revestflo@gmail.com>,
	Alexandre Courbot <acourbot@chromium.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Thomas van Kleef <thomas@vitsch.nl>,
	"Signed-off-by : Bob Ham" <rah@settrans.net>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Chen-Yu Tsai <wens@csie.org>,
	Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Subject: [PATCH 2/9] media: videobuf2-v4l2: Copy planes when needed in request qbuf
Date: Fri,  9 Mar 2018 11:09:26 +0100	[thread overview]
Message-ID: <20180309100933.15922-3-paul.kocialkowski@bootlin.com> (raw)
In-Reply-To: <20180309100933.15922-1-paul.kocialkowski@bootlin.com>

Multiplanar formats require an extra planes array in their buffers, that
is copied from userspace by the video_usercopy function prior to
dispatching the ioctl request. This wrapper also frees the allocated
planes array after the ioctl handler has returned.

In the context of the V4L2 request API, we need to keep this planes
array around so that it can be used when submitting the request later.

Thus, allocate the array and copy its contents when adding the buffer to
the request-specific queue.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/media/common/videobuf2/videobuf2-v4l2.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 0627c3339572..c14528d4a518 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -592,6 +592,7 @@ int vb2_qbuf_request(struct vb2_queue *q, struct v4l2_buffer *b,
 	struct media_request *req;
 	struct vb2_buffer *vb;
 	int ret = 0;
+	int i;
 
 	if (b->request_fd <= 0)
 		return vb2_qbuf(q, b);
@@ -657,6 +658,17 @@ int vb2_qbuf_request(struct vb2_queue *q, struct v4l2_buffer *b,
 	qb->pre_req_state = vb->state;
 	qb->queue = q;
 	memcpy(&qb->v4l2_buf, b, sizeof(*b));
+
+	if (V4L2_TYPE_IS_MULTIPLANAR(b->type) && b->length > 0) {
+		qb->v4l2_buf.m.planes = kcalloc(b->length,
+						sizeof(struct v4l2_plane),
+						GFP_KERNEL);
+
+		for (i = 0; i < b->length; i++)
+			 memcpy(&qb->v4l2_buf.m.planes[i], &b->m.planes[i],
+				sizeof(struct v4l2_plane));
+	}
+
 	vb->request = req;
 	vb->state = VB2_BUF_STATE_QUEUED;
 	list_add_tail(&qb->node, &data->queued_buffers);
@@ -672,6 +684,7 @@ EXPORT_SYMBOL_GPL(vb2_qbuf_request);
 int vb2_request_submit(struct v4l2_request_entity_data *data)
 {
 	struct v4l2_vb2_request_buffer *qb, *n;
+	int i;
 
 	/* v4l2 requests require at least one buffer to reach the device */
 	if (list_empty(&data->queued_buffers)) {
@@ -686,6 +699,12 @@ int vb2_request_submit(struct v4l2_request_entity_data *data)
 		list_del(&qb->node);
 		vb->state = qb->pre_req_state;
 		ret = vb2_core_qbuf(q, vb->index, &qb->v4l2_buf);
+
+		if (V4L2_TYPE_IS_MULTIPLANAR(qb->v4l2_buf.type) &&
+		    qb->v4l2_buf.length > 0)
+			for (i = 0; i < qb->v4l2_buf.length; i++)
+				kfree(&qb->v4l2_buf.m.planes[i]);
+
 		kfree(qb);
 		if (ret)
 			return ret;
-- 
2.16.2

  parent reply	other threads:[~2018-03-09 10:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 10:09 [PATCH 0/9] Sunxi-Cedrus driver for the Allwinner Video Engine, using the V4L2 request API Paul Kocialkowski
2018-03-09 10:09 ` [PATCH 1/9] media: vim2m: Try to schedule a m2m device run on request submission Paul Kocialkowski
2018-03-09 10:09 ` Paul Kocialkowski [this message]
2018-03-09 10:14   ` [PATCH 3/9] v4l: Add sunxi Video Engine pixel format Paul Kocialkowski
2018-03-09 10:14   ` [PATCH 4/9] v4l: Add MPEG2 low-level decoder API control Paul Kocialkowski
2018-03-09 10:14   ` [PATCH 5/9] media: platform: Add Sunxi Cedrus decoder driver Paul Kocialkowski
2018-03-09 13:57     ` Maxime Ripard
2018-03-09 14:25       ` Paul Kocialkowski
2018-04-19 14:58       ` Paul Kocialkowski
2018-03-12 17:15     ` [linux-sunxi] " Joonas Kylmälä
2018-04-19 14:56       ` Paul Kocialkowski
2018-03-12 20:29     ` Joonas Kylmälä
2018-04-19 14:56       ` Paul Kocialkowski
2018-03-09 10:14   ` [PATCH 6/9] sunxi-cedrus: Add device tree binding document Paul Kocialkowski
2018-03-09 13:38     ` [linux-sunxi] " Priit Laes
2018-03-09 13:45       ` Paul Kocialkowski
2018-03-18 12:48     ` Rob Herring
2018-04-19 14:55       ` Paul Kocialkowski
2018-03-09 10:14   ` [PATCH 7/9] ARM: dts: sun5i: Use video-engine node Paul Kocialkowski
2018-03-09 10:14   ` [PATCH 8/9] ARM: dts: sun8i: add video engine support for A33 Paul Kocialkowski
2018-03-09 10:14   ` [PATCH 9/9] ARM: dts: sun7i: Add video engine support for the A20 Paul Kocialkowski
2018-03-12 18:18   ` [linux-sunxi] [PATCH 2/9] media: videobuf2-v4l2: Copy planes when needed in request qbuf Joonas Kylmälä
2018-03-09 10:18 ` [PATCH 0/9] Sunxi-Cedrus driver for the Allwinner Video Engine, using the V4L2 request API Paul Kocialkowski

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=20180309100933.15922-3-paul.kocialkowski@bootlin.com \
    --to=paul.kocialkowski@bootlin.com \
    --cc=acourbot@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hans.verkuil@cisco.com \
    --cc=icenowy@aosc.xyz \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-sunxi@googlegroups.com \
    --cc=maxime.ripard@bootlin.com \
    --cc=rah@settrans.net \
    --cc=revestflo@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=thomas@vitsch.nl \
    --cc=wens@csie.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).