Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2825143pxv; Mon, 12 Jul 2021 02:52:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeVXWsnUj3NRFbyEQJf58Qn9yTsBqbCOmbt2DA1867tWpUBYtuKml61GU+Nf6zKzro+yWG X-Received: by 2002:a05:6602:71c:: with SMTP id f28mr24676442iox.161.1626083542026; Mon, 12 Jul 2021 02:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626083542; cv=none; d=google.com; s=arc-20160816; b=I0yignjIaiH4KTqrMsO9fD277BLIlHhnftZbdHJWdzB0/E+3Rq1ae9bRpCq/UO/zep Bp4gvs0lLII3OZ8O/4nlyzoI+GQPUFfJy1v0vRAM91px7VO0UK/3qI8JL5GfpXFphtaO FMcuiTsBXPXrt2bOFNXjI+JOb/OlWOu+aiVJ0FmhZz3y+p04Cfy+hKacSn3eh4LpCat+ OzdLtfu6avCrK2Azpf1Dnm9Khxqp0GknUEUspxvOxxQ/nWmdlM5OlWNC5NsXVUWYWRV1 WC+l5l1Y1QAAzaOJyXmy/qKF1R5PiiDvgamch5g40PxfwziBpGLGcV2X/cN/E1GBm519 MI0Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vtJ8CH5VajDMJSij6tUwbVcXuygX+lnhs7iGEoIwGJI=; b=jUKhU2yvyPGC6NfJ98ZqWXduCH4hzJ+UZlVmayVb3dd9/ndeUmHWRhpZgzKPqIGZ7i nCb0Lrb8iSwe9X79LRGWCMnSnUQ53YaUYH1rES0l5lJs7UUUSJ0rDhdHpRLvch6+mAoh jGXbvv+63hALkBWE8uFmGeWGKROXAZPSHuU82lsL14Y3djWAQZglLIcdms8jCjAHWrQx uSwvAUc+bNHCjx9VwgVbKayifeVaJDRdhQh/dENOQrXUf6wOnBY5PDGPNyROFcmurxMP vsKrr3Cwiz0qdvCLsmi5egTioWbDx0HlQdb/8xsL/PSVm8gypeRyLI1bbinBCnXTAi1H zK1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pD0izl3u; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si17025218iom.9.2021.07.12.02.52.10; Mon, 12 Jul 2021 02:52:22 -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=@linuxfoundation.org header.s=korg header.b=pD0izl3u; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238437AbhGLGrO (ORCPT + 99 others); Mon, 12 Jul 2021 02:47:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:54296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235244AbhGLGgb (ORCPT ); Mon, 12 Jul 2021 02:36:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C897D610A6; Mon, 12 Jul 2021 06:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071593; bh=TaoS9g5TrRsUhghe3xa90/jrdsLyfglBekaPaQsb4d8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pD0izl3ub+gUXdLh5qcXRkqVal8D8darechDSweH3N48E2CkOND0u1HfOfB6QZMrQ HB8XrbhzScXgiGZi3QwgFijZChEvbbsGc7oiwkwMDE2yp+gUn/9W88Sa6pa9CqAo9b SQoXYS6+i4x9fHYfq7QbFi5LdCCnBi/65MUwIe9c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrzej Pietrasiewicz , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.10 136/593] media: cedrus: Fix .buf_prepare Date: Mon, 12 Jul 2021 08:04:56 +0200 Message-Id: <20210712060858.067072501@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 911f607d9b09..16327be904d1 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c @@ -449,7 +449,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