Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3344648pxv; Sun, 4 Jul 2021 16:07:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+TiNaJ7OdeL+8T6NZYa5S/iLBrqyaQkpC46rHY0ttQGhNjKi/aZMY/BD9e3Vx4rNgOhNM X-Received: by 2002:a05:6402:4408:: with SMTP id y8mr12912505eda.55.1625440062183; Sun, 04 Jul 2021 16:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440062; cv=none; d=google.com; s=arc-20160816; b=RDcX8AWRxsulCxiVFPmYpISzAq8RMcaTiY1xB1RiAFLJHK2+m17Nm5mH20maNnDiqz mYKyibS8c0cJuAlya66Fn/pxuCGTnFgw1xJyAW2rDMEw3RrMF705mr/UtmKsSuB8fvTb 7vjLN77wvJTcwVwpS5NWilTlVX+aImVUHMUd9/kkGsvXoiMNr3TtJtw4GtnjVLe3iggK 45+r+6x3kHYRbIAX5nQYwZxqHcYwRYmuPmq6XHy2jw09IBj1M4O9XxQR/rv6ZfIY/z4b grZ6JA5Wp8phs+uiGZiJ3C4IW86eYIFwdfe/Ijn+qAZQCidVuBpMY/f/Yc51+pL4l3CA yC6Q== 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=KEX9HAE1O3YrKQddnzEePzu2KFG52Jmg6osHbdOyWbA=; b=i3VCBIBo58dXYhhaePocbcZ1fkLsiruguoXcF0y9nKacLHrWPJ7rCviZlla+7B9qf2 gSF7iP3fBw4TEiU97jY48Mw8PN6sAmbxMN6JjcTxoQEpYdNgLabTiti/JW1J0wx9ZhX2 DozqbBBUy/DuV195rsDqKbrNBt3Uh/OpaaQ3Nf8jf+a4e9JHI5IjjPvm2A4mRx1AoJBd P+GZ5JEbzQ8KPCLbCKVM8/m2tbDlfzUwGcKpAj49NL6i3JlnprbndXuVgoEG2Hw2YMCj R8+5YpzAY+/j9aR/kO5EFYkMaBasp7yiU4xMTKI5Hw0V71+HSBjBNrKAXWp5ZQIRmCNg 3Ylw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pDRZB1zD; 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 n24si6252429edb.591.2021.07.04.16.07.19; Sun, 04 Jul 2021 16:07:42 -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=pDRZB1zD; 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 S230416AbhGDXIY (ORCPT + 99 others); Sun, 4 Jul 2021 19:08:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:46514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbhGDXHy (ORCPT ); Sun, 4 Jul 2021 19:07:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED76D613E5; Sun, 4 Jul 2021 23:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439918; bh=I9lQf2lDW0MnmYwEu18O4W4OVDj02bCrE5JB6PVuLSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pDRZB1zDXLkBzumaVjpnGUg4b8/4Gi4GRYEFczQpGxapR8bHTMNSxWyfcCotGz0Wm ctkjpSP3LXyaTEx2NXARj51YM63ZoML5l6f4A45wi4soJxMKp0ZsAkF/IT7LN10wOs ZxJIXgrp/9oMC9VJOjO7PwCi/A93Ma0rT+4oo71X23PUPQOnxhYiX31TbwFR5uR4Ad PZ31Hma898xxwy/n5SV60hAMEbf1BKR8FE3x0DZto2IPfBDp4a0NfwFh5KFsPfSxK/ qg7I7F8COCfjn1p/DES8TpcbtJrxUftXm2qrLHcn03QVy12QZk2Dj45ZYxxo/L54DI OY9RSfqrAiDqA== 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-rockchip@lists.infradead.org, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 5.13 42/85] media: hantro: Fix .buf_prepare Date: Sun, 4 Jul 2021 19:03:37 -0400 Message-Id: <20210704230420.1488358-42-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 082aaecff35fbe1937531057911b1dd1fc6b496e ] 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 hantro_g1_h264_dec.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/hantro/hantro_v4l2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/hantro/hantro_v4l2.c b/drivers/staging/media/hantro/hantro_v4l2.c index 1bc118e375a1..7ccc6405036a 100644 --- a/drivers/staging/media/hantro/hantro_v4l2.c +++ b/drivers/staging/media/hantro/hantro_v4l2.c @@ -639,7 +639,14 @@ static int hantro_buf_prepare(struct vb2_buffer *vb) ret = hantro_buf_plane_check(vb, pix_fmt); if (ret) return ret; - vb2_set_plane_payload(vb, 0, pix_fmt->plane_fmt[0].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->plane_fmt[0].sizeimage); + return 0; } -- 2.30.2