Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp604724ima; Fri, 15 Mar 2019 09:48:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaANl/NqySSAtP3TwUL7Gim7dkxpYFB06uV6Zb6TXV7BMOhmWEdPWszZV04sIlF/ZXpKQd X-Received: by 2002:a17:902:a414:: with SMTP id p20mr5096914plq.289.1552668487995; Fri, 15 Mar 2019 09:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552668487; cv=none; d=google.com; s=arc-20160816; b=AkGSM4xeFsDdQmDXz2rqmxt2sJKO9uVFyTfLHjHExrB8qETZL7BRIZ30CRQ5jjU0d3 e2ZfItCVrb4//jEpBrPsn1OwLIjIgfXi/mDaPOgrUStGetMVOxELAuqwNEZvBtsPYx5F qD3Wvnr152DtI28lTzx3Q3TpcfDAgk3komWf8DRSPVl5Ft1vHszmOR2xd7ZuqRzdQMAP DwhdFGOXQ9SPbERgRshLNp1z/k8cHfyF24J64FnYuP4jBNBaR/Av7y1hYbtWgbOPb1v+ 7yebyO7DIbUtV99Kwxh6uXbfj2BF9DTPCuRwziS9pfnJ/rUsAq8+0tfrA5nDGlT5GQMJ cUoQ== 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=JSRaQ29+xSmy/K5ph+O/JQAJpY3d3BIC9rLNK79E1Sc=; b=W6QZ2d8561xUHQ4txa0G/8H9qFNwbzU33/BPSaEsvGB/iy+C+xSE8I609gClXALFIh UG7mmNWPz6QmKBILzGgy4LfhmkKJhwwxT16/oomA9K1GQI5s90DQb0hyS82duTEsRrko JM3tV664U94SFgDj5CH8Eo7P1NrxtJ6wumY9lLH+t8fDViQ3wyWevWg/TWXu1SZHpkcH n0Lck1fajzM4mhjG//jwfg+zEhI88P9I8h9H071w114e7pbitgyyshIIehOa1UrspqYT iIBBpCeebKroOWEvLdFI3EKmncsn3aaJonT6x+a0UkiJt1WQgphZ9oD9CvJyRVpJ2f1t Oo2A== 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 r198si2122721pgr.519.2019.03.15.09.47.52; Fri, 15 Mar 2019 09:48:07 -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 S1729825AbfCOQpj (ORCPT + 99 others); Fri, 15 Mar 2019 12:45:39 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49052 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729815AbfCOQpg (ORCPT ); Fri, 15 Mar 2019 12:45:36 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 5129C281581 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 Subject: [PATCH 11/16] media: vimc: cap: Allocate and verify mplanar buffers Date: Fri, 15 Mar 2019 13:43:54 -0300 Message-Id: <20190315164359.626-12-andrealmeid@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190315164359.626-1-andrealmeid@collabora.com> References: <20190315164359.626-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 --- 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 24052f15c4cf..83196b8c31b5 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c @@ -486,12 +486,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 (multiplanar) { + 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 (multiplanar) { + *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; } @@ -499,9 +515,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 (multiplanar) { + 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