Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3344255pxv; Sun, 4 Jul 2021 16:06:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdxVU3q0vZm6Pnf3TWf/XWvfaw471GCs21LGnLj/wzbyXBQ8Y4BXeYB42qqRSinZJcOO3q X-Received: by 2002:a92:d4c5:: with SMTP id o5mr8898191ilm.306.1625440019763; Sun, 04 Jul 2021 16:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440019; cv=none; d=google.com; s=arc-20160816; b=wFdVN7q2ZnR9aAQNxi+Wx7G6ZqyHWYinhL0H9oJbjvqhobye5ljpnRhy5aS+N/sZ1P h1Mr8gArvL6F+ijmvZDmP6vmHu7xLP/jhsR4nFRgwwBYYk7UcYrHNBhe1KExoJPQdqRd kK3s6qK6h+3eoiu6rsuPgy/JdFUBNPEh3xCip2XaQNMM3C4S4xzknyqaansht+EWd+IB o3WokRoBQslx1TioJ1Jt7DE0DuGi5NLO7AhwDXb3dlyW88mVQWw6li18FHDYzWDqHy9f 5os22IM+Z7/T8LUiYhrAF6aowkV/6eCZXRhDvEbcccZinq4XPx2tjCH8TBDSW+72a1l1 mxXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UtEe/nBUELQRm2ICxEZAvZKAV28Lc76xUo3ibUz9sak=; b=UtM2g6RI/PQO+gz5K+3TIn+03a+E7tgBXApVUO1nTOuwRv0a1IErFQhzrXbpfd/Ueh 0yXHYpInsxZC2DcplFLhuqWrvL47hf1XhG1Myek24kQWQB10VulGSmEN+YkMQRLRwtzu yNA2iPxHnNfz/Mq9DjNrkXZnxROeVz+un4MKJxdvH7Hg3ycGQdI9wI6mvowiQuwZhD6E 8wFp/H3+5QDZXeeKXfRCNKcr4srWeLeHQ/ox9rGvFXVO6oBDzrTtZTuZNg/GZCUE0nFh Fu2N3GqORS23b19bzWf1D0cyHYrODAL3AgpFbR+yoJ9vDVpKzks41lfw2Muv4YrttRmS +Byw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bp7gd62g; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si12874015jat.109.2021.07.04.16.06.48; Sun, 04 Jul 2021 16:06:59 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bp7gd62g; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231245AbhGDXIW (ORCPT + 99 others); Sun, 4 Jul 2021 19:08:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:46560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230462AbhGDXH4 (ORCPT ); Sun, 4 Jul 2021 19:07:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5AA3A613F7; Sun, 4 Jul 2021 23:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439920; bh=v4eR9eBfNJKTlaalPEbz0PmDz4ulYk8/v1YOXOn6Qy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bp7gd62glvRAPWRIo4bZF6wWJzDpuGOh+M8WRBzNjktZyKpPfzRVPCwoyrYQ4FuJw SZ+JVdJTETzXfG8r3LsoqBCrgD7bx9G55JvbvQ1M06GZV+RyAL7GHm9j6JVsqq37Bu M5Nko1X6JdIpAdo5DT8Y1/T6XtB3CuAfVQudLfdC4+hRAZzOewC8louWf6MgEuu3f9 3Z5hcj8ugCqsLxr+RlIZuhoCYzvHqRju1t3L3bLFj7DVgP7enbu5ANFLBpzEkOzwGL uIuKfpMTu/tdLbN11wCAu9faYW0S6AUtNpFOgPMF2r66ozmJJMXjs9QO6HB8c7GMIr RipGcD/tjq5rA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrzej Pietrasiewicz , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH AUTOSEL 5.13 43/85] media: cedrus: Fix .buf_prepare Date: Sun, 4 Jul 2021 19:03:38 -0400 Message-Id: <20210704230420.1488358-43-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrzej Pietrasiewicz [ Upstream commit d84b9202d712309840f8b5abee0ed272506563bd ] The driver should only set the payload on .buf_prepare if the buffer is CAPTURE type. If an OUTPUT buffer has a zero bytesused set by userspace then v4l2-core will set it to buffer length. If we overwrite bytesused for OUTPUT buffers, too, then vb2_get_plane_payload() will return incorrect value which might be then written to hw registers by the driver in cedrus_h264.c or cedrus_vp8.c. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/sunxi/cedrus/cedrus_video.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c index b62eb8e84057..bf731caf2ed5 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c @@ -457,7 +457,13 @@ static int cedrus_buf_prepare(struct vb2_buffer *vb) if (vb2_plane_size(vb, 0) < pix_fmt->sizeimage) return -EINVAL; - vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage); + /* + * Buffer's bytesused must be written by driver for CAPTURE buffers. + * (for OUTPUT buffers, if userspace passes 0 bytesused, v4l2-core sets + * it to buffer length). + */ + if (V4L2_TYPE_IS_CAPTURE(vq->type)) + vb2_set_plane_payload(vb, 0, pix_fmt->sizeimage); return 0; } -- 2.30.2