Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3346394pxv; Sun, 4 Jul 2021 16:11:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzioXTmUN6rxlAu2hhPyuFUySpG4zrIUtCJoaw9mwiaXHFKft9sDcYo78Zy2/TuxI/qihpz X-Received: by 2002:a92:c708:: with SMTP id a8mr8451177ilp.177.1625440260750; Sun, 04 Jul 2021 16:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440260; cv=none; d=google.com; s=arc-20160816; b=ABJwa0k7R4HzPVbq6rd4+SJPhwaGJ+z+03k5hiUD4MmBFFl1Nmfp9tqb22ip3cs4Uv f4x1TVXI1M+NdcmqXyshWpZfv/TY33k0AENluL+iiJYCtlRLMGN7gcF4SbXlb2MT4vfD XoH0cHTrFehxgHxWHqzOLGk66gxdz5SFYCPQf53P7ib8Hg+LkorZfupEvyhbAH1oJCsO Kq80v+34mRKSfVsYz0JqZ1W9vt/tGEPU7fkMmE7kbzGC2wuSOy5CPv2ykskeqXT6TBlJ 38txfT+0XIcvc+neBOHNBVEkvQKTq9NEJCINkQYb8tz20m7uC3OYNO89b4FDOaEoFQQJ 6+ow== 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=Myk3U1kexlz+qV+pOF6lBKSDuMBkJXhLIUa3lsE3+dSfatVVvrM7h3giCoIkTj+Etx bGeaJR0UiMoj4QC2xvgPpkUtDAGRpurLI/KZmNNK9BmPN94GjvEzJR27OlS10dLJszDK 8AlYlDdc/LefchvtX7ianVt8dExnV/PCLZrS/vLeEg/YP800TENHYopt6u2wTISqjB3u p3u+T6avJhKp54bjEbEIQF7bD9IawXWTflWT4qXFD/P2Mp70FlHrLF1bOqEIhmx+8+7l f0WHgPSjjMuy8jaI+J0m2UICs56i8rQG78OR8MjajZVIlQpky7VDZYP6xm9uEo4H11Qg esDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DGll1Pnm; 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 u12si13049422ilm.144.2021.07.04.16.10.48; Sun, 04 Jul 2021 16:11:00 -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=DGll1Pnm; 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 S230061AbhGDXLr (ORCPT + 99 others); Sun, 4 Jul 2021 19:11:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:49270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232113AbhGDXKC (ORCPT ); Sun, 4 Jul 2021 19:10:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48AA061941; Sun, 4 Jul 2021 23:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440033; bh=v4eR9eBfNJKTlaalPEbz0PmDz4ulYk8/v1YOXOn6Qy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DGll1PnmWQGvmoLqXvhUs9ih9ftKqj4Svp2XG9r/RbP4ncJSsjCOafQWa2hSUP+R9 3UUDDPotFgOc+w/wtj1xdZhGFiYmMX9Kp6TEHpNevNVashJxFskJswkDcXPloVYuSp YuE9NTP+pvq6VuyxBAdIYwEMhywtP1K65Zp47yOImahCaZ5YLRNk+Ck9+o8q0FmyCx hmhjooNrlcmIPstxZLC7fkHJcTBACNa2w8Y6RSAEhGVARD4Vy9xgzs7F7U2eZQiGeL J0O9QGDFQj+b73OrGy4AtQsmto2BRBHoRYL+0b1HxgQv3xYK0n58MCgIGxhJoCcSDG gv+iSaf6CpJ4w== 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.12 41/80] media: cedrus: Fix .buf_prepare Date: Sun, 4 Jul 2021 19:05:37 -0400 Message-Id: <20210704230616.1489200-41-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230616.1489200-1-sashal@kernel.org> References: <20210704230616.1489200-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