Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5430986img; Wed, 27 Mar 2019 08:23:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYp6qv7hsIfOvpZyHxiK0RLMrYW23Zwl5HQBBHJ0gFO3Fpwid1hEBX2cdcACUtoaU64EO7 X-Received: by 2002:a65:65c5:: with SMTP id y5mr35346770pgv.192.1553700194137; Wed, 27 Mar 2019 08:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553700194; cv=none; d=google.com; s=arc-20160816; b=xCWZO76bNhWaYRXcR2vqNUa3+2w/HSW3ng7HfYGCjpYymFIFDXAf+P97Ylt5222soZ n3kmX+j6fr4x+kVfak1oso0hBySu9rgHCbG5EyrcQm8UVu/diLO9st6LYXSm0cg9MFws 7fd1ZnaVoVP1lRDkkdSuPtOxS68/KazuNMY49rWviz93YdtgURdxBhTW1H7lU2dMoZCy TT2GmznzP9G42ZGB2ct7JO/tfox2ZFOc7oloi4xyWI+CWWR3hZldfSqdDKR8qFek0FBe RXxe942osasbjOaVUArQ8n+w7VZv9XMf2wPcSJvgwiK9iOSQaWmAxYuvrHWtmWeWNauY 3uNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zBh3ysijYm7WBF4q6m4HDLLwItPsYIcPoD294HY79n0=; b=X/Fm2VLTstHT/rw/rjpile5SS1QZPGJqFQqE66wQAhTYe3psWq6A7P6nGwGPwbzh1g gR5kW6D1ZR6watWhPwPI0DH8W+klLr5aMnty7uO7/8PMI81lLSqS1FcU3HgieMyTtlPx 4j0G72kRejoJBri6nYSBEnwNGPHdlDLL5OfJACHmtjL60bysj5+uJWPTbJLsSMgCH4s5 46Gc9mu1TZhoVc2b3dpYjrY3eAGRNaBkLqEtoerq8UcRclgXM4/YxwdpF0uaW2wc2hBe zOsyeS/D3OwPWFvfetPiYg2F85UwjjXjUx57XZLpUuJV148snR1W6uID1Nrm0L6gXHAk mPVg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si1105918plj.417.2019.03.27.08.22.58; Wed, 27 Mar 2019 08:23:14 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730315AbfC0PUv (ORCPT + 99 others); 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=20Almeida?= 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.21.0