From patchwork Thu Nov 9 16:34:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 163522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp568490vqs; Thu, 9 Nov 2023 08:56:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHW1E2P4YtQ7NZOizMFmfEDtGgqKZ6BgzDoRTHngosq5RXeCERsf0VRaDBGRQTwSvB4tXRL X-Received: by 2002:a17:903:1cc:b0:1bb:6875:5a73 with SMTP id e12-20020a17090301cc00b001bb68755a73mr5981654plh.2.1699549019644; Thu, 09 Nov 2023 08:56:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699549019; cv=none; d=google.com; s=arc-20160816; b=JYG30HElccibF3o+lBYGQCrg98dvfkm2k3DgwArpsGADYYxODnlEPdTznJwuhvZKhG f9KoG/g9I61W9jVGSPf9bcXLuGBYp5qM8eX59iSg8V7Qt33kaF67NqpBGJchT+8TdGuv jefcQ9L73lgEcPFMiwhLa5pGTWb/vbFRyiOpdF7mREKIP5rQbm/Zh9LwVkqq1MQBka/F A2pfol7e5ql/lgVXMzb3BCSKibSo3P3Gq1sfwM4EYjrSCojXf7jAJzuY/BKSjKwpiiRK 9CSKiVdoF1nV1my33HfTQrIcl4yD/D57okBeVV5fguRQfl/CdumdK7U3k5SKSCu27d9Q u2oA== 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=65qp/QGgaBf2hwYevjzFRWIwFujxl9lSbWbkrj80PjE=; fh=HaAiuVP/Dk4OPgKKBVp8ednw4WCxxNtRUGtKII+L22Y=; b=BNqawq5vVv+1SJVwqX38M+Tz0XO5MerrUHkdfhVEB3S7gm+S2UAE0HShsUht4FSWd5 rPqcIOJfHVafsLiiZGHnxd6bTd+aFXF9+PtCVC2iav6ujmuQWclqQtZV0miIR360RSXL WyE4HDQpluSi8EZTPTYAD42+RrkT6Ai2HWK5jbBB7CAg5VpPP1pfFTJP1afMxdZ6uH3V kjFHvbkEBYrverdnMzQlQ4ZIuiYB2rAayrhh+L9FtyobRGBl/5BQlbnes+wqWla/NS+q U/mDpZQV7+DFmjoNBUEs8vhFC06Uqkb5nd5kfYZqlfJ99s0hPz709jvNqvkCuY+eoMmV zmqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IKwccqyc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p11-20020a170902eacb00b001bbdb34628bsi5003819pld.289.2023.11.09.08.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 08:56:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IKwccqyc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8A18E806CF40; Thu, 9 Nov 2023 08:56:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343910AbjKIQzz (ORCPT + 31 others); Thu, 9 Nov 2023 11:55:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234815AbjKIQio (ORCPT ); Thu, 9 Nov 2023 11:38:44 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B742E4219; Thu, 9 Nov 2023 08:38:17 -0800 (PST) Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 8CD7766076BE; Thu, 9 Nov 2023 16:38:15 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1699547896; bh=8T4DdeHs6mpVgqmMv5KtofAn83k7sC5nyycBFLf4ldc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKwccqycl6+A3/fK7/ZrNuDxedUiPPpD3vwjj461IqxQF3phnExhMpTyZnPXSUWet U91MMOLQkF8qRR4iSM4ivpjWz+/bElQNcXHG0ZenSjshoBazaBgkMn1Y7i6z6dv5Z/ NYScCpxIkrLTtu0zzcUmYSODbOu5RYKOMOa4gSfnvYS/O0lu0ndsp0xMcmlvEyIaWQ yXj5Wo5gnSzhE40X/j5TvDFO5A0LblgWgWdeoVEJphVbzPEmNRVGlQ4KIjqJ5igkGX HUWSCtB1OkgnN12uv8s7Ft4FLpibFkO7P9pou2YR3KfPlbfSz0NelSOM/qOmJiWiyT /gR13o7etPugQ== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard , Andrzej Pietrasiewicz , Paul Kocialkowski , Maxime Ripard Subject: [PATCH v15 35/56] media: cedrus: Stop direct calls to queue num_buffers field Date: Thu, 9 Nov 2023 17:34:51 +0100 Message-Id: <20231109163512.179524-36-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231109163512.179524-14-benjamin.gaignard@collabora.com> References: <20231109163512.179524-14-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 09 Nov 2023 08:56:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782106312798229597 X-GMAIL-MSGID: 1782106312798229597 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. While at it, check the return value of vb2_get_buffer(). Signed-off-by: Benjamin Gaignard Reviewed-by: Andrzej Pietrasiewicz Acked-by: Paul Kocialkowski CC: Maxime Ripard --- drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 9 +++++++-- drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c index dfb401df138a..3e2843ef6cce 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c @@ -653,8 +653,13 @@ static void cedrus_h264_stop(struct cedrus_ctx *ctx) vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); - for (i = 0; i < vq->num_buffers; i++) { - buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i)); + for (i = 0; i < vb2_get_num_buffers(vq); i++) { + struct vb2_buffer *vb = vb2_get_buffer(vq, i); + + if (!vb) + continue; + + buf = vb2_to_cedrus_buffer(vb); if (buf->codec.h264.mv_col_buf_size > 0) { dma_free_attrs(dev->dev, diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index fc9297232456..52e94c8f2f01 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c @@ -869,8 +869,13 @@ static void cedrus_h265_stop(struct cedrus_ctx *ctx) vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); - for (i = 0; i < vq->num_buffers; i++) { - buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i)); + for (i = 0; i < vb2_get_num_buffers(vq); i++) { + struct vb2_buffer *vb = vb2_get_buffer(vq, i); + + if (!vb) + continue; + + buf = vb2_to_cedrus_buffer(vb); if (buf->codec.h265.mv_col_buf_size > 0) { dma_free_attrs(dev->dev,