From patchwork Thu Sep 14 13:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 139929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp706307vqi; Thu, 14 Sep 2023 17:11:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpFgdgZeRe+01HRNc0/30MzGEdTgNlJzC2JF+kZTI/AD9yvz6PrLiLyTB9tX82mOxTC8i0 X-Received: by 2002:a17:902:e841:b0:1c1:f5a6:bdfa with SMTP id t1-20020a170902e84100b001c1f5a6bdfamr182316plg.7.1694736716040; Thu, 14 Sep 2023 17:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694736716; cv=none; d=google.com; s=arc-20160816; b=ww4XhbWWQtrxsnV6f/DezeTdnIQk7QtcR9ywpfh8+EZtYsPaTTYoMJT/kcfTYnbRj/ +S1q4z/mAgM0qrgQM/r9SebEwTgJOvUkW0sEQkfHUj6hnWeefK2EV5d6WIBfB0u2CgEu iRot6d95RkW3XO/E4rUo4TNNXtQQCrZx5MjPmjQlDjxcVWZWmglUA07eSM5582r72CD9 +zFq9avxE3zoUbE8DJok6w1aP0GOBDeymgQgNQRYV948kxFfRcV1M6RtJaUTl2nunhKB r/o9k7RcUbuATtBZgLZ45ESPTBMRacPydcY+g9Bu7J8j2JkNXQYKMMGNjzt7WqmRCEML teDQ== 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=U2gW/Q+RNn3ntItDX+hvmZgS358f/BD2tGGafv55qEw=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=j3vXSvEUfg8DcWtxo1Edre1+1wRdU08D2XczFjp7B2BU5DfmkGfoCml7e017B6vnN4 BJhPkSOcqtEVnwEjiOZpRUtIjFP/3UXs7pD6X+F63kU4I0ujDwBW3fBjWTOlDjtjdBnO eoSYX0JRvyqLeg+Gbju0HcTTln/N43JtYubQlBafv1Hi9Gi0yIyYYc2cAQ4GKaW2hhX9 ZjDJKQcJKiAdUK3Nr1vkbF5LFGEks+w75lt5HRfoIcwNGXLnhewBAb7L7P1NbfN3UQef BCKFSXHYfoxzpABPvqF4ET1rIzRb/0Ik1HAd8e6ljIH+cfC+PDRaP1hYSfZN10l39PcP 2y4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="SDSzY/Tw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d18-20020a170903231200b001b9e9b21249si2656455plh.649.2023.09.14.17.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 17:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="SDSzY/Tw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 9404181A6E66; Thu, 14 Sep 2023 06:34:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239257AbjINNd5 (ORCPT + 35 others); Thu, 14 Sep 2023 09:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239065AbjINNdk (ORCPT ); Thu, 14 Sep 2023 09:33:40 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4DB11FD5; Thu, 14 Sep 2023 06:33:36 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:36f2:37bd:ccbb:373f]) (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 5D2FE6607358; Thu, 14 Sep 2023 14:33:35 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1694698415; bh=Osy0YWOEVUvzSOYoJm+JBXSigMNkmpw77qpRTwkivks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SDSzY/TwRn4hjbZQQ8bWA6bcK8mXL3C87PQzzQUb/JwUM/y4+aAzMW3YoEWJXVOcl Aq6a+39QRO1ModNJw7jOTRL+eehodGl2VjPUWKOn95HyaNN3G5208QS6wNPJI2BCKO geJrLl58MRUIb2HfT+U9XnfeOcZxXqiZRhtZ+yehb9+i+XQDd8AXxEIlmVR11YheSP 7Vf9MZY+YbFww48huT3wDz7xgFSCS9KH07RlSGtwDkkz1ygDqEsVdmojH+pI+jg7Tw A+T4eAzI1Ccc5Kru15mlAo0XK2w4dnK1IK1UlMNg6Z3Sjv+o3GbzO78396TbxNmhoI YrM4knVZIB21g== 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 Subject: [PATCH v7 08/49] media: visl: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 14 Sep 2023 15:32:42 +0200 Message-Id: <20230914133323.198857-9-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230914133323.198857-1-benjamin.gaignard@collabora.com> References: <20230914133323.198857-1-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, 14 Sep 2023 06:34:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777060246773157233 X-GMAIL-MSGID: 1777060246773157233 Use vb2_get_buffer() instead of directly access to vb2_buffer buffer array. This could allow to change the type bufs[] field of vb2_buffer structure if needed. After each call to vb2_get_buffer() we need to be sure that we get a valid pointer so check the return value of all of them. Signed-off-by: Benjamin Gaignard --- drivers/media/test-drivers/visl/visl-dec.c | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/media/test-drivers/visl/visl-dec.c b/drivers/media/test-drivers/visl/visl-dec.c index 318d675e5668..ba20ea998d19 100644 --- a/drivers/media/test-drivers/visl/visl-dec.c +++ b/drivers/media/test-drivers/visl/visl-dec.c @@ -290,13 +290,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) for (i = 0; i < out_q->num_buffers; i++) { char entry[] = "index: %u, state: %s, request_fd: %d, "; u32 old_len = len; - char *q_status = visl_get_vb2_state(out_q->bufs[i]->state); + struct vb2_buffer *vb2; + char *q_status; + + vb2 = vb2_get_buffer(out_q, i); + if (!vb2) + continue; + + q_status = visl_get_vb2_state(vb2->state); len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len, entry, i, q_status, - to_vb2_v4l2_buffer(out_q->bufs[i])->request_fd); + to_vb2_v4l2_buffer(vb2)->request_fd); - len += visl_fill_bytesused(to_vb2_v4l2_buffer(out_q->bufs[i]), + len += visl_fill_bytesused(to_vb2_v4l2_buffer(vb2), &buf[len], TPG_STR_BUF_SZ - len); @@ -342,13 +349,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) len = 0; for (i = 0; i < cap_q->num_buffers; i++) { u32 old_len = len; - char *q_status = visl_get_vb2_state(cap_q->bufs[i]->state); + struct vb2_buffer *vb2; + char *q_status; + + vb2 = vb2_get_buffer(cap_q, i); + if (!vb2) + continue; + + q_status = visl_get_vb2_state(vb2->state); len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len, "index: %u, status: %s, timestamp: %llu, is_held: %d", - cap_q->bufs[i]->index, q_status, - cap_q->bufs[i]->timestamp, - to_vb2_v4l2_buffer(cap_q->bufs[i])->is_held); + vb2->index, q_status, + vb2->timestamp, + to_vb2_v4l2_buffer(vb2)->is_held); tpg_gen_text(&ctx->tpg, basep, line++ * line_height, 16, &buf[old_len]); frame_dprintk(ctx->dev, run->dst->sequence, "%s", &buf[old_len]);