From patchwork Wed Mar 27 15:17:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 10873675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 933921575 for ; Wed, 27 Mar 2019 15:20:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77EDF28D74 for ; Wed, 27 Mar 2019 15:20:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73A5628DDC; Wed, 27 Mar 2019 15:20:57 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 651FF28DBC for ; Wed, 27 Mar 2019 15:20:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730247AbfC0PUv (ORCPT ); Wed, 27 Mar 2019 11:20:51 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:48548 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbfC0PTY (ORCPT ); Wed, 27 Mar 2019 11:19:24 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id EC75C281FF7 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, hverkuil@xs4all.nl, helen.koike@collabora.com, lucmaga@gmail.com, linux-kernel@vger.kernel.org, kernel@collabora.com, lkcamp@lists.libreplanetbr.org Subject: [PATCH v2 09/15] media: vimc: cap: Allocate and verify mplanar buffers Date: Wed, 27 Mar 2019 12:17:37 -0300 Message-Id: <20190327151743.18528-10-andrealmeid@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190327151743.18528-1-andrealmeid@collabora.com> References: <20190327151743.18528-1-andrealmeid@collabora.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the driver is in multiplanar mode, fill the vb2 structures with the planes sizes and verify it the sizes allocated to the planes are enough. Signed-off-by: André Almeida Acked-by: Helen Koike --- Change in v2: - Use IS_MULTIPLANAR macro drivers/media/platform/vimc/vimc-capture.c | 42 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c index c344d04ed8ea..57bc2b64b093 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c @@ -505,12 +505,28 @@ static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, struct device *alloc_devs[]) { struct vimc_cap_device *vcap = vb2_get_drv_priv(vq); + const struct v4l2_plane_pix_format *plane_fmt = + vcap->format.fmt.pix_mp.plane_fmt; + unsigned int i; + + if (IS_MULTIPLANAR(vcap)) { + for (i = 0; i < *nplanes; i++) + if (sizes[i] < plane_fmt[i].sizeimage) + return -EINVAL; + } else if (*nplanes && sizes[0] < vcap->format.fmt.pix.sizeimage) + return -EINVAL; if (*nplanes) - return sizes[0] < vcap->format.fmt.pix.sizeimage ? -EINVAL : 0; - /* We don't support multiplanes for now */ - *nplanes = 1; - sizes[0] = vcap->format.fmt.pix.sizeimage; + return 0; + + if (IS_MULTIPLANAR(vcap)) { + *nplanes = vcap->format.fmt.pix_mp.num_planes; + for (i = 0; i < *nplanes; i++) + sizes[i] = plane_fmt[i].sizeimage; + } else { + *nplanes = 1; + sizes[0] = vcap->format.fmt.pix.sizeimage; + } return 0; } @@ -518,9 +534,23 @@ static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, static int vimc_cap_buffer_prepare(struct vb2_buffer *vb) { struct vimc_cap_device *vcap = vb2_get_drv_priv(vb->vb2_queue); - unsigned long size = vcap->format.fmt.pix.sizeimage; + unsigned long size; + unsigned int i; - if (vb2_plane_size(vb, 0) < size) { + if (IS_MULTIPLANAR(vcap)) { + for (i = 0; i < vb->num_planes; i++) { + size = vcap->format.fmt.pix_mp.plane_fmt[i].sizeimage; + if (vb2_plane_size(vb, i) < size) { + dev_err(vcap->dev, + "%s: buffer too small (%lu < %lu)\n", + vcap->vdev.name, vb2_plane_size(vb, i), + size); + + return -EINVAL; + } + } + } else if (vb2_plane_size(vb, 0) < vcap->format.fmt.pix.sizeimage) { + size = vcap->format.fmt.pix.sizeimage; dev_err(vcap->dev, "%s: buffer too small (%lu < %lu)\n", vcap->vdev.name, vb2_plane_size(vb, 0), size); return -EINVAL;