Received: by 10.223.185.111 with SMTP id b44csp123586wrg; Fri, 9 Mar 2018 02:11:57 -0800 (PST) X-Google-Smtp-Source: AG47ELtQUWYCuP3inaGzg9ITXnNgBPDad8qBlLIbhZ+AWAd3+qpNaaUJGFS92MDWlbjd8EdOoZPs X-Received: by 2002:a17:902:ba95:: with SMTP id k21-v6mr27613700pls.111.1520590317774; Fri, 09 Mar 2018 02:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520590317; cv=none; d=google.com; s=arc-20160816; b=t86v+1fQmSfr3/YHfR6THVOaI+aehpzmWPUxH69VTcoVzd6rvme1/WLJ/3Iv1pR3nF pCY5pHDxf8DZrcOT+RFzwd0OIr6VVJpU6qyCwWvdF5ottcm3KiMIphjDXQRhkm2Jbgzp m36N68XmOqQ25+hbbDipPdPKlLumZLidWroWaGvqrpFECPCBP/ULcAuOi+BwMF7u7W6G /sH91bgkG+1WMWLZn15/XSAFUIIucOHUornJPKhkDo3u+ZqyartOf4TN2Ig51wL5jcu/ X1yHQzEuQLFoMtBM2Ne3vWFHWv+m4dqnE2cIheUZfXcbWLHn+ZewTb3qiXUTEWAa/Igi TDPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=DWBm6jZQ4DlUjjPjB0KFTGC7eybQbXO8IQikfVSojyQ=; b=IPctQ9HAjF5aQXZ3aXVksvXEHhuTWkkIgOUZg8eYMiGkPfs3pT0z1SA9BALD+2bDfq Fu16UGI/TrxuFIxJiZwGc6enukExX3L7WqX0zcFvVISoFClVU8Or2jz3afEB45SZNVE/ T8wSnLbs04LaTyNyvexCATlkYHEjwtd1K519jOxwMlS+y2yGfnXNyuRMpEVFVQrgwf8I 7cZB/bM1SHnzdq0BTqjgoTPjty3ugkjMwVkLEw+AM7AkFPJnh9qFJQ6zkDAiHln6e4rV pwAAX0FAbneFcDQpNYbl0w4e7kQQtUvOqNb8P5Cc+T9Xorr+5CoLHL4bm05IMIECumQw O6sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si510714pgr.233.2018.03.09.02.11.42; Fri, 09 Mar 2018 02:11:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751198AbeCIKKs (ORCPT + 99 others); Fri, 9 Mar 2018 05:10:48 -0500 Received: from mail.bootlin.com ([62.4.15.54]:49675 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750966AbeCIKKl (ORCPT ); Fri, 9 Mar 2018 05:10:41 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id DAC162077B; Fri, 9 Mar 2018 11:10:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 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 Cc: Icenowy Zheng , Florent Revest , Alexandre Courbot , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Maxime Ripard , Thomas van Kleef , "Signed-off-by : Bob Ham" , Thomas Petazzoni , Chen-Yu Tsai , Paul Kocialkowski 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.16.2