From patchwork Tue Oct 17 14:47:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 154318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4187186vqb; Tue, 17 Oct 2023 07:49:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSCcE1Dkr4Qb3syspr91ttPR8lMZbd116aNoLxNpYiISVEvD0Lucl2UbVlp1JNFfKsUSu9 X-Received: by 2002:a05:6358:72a6:b0:166:d9f6:fbbc with SMTP id w38-20020a05635872a600b00166d9f6fbbcmr2610004rwf.3.1697554172411; Tue, 17 Oct 2023 07:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697554172; cv=none; d=google.com; s=arc-20160816; b=SWTjgXcyaBanuB5ncA/UB89Lf3woWzueRV+B2KDbfwcKTNrBMxa5gHuusORUAyVM4H tymbRlWNK+t7Pax7k2tn09QcRl7k2d3pU7h6RXYx2WEGiy8Y8i9ec5oD1rUOTMgEz/lG c0xMtwlDIzni5f3ey2oD3TU3PxjhXZQLEi7+1gXQZstGLb7DW9ULZ8WI99Kyfbj0NjL9 vADNvkR7aqe405pAChf/Cc4vH5nFnO7EdCD4OJRaHCrLOTiPGeVq6UXXl7Q7U4DYwVfM pCX1MKIU/wv17Ki6HkHmtuW6p0k4d1Bsm5r5cKD93QUdBwx8KtPkTXDwlWNnDfpC8EMC z+Eg== 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=NyJ7BF1AH0Xaf2XOQr0Ummtk6Obj50YB13wLLlG1vAk=; fh=R7B7Bon9pv+GFCDou9bQ9Fb3T633P/NGL4WG9w9NtOc=; b=mbeDihFQD4vIARrFvQIMuzGdCx1uRfxXAgc+Fy9EWvW+VB+hWCrWYISQ8BXOD/I9Gj uq4tbFMm04vOonI6DxFwiS9WtVM7BMk88iWcMybiRliVeGZ7bskHsGjj7S+zqTMAE8tl DBR7IaVn7TfhcWWp/jIpKnfw0qwcOvHNh/zRMJuAXl6LAxuTo42WmHxq8E+TmIT02HsN g6sHMvDWORpKTtyhNzxzXwelDPHlI/int7w72U2U5XXY/AOek49zOBnosKJeV9lGfTaT esHtCPUEE9Mk7oD01bxlWjrMvnpyL8pMy+U0pKDXMQ8ZKexms4uSlK9RiaE60UNFwCt5 zckw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YOs6+Xbi; 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 s22-20020a056a00195600b006be057d0923si1874899pfk.42.2023.10.17.07.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:49:32 -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=YOs6+Xbi; 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 AD135801B18A; Tue, 17 Oct 2023 07:49:30 -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 S1344343AbjJQOtR (ORCPT + 20 others); Tue, 17 Oct 2023 10:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344162AbjJQOsO (ORCPT ); Tue, 17 Oct 2023 10:48:14 -0400 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 07A74B0; Tue, 17 Oct 2023 07:48:13 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7205:da49:a7e8:59f8]) (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 F33806607351; Tue, 17 Oct 2023 15:48:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697554091; bh=b1HWvospKm41+ZR+lTHAwjFMrNIUi+qp4QEOx4PbCAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YOs6+XbifI+WkSju1IzN8c83yJB15Nbv8YtChMDwPwCWutYdQHumcimv4WdXK6yQb LNlyr4hC+gos+VVKtomgkAJhYLQtDe60E79u3XWJmp2Gjl4ID/8eu9SdbyFYkRnvxx 8JIJfGAFA+eZb4kkeJ2wky5Al0dyvgi3zQy0SJXtcaYm6tPg1btyvZ/JLR8cqU4cAM sBej5hGo1hD6K53Sr6iinkDwWk1XHHagSPq4b7E9zvQdov8M/h16Xfoxxz3wloDEhe xiyA+BT9zpuL+M9L3qwt2Ewo2YkJ9e8lmXWRbM0QjPfnSXsFpivRAhavltSW++SYxP uE8GHVLJCOhcA== 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 , Daniel Almeida Subject: [PATCH v12 15/56] media: visl: Use vb2_get_buffer() instead of directly access to buffers array Date: Tue, 17 Oct 2023 16:47:15 +0200 Message-Id: <20231017144756.34719-16-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231017144756.34719-1-benjamin.gaignard@collabora.com> References: <20231017144756.34719-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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]); Tue, 17 Oct 2023 07:49:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780014563640591151 X-GMAIL-MSGID: 1780014563640591151 Use vb2_get_buffer() instead of direct access to the vb2_queue bufs array. This allows us to change the type of the bufs in the future. 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 CC: Daniel Almeida CC: Mauro Carvalho Chehab --- 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]);