Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3347404pxv; Sun, 4 Jul 2021 16:13:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJ+rEL4Z1AgpygXWGEdUXx1tyMVNOVTVeoyXs8LcQ/IKxW0CAkR/6pfRMW9IrWeyIrhJTC X-Received: by 2002:aa7:dbc3:: with SMTP id v3mr12756140edt.63.1625440388184; Sun, 04 Jul 2021 16:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440388; cv=none; d=google.com; s=arc-20160816; b=sI34HYvCF7Rd05Q+g2D71Pqpf9GA8MmKu9qQ7ogWmHrL8w9fQP+B/Qalsc4kxQWevx 5PZmQNd74Ot/eLTAq64ZF6gRUbX7qDgeOc6QbjnrRNgVcFOn+Vum3EU017yTpCFrBeW5 J2M3Fvt5bqGYDmnG7wANLrLRI3OsSzXl84aoCV1fqxBnYzdS8lDd393LGM8vGGm6cSfi hXMseO3kK3q1Bta90CYvsTATev9XdQy6K6y91GxkYyRh8NkWTl4vuYRgMAnQUnT5D6DX VPL8OlHb4Bt5bAx4HOnPEKWIogqnW6S7lEcPXLyxh+XW4VXgGaqfrk1V71gwr75EEjRs N8ew== 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=G3hOnfPKJaFslVKDE2MkjBwuZuwzt72CdXVZ3ms6AA+3osOiuf84j5v2pbzbISnJCM WoTM5G3J/yJgaUUTSWJ2ZlKI7kgC0BrpPT+25gDNXAqqNZNa6IFC0bu5VeoB0338NerJ 6zthRkTiGQ728iTUNBmS1GqhAgCBFcYJDPQ0qsx3qiFFLA7cyeENylFtgETa5l7KVzb5 32tES5ynrGSIJBOVa0z5R48y56GDkIT1B71SZtViVF9Ra/j/YxvPCsMYhzCAlpfwtKFN wEWuzgYRWsLVpih9aLrW1WivsV/YAh/c5/tjlA46wM4p6qmkJ2R62nTXljtb73ZHmNKW oslA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EYm41YaP; 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 p10si9765506ejo.39.2021.07.04.16.12.45; Sun, 04 Jul 2021 16:13:08 -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=EYm41YaP; 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 S232515AbhGDXLn (ORCPT + 99 others); Sun, 4 Jul 2021 19:11:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:46604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232112AbhGDXKC (ORCPT ); Sun, 4 Jul 2021 19:10:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E209C613F3; Sun, 4 Jul 2021 23:07:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440031; bh=I9lQf2lDW0MnmYwEu18O4W4OVDj02bCrE5JB6PVuLSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EYm41YaPv3RUCmjfu6wRfwXcD872AM1Fw+wIrO/uYFUEcyE9HlngeKVG95ngtGMeb JkPWWPacaQqkkXyvq4RG4aJFIXSie525r1FOIPFlYqk1XmNEELgGh9dvhHvOBXEXi1 oeo9i7wyTS1rPLN47zir7wb+PBNlSw0wseYd3jIZ8mWHAfyW48mm391pSeMSCGyu2T 0I19w7Z7ydymvq/wVvJMCzSgwzvGEvVF1mj8DAzZsabC9BRzJFs5+Qw9gFeHzhND1U WuvKzRq4LLSzxhA9HCpB1E43MB1PzDuatqukIZQkkvXaKLUKAum3n+Nz6Qa+1EjXln GWXLJQLfISBhQ== 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.12 40/80] media: hantro: Fix .buf_prepare Date: Sun, 4 Jul 2021 19:05:36 -0400 Message-Id: <20210704230616.1489200-40-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 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