From patchwork Fri Mar 9 10:09:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 10270307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE90660211 for ; Fri, 9 Mar 2018 10:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94C9328D11 for ; Fri, 9 Mar 2018 10:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 894C829D82; Fri, 9 Mar 2018 10:11:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3233E28D11 for ; Fri, 9 Mar 2018 10:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=w2ArieyE72a+oU09iFkR0TkfO6vApAOsL5vPKDlh6N4=; b=N+xrzHP6kbRh3dh9VDkESwL5TY 0m/hBByPw2Y50BUuBWJ295eCQLZh9JfXdSuYK6+WYUCf3ojL6VKe0cq09lfmsFAadglSDcSeW2FRU dpNPncewD+Flah82KK93if466kSE7HNqqBTcH3CMUtM0il/N3OFQZpVIdJRSF1Itbv/2wVaOuSkH2 wCuqqAZOxwxOcS8UIijcZOR/9qnjYSJGYhPVo+HDS/7rXbLnC+yYsXwY9eo2XrdSZa/HUQM9iGBYj PGJ2Ipd1vJqu6UO+eoY8+U0kodYxil965Cv+ZM/r9jiHc+nwYnQVGJ9WT8JM4yqZRyp4YZV/sg0Sq 7qG19GpQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1euEzf-0006Pd-HN; Fri, 09 Mar 2018 10:11:19 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1euEzD-00067Q-RN for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 10:10:53 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id DAC162077B; Fri, 9 Mar 2018 11:10:38 +0100 (CET) Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 5914E20379; Fri, 9 Mar 2018 11:10:38 +0100 (CET) From: Paul Kocialkowski 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 Subject: [PATCH 2/9] media: videobuf2-v4l2: Copy planes when needed in request qbuf Date: Fri, 9 Mar 2018 11:09:26 +0100 Message-Id: <20180309100933.15922-3-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180309100933.15922-1-paul.kocialkowski@bootlin.com> References: <20180309100933.15922-1-paul.kocialkowski@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_021052_222805_D4B0F949 X-CRM114-Status: GOOD ( 13.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Signed-off-by : Bob Ham" , Thomas Petazzoni , Alexandre Courbot , Maxime Ripard , Chen-Yu Tsai , Paul Kocialkowski , Florent Revest , Hans Verkuil , Icenowy Zheng , Sakari Ailus , Thomas van Kleef , Laurent Pinchart MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;