Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2471486pxj; Sat, 19 Jun 2021 13:24:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5NcW04LvqHqsffJmhzvViEFr1eV0Ta5/LSsXecr2TmLXhdP3o3bxKBhmP78xiABPx/yI3 X-Received: by 2002:a17:907:1609:: with SMTP id hb9mr7396529ejc.368.1624134249055; Sat, 19 Jun 2021 13:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624134249; cv=none; d=google.com; s=arc-20160816; b=GPn1oEDR86YQiqt7cM4D2JFKjjUfRebqtqxBEfZk/I7MwLCJrrxnZlzGJfJw12RZky DJYcXaXzn+o9aNT7wgBRMoivbM04txPf0nDkzREy4vmNpkvMZKiZA2F1WncD7r5Nbbg+ H9qSK+aQxFU9Ynu4512wWI3jqAhRzn7XtaEBHl4alFY+kRnZ7xVU0AkDkBgkjOrwMmXD 9dbPKiqi2K84SEnn75eavH4L1+YO+cigWS6quxEbJobjvQYdPOmCDQR968sYBXsAc+CT Whxg7Xplmn2uFiF8j+fJwGcqUXJKN718s8JewGqUSKWKgkBQHx55oppMgOMK2gMowc24 c6iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=h/aDrrVDpi+RPq2PVOnJSPKOT8uA6KuRsCX3ZBpnYd0=; b=se740qkxtBQuRpjXeBFJ9HpxwuiY8mWD/Wpv3J9tFmXhwbW1jDEC6QLpR4iyZnr99d iTmDzttFU009BkAM881KB6zKdad/EHZxd+Z1MwAauSEKP+pkvLkbymkWaFx4XBb8hJwT JnXt+/vPtf9gkv7JTKRX5SesvVA8VGrmANhNfJ8qCEDdwlhdhZkbHf8j+8LstRkAO6fB 0jX1vbr3qipLq6sP2MEXwGqm7inI1dlj4xAb3AVsySr+S8zh5iLBS0eNGUhi1BVxYq8a cVc7eUuih97M1Cbq0BgtD3OBK4o6W+HtF8/7TavxOXA0K4bAuekh7BeQPPzZeTJvlEmE zs4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id jl14si5490377ejc.222.2021.06.19.13.23.46; Sat, 19 Jun 2021 13:24:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231128AbhFSJtQ (ORCPT + 99 others); Sat, 19 Jun 2021 05:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbhFSJtP (ORCPT ); Sat, 19 Jun 2021 05:49:15 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A426C061574; Sat, 19 Jun 2021 02:47:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id D2E9E1F448EC From: Dafna Hirschfeld To: linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, bin.liu@mediatek.com, rick.chang@mediatek.com Cc: dafna.hirschfeld@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, mchehab@kernel.org, tfiga@chromium.org, matthias.bgg@gmail.com, enric.balletbo@collabora.com Subject: [PATCH] media: mtk-jpeg: fix setting plane paylod Date: Sat, 19 Jun 2021 12:46:42 +0300 Message-Id: <20210619094642.17779-1-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In mtk_jpeg_buf_prepare, in case the format is V4L2_PIX_FMT_JPEG, then the payload of the vb2_buffer planes can be overwritten only if 'ctx->enable_exif' is true, in that case, the driver is a jpeg encoder and the payload is determined by the driver. If 'ctx->enable_exif' is not set and the format is V4L2_PIX_FMT_JPEG then the payload might came from userspace (in case of a decoder) and should not be overwritten by the driver. In addition, the cb 'queue_setup' should add the MTK_JPEG_MAX_EXIF_SIZE to the plane sizes in case the format is V4L2_PIX_FMT_JPEG and ctx->enable_exif is set. Signed-off-by: Dafna Hirschfeld --- .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 88a23bce569d..397a27888a84 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -651,6 +651,7 @@ static int mtk_jpeg_queue_setup(struct vb2_queue *q, struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q); struct mtk_jpeg_q_data *q_data = NULL; struct mtk_jpeg_dev *jpeg = ctx->jpeg; + unsigned int exif_extra; int i; v4l2_dbg(1, debug, &jpeg->v4l2_dev, "(%d) buf_req count=%u\n", @@ -660,18 +661,20 @@ static int mtk_jpeg_queue_setup(struct vb2_queue *q, if (!q_data) return -EINVAL; + exif_extra = ctx->enable_exif && V4L2_TYPE_IS_CAPTURE(q->type) ? + MTK_JPEG_MAX_EXIF_SIZE : 0; + if (*num_planes) { for (i = 0; i < *num_planes; i++) - if (sizes[i] < q_data->pix_mp.plane_fmt[i].sizeimage) + if (sizes[i] < q_data->pix_mp.plane_fmt[i].sizeimage + exif_extra) return -EINVAL; return 0; } *num_planes = q_data->fmt->colplanes; for (i = 0; i < q_data->fmt->colplanes; i++) { - sizes[i] = q_data->pix_mp.plane_fmt[i].sizeimage; - v4l2_dbg(1, debug, &jpeg->v4l2_dev, "sizeimage[%d]=%u\n", - i, sizes[i]); + sizes[i] = q_data->pix_mp.plane_fmt[i].sizeimage + exif_extra; + v4l2_dbg(1, debug, &jpeg->v4l2_dev, "sizes[%d]=%u\n", i, sizes[i]); } return 0; @@ -690,12 +693,11 @@ static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb) for (i = 0; i < q_data->fmt->colplanes; i++) { plane_fmt = q_data->pix_mp.plane_fmt[i]; - if (ctx->enable_exif && - q_data->fmt->fourcc == V4L2_PIX_FMT_JPEG) - vb2_set_plane_payload(vb, i, plane_fmt.sizeimage + + if (q_data->fmt->fourcc != V4L2_PIX_FMT_JPEG) + vb2_set_plane_payload(vb, i, plane_fmt.sizeimage); + else if (ctx->enable_exif) + vb2_set_plane_payload(vb, i, plane_fmt.sizeimage + MTK_JPEG_MAX_EXIF_SIZE); - else - vb2_set_plane_payload(vb, i, plane_fmt.sizeimage); } return 0; -- 2.17.1